orientechnologies / orientdb-gremlin

TinkerPop3 Graph Structure Implementation for OrientDB

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Cannot create property-index on graph loaded via gremlin API

MartinBrugnara opened this issue · comments

Version: 3.0.27
Store: plocal

Issue

I cannot create an index on any property when the graph is loaded via the gremlin API.

Questions

  • Should I manually alter the schema to make it aware of the properties or there is way to auto discover it ?
  • In case I need to create the schema a-priory, what's the recommend way to do so?

Context & Code

Loading code:

GraphSONReader.build().create().readGraph(new FileInputStream(new File(dataset)), g);

Partial, relevant, loading log:

INFO: $ANSI{green {db=thedb}} created class 'software' as subclass of 'V'

Index creation code:

String label = "software";
String prop_name = "lang";

OrientGraph og = (OrientGraph)g;
String query = "CREATE INDEX %1$s_%2$s_index ON %1$s (%2$s) NOTUNIQUE METADATA {ignoreNullValues: true}";
String cls = og.labelToClassName(label, "V");
og.executeSql(String.format(query, cls, prop_name));
og.commit();

Stacktrace:

com.orientechnologies.orient.core.index.OIndexException: Index with name 'software_lang_index' cannot be created on class 'software' because the field 'lang' is absent in class definition
	DB name="thedb"
	at com.orientechnologies.orient.core.metadata.schema.OClassImpl.createIndex(OClassImpl.java:1155)
	at com.orientechnologies.orient.core.sql.parser.OCreateIndexStatement.getoIndex(OCreateIndexStatement.java:133)
	at com.orientechnologies.orient.core.sql.parser.OCreateIndexStatement.execute(OCreateIndexStatement.java:119)
	at com.orientechnologies.orient.core.sql.parser.OCreateIndexStatement.executeDDL(OCreateIndexStatement.java:54)
	at com.orientechnologies.orient.core.sql.executor.ODDLExecutionPlan.executeInternal(ODDLExecutionPlan.java:55)
	at com.orientechnologies.orient.core.sql.parser.ODDLStatement.execute(ODDLStatement.java:42)
	at com.orientechnologies.orient.core.sql.parser.OStatement.execute(OStatement.java:79)
	at com.orientechnologies.orient.core.db.document.ODatabaseDocumentEmbedded.command(ODatabaseDocumentEmbedded.java:567)
	at org.apache.tinkerpop.gremlin.orientdb.OrientGraph.executeSql(OrientGraph.java:230)
	at com.graphbenchmark.shell.orientdb.IndexMgm.node(IndexMgm.java:26)
	at com.graphbenchmark.queries.mgm.CreateIndexes.lambda$query$0(CreateIndexes.java:37)
        ...

Hi @MartinBrugnara

There is no way to auto-discover properties, so I'm afraid you will have to create them manually.
My suggestion is to use plain SQL to do it

Thanks

Luigi

Thanks @luigidellaquila for the quick and clear response.

I proceed to close this issue.