Why is JanusGraph throwing-up a User-Defined-Key problem when I'm just trying to make an index?
2023-05-08 12:40:25,640 [INFO] [c.d.o.d.i.c.ContactPoints.main] :: Contact point localhost:9042 resolves to multiple addresses, will use them all ([localhost/127.0.0.1, localhost/0:0:0:0:0:0:0:1])
2023-05-08 12:40:25,731 [INFO] [c.d.o.d.i.c.DefaultMavenCoordinates.main] :: DataStax Java driver for Apache Cassandra(R) (com.datastax.oss:java-driver-core) version 4.15.0
2023-05-08 12:40:26,173 [INFO] [c.d.o.d.i.c.t.Clock.JanusGraph Session-admin-0] :: Using native clock for microsecond precision
2023-05-08 12:40:26,414 [WARN] [c.d.o.d.i.c.l.h.OptionalLocalDcHelper.JanusGraph Session-admin-0] :: [JanusGraph Session|default] You specified datacenter1 as the local DC, but some contact points are from a different DC: Node(endPoint=localhost/127.0.0.1:9042, hostId=null, hashCode=6415177b)=null; please provide the correct local DC, or check your contact points
2023-05-08 12:40:26,643 [INFO] [o.j.g.i.UniqueInstanceIdRetriever.main] :: Generated unique-instance-id=c0a8563c15928-rmt-lap-win201
2023-05-08 12:40:26,657 [INFO] [c.d.o.d.i.c.ContactPoints.main] :: Contact point localhost:9042 resolves to multiple addresses, will use them all ([localhost/127.0.0.1, localhost/0:0:0:0:0:0:0:1])
2023-05-08 12:40:26,684 [INFO] [c.d.o.d.i.c.t.Clock.JanusGraph Session-admin-0] :: Using native clock for microsecond precision
2023-05-08 12:40:26,724 [WARN] [c.d.o.d.i.c.l.h.OptionalLocalDcHelper.JanusGraph Session-admin-0] :: [JanusGraph Session|default] You specified datacenter1 as the local DC, but some contact points are from a different DC: Node(endPoint=localhost/[0:0:0:0:0:0:0:1]:9042, hostId=null, hashCode=114c356b)=null; please provide the correct local DC, or check your contact points
2023-05-08 12:40:26,739 [INFO] [o.j.d.c.ExecutorServiceBuilder.main] :: Initiated fixed thread pool of size 40
2023-05-08 12:40:26,845 [INFO] [o.j.g.d.StandardJanusGraph.main] :: Gremlin script evaluation is disabled
2023-05-08 12:40:26,872 [INFO] [o.j.d.l.k.KCVSLog.main] :: Loaded unidentified ReadMarker start time 2023-05-08T17:40:26.872018Z into org.janusgraph.diskstorage.log.kcvs.KCVSLog$MessagePuller@8d8f754
Exception in thread "main" java.lang.IllegalArgumentException: Key must be a user defined key: null
at com.google.common.base.Preconditions.checkArgument(Preconditions.java:220)
at org.janusgraph.graphdb.database.management.ManagementSystem$IndexBuilder.addKey(ManagementSystem.java:789)
at Main.main(Main.java:15)
Process finished with exit code 130
POM.XML
log4j2.xml
, remote-graph.properties
, and remote-objects.yaml
(Optional)JanusGraphManagement
PropertyKey()
seems right because its in the latest index documentMapReduceIndexManagement()
seems wrong because its not in the latest documentJanusGraphManagement
their example doesn't show a example of how they classed their own interfacejava.lang.IllegalArgumentException: Key must be a user defined key: null
│ pom.xml
│
├───src
│ ├───main
│ │ ├───java
│ │ │ Main.java
│ │ │
│ │ └───resources
│ │ │ log4j2.xml
pom.xml
<dependencies>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j2-impl</artifactId>
<version>2.20.0</version>
</dependency>
<dependency>
<groupId>org.janusgraph</groupId>
<artifactId>janusgraph-cql</artifactId>
<version>1.0.0-20230504-014643.988c094</version>
</dependency>
</dependencies>
Main.java
import org.apache.tinkerpop.gremlin.structure.Vertex;
import org.janusgraph.core.JanusGraph;
import org.janusgraph.core.JanusGraphFactory;
import org.janusgraph.core.PropertyKey;
import org.janusgraph.core.schema.JanusGraphManagement;
public class Main {
public static void main(String[] args) {
JanusGraph janusGraph = JanusGraphFactory.build().set("storage.backend", "cql").set("storage.hostname", "localhost:9042").open();
JanusGraphManagement janusGraphManagement = janusGraph.openManagement();
PropertyKey propertyKey = janusGraphManagement.getPropertyKey("_id");
janusGraphManagement.buildIndex("_id", Vertex.class).addKey(propertyKey).buildCompositeIndex();
janusGraphManagement.commit();
janusGraph.close();
}
}
Here's the fix.
PropertyKey propertyKey = janusGraphManagement.getOrCreatePropertyKey("_id");
2023-05-09 08:46:38,617 [INFO] [c.d.o.d.i.c.ContactPoints.main] :: Contact point localhost:9042 resolves to multiple addresses, will use them all ([localhost/127.0.0.1, localhost/0:0:0:0:0:0:0:1])
2023-05-09 08:46:38,689 [INFO] [c.d.o.d.i.c.DefaultMavenCoordinates.main] :: DataStax Java driver for Apache Cassandra(R) (com.datastax.oss:java-driver-core) version 4.15.0
2023-05-09 08:46:39,124 [INFO] [c.d.o.d.i.c.t.Clock.JanusGraph Session-admin-0] :: Using native clock for microsecond precision
2023-05-09 08:46:39,385 [WARN] [c.d.o.d.i.c.l.h.OptionalLocalDcHelper.JanusGraph Session-admin-0] :: [JanusGraph Session|default] You specified datacenter1 as the local DC, but some contact points are from a different DC: Node(endPoint=localhost/[0:0:0:0:0:0:0:1]:9042, hostId=null, hashCode=7b9f753a)=null; please provide the correct local DC, or check your contact points
2023-05-09 08:46:39,610 [INFO] [o.j.g.i.UniqueInstanceIdRetriever.main] :: Generated unique-instance-id=c0a8563c11168-rmt-lap-win201
2023-05-09 08:46:39,625 [INFO] [c.d.o.d.i.c.ContactPoints.main] :: Contact point localhost:9042 resolves to multiple addresses, will use them all ([localhost/127.0.0.1, localhost/0:0:0:0:0:0:0:1])
2023-05-09 08:46:39,651 [INFO] [c.d.o.d.i.c.t.Clock.JanusGraph Session-admin-0] :: Using native clock for microsecond precision
2023-05-09 08:46:39,693 [WARN] [c.d.o.d.i.c.l.h.OptionalLocalDcHelper.JanusGraph Session-admin-0] :: [JanusGraph Session|default] You specified datacenter1 as the local DC, but some contact points are from a different DC: Node(endPoint=localhost/[0:0:0:0:0:0:0:1]:9042, hostId=null, hashCode=1ce6602a)=null; please provide the correct local DC, or check your contact points
2023-05-09 08:46:39,707 [INFO] [o.j.d.c.ExecutorServiceBuilder.main] :: Initiated fixed thread pool of size 40
2023-05-09 08:46:39,818 [INFO] [o.j.g.d.StandardJanusGraph.main] :: Gremlin script evaluation is disabled
2023-05-09 08:46:39,844 [INFO] [o.j.d.l.k.KCVSLog.main] :: Loaded unidentified ReadMarker start time 2023-05-09T13:46:39.844155Z into org.janusgraph.diskstorage.log.kcvs.KCVSLog$MessagePuller@ff23ae7
Process finished with exit code 0
There might not be any JanusGraphManagement
method like set()
, create()
, insert()
, make()
, or add()
for new PropertyKeys
. But, they've conjoined get-and-create together like making a SQL
SELECT
-or-CREATE
/INSERT
or a Java
Getter
-and-Setter
as one method.
Finding-and-realizing this just threw me through a loop.
import org.apache.tinkerpop.gremlin.structure.Vertex;
import org.janusgraph.core.JanusGraph;
import org.janusgraph.core.JanusGraphFactory;
import org.janusgraph.core.PropertyKey;
import org.janusgraph.core.schema.JanusGraphManagement;
public class Main {
public static void main(String[] args) {
JanusGraph janusGraph = JanusGraphFactory.build().set("storage.backend", "cql").set("storage.hostname", "localhost:9042").open();
JanusGraphManagement janusGraphManagement = janusGraph.openManagement();
PropertyKey propertyKey = janusGraphManagement.getOrCreatePropertyKey("_id");
janusGraphManagement.buildIndex("_id", Vertex.class).addKey(propertyKey).buildCompositeIndex();
janusGraphManagement.commit();
janusGraph.close();
}
}