orientechnologies / orientjs

The official fast, lightweight node.js client for OrientDB
http://orientdb.com
Other
327 stars 67 forks source link

Orientjs Batch query issue for creating class and class properties #441

Closed SameerChorge94 closed 3 years ago

SameerChorge94 commented 3 years ago

Description: I'm trying to run the batch query using orientJs client for creating the multiple classes and it's respective properties. But getting the request Error parsing query error with below query.

Batch Query:

BEGIN; 
LET typeInsdemo1 = CREATE CLASS demo1 EXTENDS V;
LET typePropInsdemo10 = create Property demo1.name String;
LET typePropInsdemo11 = create Property demo1.desc String;
LET typeInsdemo2 = CREATE CLASS demo2 EXTENDS V;
LET typePropInsdemo20 = create Property demo2.name String;
LET typePropInsdemo21 = create Property demo2.desc String;

COMMIT;
return  typeInsdemo1;

If I execute the normal insert queries in batch then t works without issues refer below example

begin;
        let $v1 = create vertex random2 set name = "first";
        let $v2 = create vertex random3 set name = "second";
        let $e = create edge randomEdge from $v1 to $v2;
        commit;
        return  $e;

Expected Result: Above batch query should create 2 classes and it's respective properties in orientDB

Acutal Result: After executing the above query using orientJsClientDBSession.batch(BATCH_QUERY) it's returning the parsing error Complete Error Response:

Encountered " <LET> "LET "" at line 4, column 1.
Was expecting one of:
    <WHILE> ...
    <IF> ...
    <FOREACH> ...
    ";" ...
    <IF> ...
    <IF> ...
    <IF> ...
    <IF> ...
    <IF> ...

        DB name="pocketmaster"
        Error Code="1"
    at child.Operation.parseError (D:\ADMIN\Fastify-Server\OrientJs_Fastify_Server\node_modules\orientjs\lib\client\network\protocol37\operation.js:1247:13)
    at child.Operation.consume (D:\ADMIN\Fastify-Server\OrientJs_Fastify_Server\node_modules\orientjs\lib\client\network\protocol37\operation.js:571:35)
    at ONetworkConnection.Connection.process (D:\ADMIN\Fastify-Server\OrientJs_Fastify_Server\node_modules\orientjs\lib\client\network\conn.js:462:17)
    at ONetworkConnection.Connection.handleSocketData (D:\ADMIN\Fastify-Server\OrientJs_Fastify_Server\node_modules\orientjs\lib\client\network\conn.js:344:20)
    at Socket.emit (events.js:311:20)
    at addChunk (_stream_readable.js:294:12)
    at readableAddChunk (_stream_readable.js:275:11)
    at Socket.Readable.push (_stream_readable.js:209:10)
    at TCP.onStreamRead (internal/stream_base_commons.js:186:23) {
  name: 'OrientDB.RequestError',
  message: 'Error parsing query:\n' +
    '\n' +
    'Encountered " <LET> "LET "" at line 4, column 1.\r\n' +
    'Was expecting one of:\r\n' +
    '    <WHILE> ...\r\n' +
    '    <IF> ...\r\n' +
    '    <FOREACH> ...\r\n' +
    '    ";" ...\r\n' +
    '    <IF> ...\r\n' +
    '    <IF> ...\r\n' +
    '    <IF> ...\r\n' +
    '    <IF> ...\r\n' +
    '    <IF> ...\r\n' +
    '    \r\n' +
    '\tDB name="pocketmaster"\r\n' +
    '\tError Code="1"',
  data: {},
  isMVCC: [Function],
  isTokenException: [Function],
  previous: [],
  code: 1,
  identifier: 0,
  id: 1,
  type: 'com.orientechnologies.orient.core.sql.OCommandSQLParsingException',
  hasMore: 0
}

OrientDB Version:

Studio version : 3.1.3
OrientDB version : 3.1.3
Copyrights : OrientDB LTD
License : Apache 2

OrientJs version: orientjs: "^3.0.11"

SameerChorge94 commented 3 years ago

I was able to create the class with below batch query:

BEGIN; 
LET typeInstest1 = CREATE CLASS test1 IF NOT EXISTS EXTENDS V;
LET typePropInstest10 = create Property test1.name String;
LET typePropInstest11 = create Property test1.description String;
COMMIT;
return  typeInstest1;

but it fails after creating the class only and throws error and does not create the properties for the class it returns the below error:

'Cannot change the schema while a transaction is active. Schema changes are not transactional\r\n' +
  '\tDB name="test"'

Is there any workoround which i can use to create the multiple Class and it's properties in single batch query.

luigidellaquila commented 3 years ago

Hi @SameerChorge94

The only problem here is that the schema cannot be updated inside a transaction, so you have to omit the BEGIN/COMMIT:

LET typeInstest1 = CREATE CLASS test1 IF NOT EXISTS EXTENDS V;
LET typePropInstest10 = create Property test1.name String;
LET typePropInstest11 = create Property test1.description String;
return  typeInstest1;

Thanks

Luigi

SameerChorge94 commented 3 years ago

@luigidellaquila Thank you above solution worked for me.