MATCHES broken in 2.1-rc3: fails to return data in simple query; causes Exception in nested query
Orient 2.1-rc3 throws an error when attempting to use MATCHES in a nested query. The following sample query/test works in 2.0.x, but fails with an error in 2.1-rc3. (Note: this example is a simplified version of the actual query that's failing in the application.)
orientdb {db=selectTest}> select from (select expand(in('metadata')) from ItemMetadata where code matches 'A-B-15-1.*')
Error: com.orientechnologies.orient.core.exception.OQueryParsingException: Error on parsing command at position #0: Error on parsing query
Query: (SELECT expand(in('metadata')) FROM ItemMetadata WHERE MatchesCondition)
------^
Test steps to reproduce error in console:
orientdb {db=selectTest}> create class Item extends V
Class created successfully. Total classes in database now: 11
orientdb {db=selectTest}> create class ItemMetadata extends V
Class created successfully. Total classes in database now: 12
orientdb {db=selectTest}> create class metadata extends E
Class created successfully. Total classes in database now: 13
orientdb {db=selectTest}> create vertex Item set name = "item 1"
Created vertex 'Item#11:0{name:item 1} v1' in 0.016000 sec(s).
orientdb {db=selectTest}> create vertex Item set name = "item 2"
Created vertex 'Item#11:1{name:item 2} v1' in 0.000000 sec(s).
orientdb {db=selectTest}> create vertex ItemMetadata set code = "A-B-15-0-0"
Created vertex 'ItemMetadata#12:0{code:A-B-15-0-0} v1' in 0.000000 sec(s).
orientdb {db=selectTest}> create edge metadata from #11:0 to #12:0
Created edge '[metadata#13:0{out:#11:0,in:#12:0} v2]' in 0.015000 sec(s).
orientdb {db=selectTest}> create vertex ItemMetadata set code = "A-B-15-1-0"
Created vertex 'ItemMetadata#12:1{code:A-B-15-1-0} v1' in 0.000000 sec(s).
orientdb {db=selectTest}> create edge metadata from #11:1 to #12:1
Created edge '[metadata#13:1{out:#11:1,in:#12:1} v2]' in 0.015000 sec(s).
orientdb {db=selectTest}> select from (select expand(in('metadata')) from ItemMetadata where code matches 'A-B-15-1.*')
Error: com.orientechnologies.orient.core.exception.OQueryParsingException: Error on parsing command at position #0: Error on parsing query
Query: (SELECT expand(in('metadata')) FROM ItemMetadata WHERE MatchesCondition)
------^
Error: com.orientechnologies.orient.core.sql.OCommandSQLParsingException: Error on parsing command at position #0: Encountered "" at line 1, column 55.
Was expecting one of:
Further check to verify equality works while matches fails:
orientdb {db=selectTest}> select from (select expand(in('metadata')) from ItemMetadata)
----+-----+------+------+------------
# |@RID |@CLASS|name |out_metadata
----+-----+------+------+------------
0 |#11:0|Item |item 1|[size=1]
1 |#11:1|Item |item 2|[size=1]
----+-----+------+------+------------
2 item(s) found. Query executed in 0.015 sec(s).
orientdb {db=selectTest}> select from (select expand(in('metadata')) from ItemMetadata where code = 'A-B-15-1-0')
----+-----+------+------+------------
# |@RID |@CLASS|name |out_metadata
----+-----+------+------+------------
0 |#11:1|Item |item 2|[size=1]
----+-----+------+------+------------
1 item(s) found. Query executed in 0.0 sec(s).
orientdb {db=selectTest}> select from (select expand(in('metadata')) from ItemMetadata where code = 'A-B-15-0-0')
----+-----+------+------+------------
# |@RID |@CLASS|name |out_metadata
----+-----+------+------+------------
0 |#11:0|Item |item 1|[size=1]
----+-----+------+------+------------
1 item(s) found. Query executed in 0.016 sec(s).
looks like 'matches' itself is broken...
orientdb {db=testdb}> select from ItemMetadata
----+-----+------------+----------+-----------
# |@RID |@CLASS |code |in_metadata
----+-----+------------+----------+-----------
0 |#74:0|ItemMetadata|A-B-15-0-0|[size=1]
1 |#74:1|ItemMetadata|A-B-15-1-0|[size=1]
----+-----+------------+----------+-----------
2 item(s) found. Query executed in 0.012 sec(s).
orientdb {db=testdb}> select from ItemMetadata where code matches 'A-B.*'
0 item(s) found. Query executed in 0.007 sec(s).
and also this:
orientdb {db=testdb}> select from ItemMetadata where code matches '*'
Error: com.orientechnologies.orient.core.sql.OCommandSQLParsingException: Error on parsing command at position #0: Encountered "" at line 1, column 32.
Was expecting one of:
orientdb {db=testdb}> select from ItemMetadata where code matches '.'
Error: com.orientechnologies.orient.core.sql.OCommandSQLParsingException: Error on parsing command at position #0: Encountered "" at line 1, column 32.
Was expecting one of:
using double quotes instead of single quotes does not cause the parser to fail, but still does not return the correct results:
orientdb {db=testdb}> select from ItemMetadata where code matches "*"
0 item(s) found. Query executed in 0.015 sec(s).
orientdb {db=testdb}> select from ItemMetadata where code matches "."
0 item(s) found. Query executed in 0.006 sec(s).
by the way, @buzzkillington, your original query would not have returned the right results anyway, since 'code' is a field of Item, not ItemMetadata which is the target of your query. using the '=' operator instead of matches, the query should look like this:
orientdb {db=testdb}> select expand(in('metadata')) from (select from ItemMetadata where code='A-B-15-1-0')
----+-----+------+------+------------
# |@RID |@CLASS|name |out_metadata
----+-----+------+------+------------
0 |#73:1|Item |item 2|[size=1]
----+-----+------+------+------------
1 item(s) found. Query executed in 0.008 sec(s).
@nagarajasr The original query is correct, "code" is a field of ItemMetadata (not Item) - see the examples I'd included for '='. Yours just moves the expand outside of the nested query, which happens to give the same result in this test, but (as I'd already mentioned) this is a simplified version of an existing query that worked in 2.0.x and I need it working again as-specified.
Please keep the discussion relevant to the actual issue.
Confirming that MATCHES is not working:
orientdb {db=selectTest}> select from ItemMetadata where code matches 'A-B.*'
0 item(s) found. Query executed in 0.0 sec(s).
orientdb {db=selectTest}> select from ItemMetadata where code like 'A-B%'
----+-----+------------+----------+-----------
# |@RID |@CLASS |code |in_metadata
----+-----+------------+----------+-----------
0 |#12:0|ItemMetadata|A-B-15-0-0|[size=1]
1 |#12:1|ItemMetadata|A-B-15-1-0|[size=1]
----+-----+------------+----------+-----------
2 item(s) found. Query executed in 0.0 sec(s).
For the nested query case, using the Java API for a prepared statement version of the query (with named parameters) results in the following stacktrace:
Exception in thread "main" com.orientechnologies.orient.core.sql.OCommandSQLParsingException: Error on parsing command at position #0: Encountered " <FROM> "from "" at line 1, column 8.
Was expecting one of:
<TO> ...
<VALUES> ...
<SET> ...
<ADD> ...
<PUT> ...
<MERGE> ...
<CONTENT> ...
<REMOVE> ...
<NULL> ...
<ORDER> ...
<GROUP> ...
<OFFSET> ...
<RECORD> ...
<LUCENE> ...
"@this" ...
<RECORD_ATTRIBUTE> ...
<INTEGER_LITERAL> ...
<FLOATING_POINT_LITERAL> ...
<CHARACTER_LITERAL> ...
"true" ...
"false" ...
"(" ...
"{" ...
"[" ...
"`" ...
"?" ...
":" ...
"-" ...
"*" ...
<IN> ...
<KEY> ...
<IDENTIFIER> ...
<NULL> ...
<CHARACTER_LITERAL> ...
"-" ...
<INTEGER_LITERAL> ...
"?" ...
":" ...
"(" ...
"-" ...
<INTEGER_LITERAL> ...
"-" ...
<FLOATING_POINT_LITERAL> ...
<IDENTIFIER> ...
<IN> ...
<SET> ...
<PUT> ...
<ADD> ...
<REMOVE> ...
<MERGE> ...
<CONTENT> ...
<ORDER> ...
<KEY> ...
<OFFSET> ...
<GROUP> ...
<VALUES> ...
<RECORD> ...
<TO> ...
<LUCENE> ...
"`" ...
"@this" ...
"[" ...
<IDENTIFIER> ...
<IN> ...
<SET> ...
<PUT> ...
<ADD> ...
<REMOVE> ...
<MERGE> ...
<CONTENT> ...
<ORDER> ...
<KEY> ...
<OFFSET> ...
<GROUP> ...
<VALUES> ...
<RECORD> ...
<TO> ...
<LUCENE> ...
"`" ...
<RECORD_ATTRIBUTE> ...
"*" ...
"?" ...
":" ...
"{" ...
"true" ...
"false" ...
"-" ...
<INTEGER_LITERAL> ...
"?" ...
":" ...
at com.orientechnologies.orient.core.sql.OCommandExecutorSQLAbstract.throwParsingException(OCommandExecutorSQLAbstract.java:101)
at com.orientechnologies.orient.core.sql.OCommandExecutorSQLAbstract.preParse(OCommandExecutorSQLAbstract.java:236)
at com.orientechnologies.orient.core.sql.OCommandExecutorSQLSelect.parse(OCommandExecutorSQLSelect.java:220)
at com.orientechnologies.orient.core.sql.OCommandExecutorSQLSelect.parse(OCommandExecutorSQLSelect.java:100)
at com.orientechnologies.orient.core.sql.OCommandExecutorSQLDelegate.parse(OCommandExecutorSQLDelegate.java:75)
at com.orientechnologies.orient.core.sql.OCommandExecutorSQLDelegate.parse(OCommandExecutorSQLDelegate.java:41)
at com.orientechnologies.orient.core.storage.impl.local.OAbstractPaginatedStorage.command(OAbstractPaginatedStorage.java:1184)
at com.orientechnologies.orient.core.sql.query.OSQLQuery.run(OSQLQuery.java:72)
at com.orientechnologies.orient.core.sql.query.OSQLSynchQuery.run(OSQLSynchQuery.java:85)
at com.orientechnologies.orient.core.query.OQueryAbstract.execute(OQueryAbstract.java:33)
at com.orientechnologies.orient.server.network.protocol.binary.ONetworkProtocolBinary.command(ONetworkProtocolBinary.java:1190)
at com.orientechnologies.orient.server.network.protocol.binary.ONetworkProtocolBinary.executeRequest(ONetworkProtocolBinary.java:390)
at com.orientechnologies.orient.server.network.protocol.binary.OBinaryNetworkProtocolAbstract.execute(OBinaryNetworkProtocolAbstract.java:222)
at com.orientechnologies.common.thread.OSoftThread.run(OSoftThread.java:71)
Hi @buzzkillington
thank you for reporting, I could reproduce the original problem, it's scheduled for a fix. Could you provide the code you used from Java API for the prepared statement? That's quite strange...
thanks
Luigi
@luigidellaquila Certainly - here's the prepared statement code, as requested:
public static void main(String[] args) {
OrientGraphFactory graphFactory = null;
OrientGraph graph = null;
try {
graphFactory = new OrientGraphFactory("remote:" + host + "/" + db, user, pass).setupPool(1, 10);
graph = graphFactory.getTx();
Map<String, Object> params = new HashMap<>();
params.put("code", "A-B-15-1.*");
List<ODocument> results = graph.getRawGraph().command(new OSQLSynchQuery<ODocument>("select from (select expand(in('metadata')) from ItemMetadata where code matches :code)")).execute(params);
LOG.debug("Got " + results.size() + " results:");
for(ODocument doc : results) {
LOG.debug(doc.toString());
}
}
finally {
if(graph != null) {
try {
graph.shutdown();
}
catch(Throwable t) {
// Ignore
}
}
if(graphFactory != null) {
try {
graphFactory.close();
}
catch(Throwable t) {
// Ignore
}
}
}
}
MATCHES is also broken in non-nested statements (tested in console and studio)
OrientDB2.1-rc3:
SELECT FROM OUSER WHERE any() MATCHES '.*' 0 item(s) found. Query executed in 0.002 sec(s).
OrientDB2.0:
SELECT FROM OUSER WHERE any() MATCHES '.*' #5:0 2 OUser admin ... #5:1 1 OUser reader ... #5:2 1 OUser writer ...
fixed in develop branch
@luigidellaquila I just downloaded the rc5 (latest) download of orientdb and MATCHES still doesn't work. Am I missing something?
Hi @iamlogiq could you post a query that does not work? I just tried these proposed by @ycxq and they work fine here
Luigi