OrientDB Creating an edge using select statement to set property - orientdb

I want to create an edge using a sub query to set a property. The following is the query i am using:
create edge HAS from #57:0 to #80:3 set Type = (select from A where ID = 1)
This gives me the following error:
OvalidationException:
The field 'HAS.Type' has been declared as LINK but the
value is not a record or a record-id
Please note the Type is a property of type LINK.
Any help is appreciated thanks!

The following is the answer:
create edge HAS from #57:0 to #80:3 set Type = first((select from A where ID = 1))

Related

Multipart column names in update statement with select

I'm sure this could be a duplicate but I can't seem to find the right search phrase.
Given a table in a named schema (i.e. not dbo) requires you include the schema name in the statement. So previously I'd have simply written it as so:
UPDATE [Schema].[Table1]
SET [AColumn] =
(
SELECT [SomeColumn]
FROM [Schema].[Table2]
WHERE [Schema].[Table2].[SameColumnName] = [Schema].[Table1].[SameColumnName]
);
But since More than two-part column name is deprecated, I need to find a new way to do this which is future proof. I have come up with 2 options, firstly using an alias:
UPDATE [Alias1]
SET [AColumn] =
(
SELECT [SomeColumn]
FROM [Schema].[Table2] [Alias2]
WHERE [Alias2].[SameColumnName] = [Alias1].[SameColumnName]
)
FROM [Schema].[Table1] [Alias1];
The second way is the one I'm really having trouble finding out if it's truly VALID T-Sql:
UPDATE [Schema].[Table1]
SET [AColumn] =
(
SELECT [SomeColumn]
FROM [Schema].[Table2]
WHERE [Table2].[SameColumnName] = [Table1].[SameColumnName]
);
I have tested both and they work, so my question is, is the second completely valid and normal to use just the table name without the Schema in this sense or should I rather opt for the slightly more verbose Alias?
As I said in my comment, alias your objects.
SELECT MT.MyColumn,
YT.MyColumn
FROM dbo.MyTable MT
JOIN so.YourTable YT ON MT.ID = YT.fID
WHERE YT.[name] = N'Jane';
If you're performing an UPDATE, then specify the alias of the object to Update:
UPDATE MT
SET MyColumn = YT.MyColumn --Column on the left side of the SET will always reference the table being updated
FROM dbo.MyTable MT
JOIN so.YourTable YT ON MT.ID = YT.fID
WHERE YT.[name] = N'Jane';

OrientDB Wrong search result

Seem that OrientDB doesn't return the correct result for the simple search.
I created a class node item with 2 properties id and flag
id: type STRING, index: UNIQUE
flag: type DECIMAL
flag can be set by 1, 0, or null value.
I use the query below to get all item which has flag is 1
`select from item where flag = 1`
But the query returns nothing.
Note: I have tested on 2.2.7 and 2.2.10, and seem that this issue only occurs if flag was defined in schema before feeding data.
Is it bug?
UPDATED: Added sample database. Get it here
If you use select from item where 1 = flag it works.
For your query select from item where flag = 1 could you open an issue on github attaching your database ?
Tested on 2.2.10, no problems here:
create class item extends v
create property item.id STRING
create property item.flag DECIMAL
insert into item(id,flag) values ("id1",1)
select from item where flag = 1
Also added UNIQUE index on id from studio -> schema.
Output:

AEM: How to find the nodes with property name "customProp" and empty property value, using query builder?

There are nodes which have properties but no values.
I am trying to avoid those nodes in query builder using,
path=/content/
type=cq:Page
2_property=jcr:content/customProp
2_property.operation=exists
3_property=jcr:content/customProp
3_property.operation=unequals
3_property.value=
But the empty value condition (3_property) is being ignored.
How this can be achieved?
I had the issue to search for all occurrence of a propertiy with no value.
I constructed the following SQL2 Query:
SELECT * FROM [{{jcr:primaryType}}] AS ref WHERE ISDESCENDANTNODE([{{Start Path}}]) AND ref.[{{Property Name}}] = ''
In your case I think something like should work
SELECT * FROM [{{jcr:primaryType}}] AS ref WHERE ISDESCENDANTNODE([{{Start Path}}]) AND NOT(ref.[{{Property Name}}] = '')

OrientDB - Creating an edge using rid's from index queries

I'm trying to create edges between existing vertices queried by their indexed IDs, similar to the first answer here, but using this index lookup query instead of the label query:
CREATE EDGE cite
FROM
(SELECT FROM index:<className>.<indexName> WHERE key = "<keyString>")
TO
(SELECT FROM index:<className>.<indexName> WHERE key = "<keyString>")
This gives me the following error: com.orientechnologies.orient.core.exception.OCommandExecutionException: Source vertex '#-1:-1' not exists
Possibly relevant:
When I just query SELECT FROM index:<className>.<indexName> WHERE key = "<keyString>" by itself it returns an array object structured like:
[ { '#type': 'd',
key: '<keyString>',
rid: { cluster: <actual cluster>, position: <actual position> }
#rid: { cluster: -1, position: -1 } } ]
I'm guessing that the error has something to do with the CREATE EDGE query using the #rid instead of the rid but I'm not sure.
The query successfully creates the edges if I simply use the #<actual cluster>:<actual position> instead of the SELECT subquery.
Any ideas what I might be doing wrong?
Edit: In the interest of replicability, I have the same problem in the GratefulDeadConcerts database when I (1) add a property name to the V class schema, (2) create a unique nameIndex index of V using the name property under V, and then (3) use the following query:
create edge followed_by from (select from index:nameIndex where key = 'HEY BO DIDDLEY') to (select from index:nameIndex where key = 'IM A MAN')
Why don't you query the class directly?
CREATE EDGE cite
FROM
(select from Class where field = '<keyString>')
TO
(select from Class where field = '<keyString>')
Select from index return a temp document as result set with key,and rid
you can try but i don't know if it will work
SELECT expand(rid) FROM index:<className>.<indexName> WHERE key = "<keyString>"

Filtering one of the columns in an MDX query

I am comparatively new to MDX. I am working witht he following query :-
WITH
SET [Organisation Default Member]
AS
STRTOMEMBER(iif(isempty(LadbrokesSAS.GetDimensionSecurityUserDefaultOrgMember(USERNAME)),"[Organisation].[Organisation Hierarchy].[ALL]",LadbrokesSAS.GetDimensionSecurityUserDefaultOrgMember(USERNAME)),CONSTRAINED)
MEMBER [Measures].[ParameterCaption] AS '[Organisation].[Organisation Hierarchy].CURRENTMEMBER.MEMBER_CAPTION'
MEMBER [Measures].[ParameterValue] AS '[Organisation].[Organisation Hierarchy].CURRENTMEMBER.UNIQUENAME'
MEMBER [Measures].[ParameterLevel] AS '[Organisation].[Organisation Hierarchy].CURRENTMEMBER.LEVEL.ORDINAL'
MEMBER [Measures].[ParameterCaptionIndented] AS Space([Organisation].[Organisation Hierarchy].CURRENTMEMBER.LEVEL.ORDINAL) + [Organisation].[Organisation Hierarchy].CURRENTMEMBER.MEMBER_CAPTION
SET [Organisation]
AS Descendants([Organisation Default Member] ,[Organisation].[Organisation Hierarchy]. [Key Organisation],SELF_AND_BEFORE)
SELECT
{
[Measures].[ParameterValue]
,[Measures].[ParameterCaptionIndented]
} ON COLUMNS ,
{Organisation}
ON ROWS
FROM [ShopTradingCube]
The above query returns results like below:-
Now I want to filter the ParameterValue such that if it contains a value containing '[Organisation].[Organisation Hierarchy].[Supervisor - HO Manager]' it should not include that in the results. eg. [Organisation].[Organisation Hierarchy].[Supervisor - HO Manager].&[L7_Z_250_Closed]
I tried approaches using a where condition or by using an Except function. However, I always got some error no matter what all I tried. Can someone please let me know what should be my syntax and what is the most efficient way to achieve this?
Modify your set to the following:
SET [Organisation]
AS Descendants([Organisation Default Member] ,[Organisation].[Organisation Hierarchy]. [Key Organisation],SELF_AND_BEFORE)
-
Descendants([Organisation].[Organisation Hierarchy].[Supervisor - HO Manager])
This works like except.