orientjs icon indicating copy to clipboard operation
orientjs copied to clipboard

Error parsing query on select from list of record Ids (v3)

Open creisle opened this issue 5 years ago • 3 comments

Version info

orientdb version: 3.0.14 orientjs version: 3.0.5 nodejs version: v10.13.0

Expected Behaviour

The same query previously worked in v2.2.X and works when done in the orientdb console but throws an error when using orientjs v3+

Observed Behaviour

throws the following error message

Unhandled rejection OrientDB.RequestError: Error parsing query:
SELECT * FROM [:bob, :alice]
            ^
Encountered " <FROM> "FROM "" at line 1, column 10.
Was expecting one of:
    <EOF> 

Min Reproducible Example

const cleanup = async (server, conf) => {
    await server.dropDatabase({
        name: 'test_select_from_list',
        username: conf.DBS_USER,
        password: conf.DBS_PASS
    });
    await server.close();
};

const test = async (conf) => {
    const server = await OrientDBClient.connect({
        host: conf.DB_HOST,
        port: conf.DB_PORT
    });
    await server.createDatabase({
        name: 'test_select_from_list',
        username: conf.DBS_USER,
        password: conf.DBS_PASS
    });
    const db = await server.session({
        name: 'test_select_from_list',
        username: conf.DBS_USER,
        password: conf.DBS_PASS
    });
    let bob,
        alice;
    try {
        // create some vertices
        ([bob, alice] = await Promise.all([
            db.command('CREATE VERTEX V SET name = \'bob\'').all(),
            db.command('CREATE VERTEX V SET name = \'alice\'').all()
        ]));
    } catch (err) {
        await cleanup(server, conf);
        throw err;
    }
    // do the error prone select
    try {
        // create some vertices
        const result = await db.query('SELECT * FROM [:bob, :alice]', {bob: bob['@rid'], alice: alice['@rid']}).all();
        await cleanup(server, conf);
        return result;
    } catch (err) {
        await cleanup(server, conf);
        throw err;
    }
};

creisle avatar Jun 12 '19 23:06 creisle

Note that this may be related to https://github.com/orientechnologies/orientjs/issues/380 ? Unsure if select from list of records is treated the same as filtering against a list of records

creisle avatar Jul 18 '19 17:07 creisle

Hi @creisle

i've checked this syntax is not supported

SELECT * FROM [:bob, :alice]

if you want to use parameters in the target you have to use one 1 param like this

SELECT * FROM :target

let me know if this helps

Thanks

wolf4ood avatar Jul 29 '19 13:07 wolf4ood

@wolf4ood I get a different error when i try that

const result = await db.query(
    'SELECT * FROM :people', 
    {params: {people: [bob['@rid'], alice['@rid']]}}
).all();

error message

{ OrientDB.RequestError: Cannot use colleciton as target: [null, null]
	DB name="test_select_from_list"
    at child.Operation.parseError (/home/creisle/git/knowledgebase/knowledgebase_api/node_modules/orientjs/lib/client/network/protocol37/operation.js:1224:13)
    at child.Operation.consume (/home/creisle/git/knowledgebase/knowledgebase_api/node_modules/orientjs/lib/client/network/protocol37/operation.js:566:35)
    at ONetworkConnection.Connection.process (/home/creisle/git/knowledgebase/knowledgebase_api/node_modules/orientjs/lib/client/network/conn.js:462:17)
    at ONetworkConnection.Connection.handleSocketData (/home/creisle/git/knowledgebase/knowledgebase_api/node_modules/orientjs/lib/client/network/conn.js:344:20)
    at Socket.emit (events.js:182:13)
    at addChunk (_stream_readable.js:283:12)
    at readableAddChunk (_stream_readable.js:264:11)
    at Socket.Readable.push (_stream_readable.js:219:10)
    at TCP.onStreamRead [as onread] (internal/stream_base_commons.js:94:17)
  name: 'OrientDB.RequestError',
  message:
   'Cannot use colleciton as target: [null, null]\r\n\tDB name="test_select_from_list"',
  data: {},
  isMVCC: [Function],
  isTokenException: [Function],
  previous: [],
  code: 5,
  identifier: 0,
  id: 1,
  type:
   'com.orientechnologies.orient.core.exception.OCommandExecutionException',
  hasMore: 0 }

I can select from a collection when not using parameters (ex. if I sub them in directly)

const result = await db.query(`SELECT * FROM [${bob['@rid']}, ${alice['@rid']}]`).all();

creisle avatar Jul 29 '19 22:07 creisle