Creating a custom vertex id

A custom vertex id can be created to replace the standard auto-generated vertex id that is normally generated for vertices. The use cases for creating a custom vertex id are:

  • When the data stored in DSE Graph is aligned with other data sources, such as other DSE database keyspaces or another database.

  • When custom graph partitioning is desired.

Standard auto-generated ids are deprecated with DSE 6.0. Custom ids will undergo changes, and specifying vertex ids with partitionKey and clusteringKey will likely become the normal method.

For example, sensor time series data is stored in the DSE database. In addition to the time series queries to the DSE database, relationship information about the sensors is desired, such as how the sensors are networked and where the sensors are located. To load the data into a graph to explore the relationships, but retain the ability to write an application that accesses both the time series data and the graph data, custom vertex ids are created that span across both database models.

Keep in mind that if custom vertex ids are used, they must be globally unique within the graph, or duplicate vertices can potentially be loaded into a graph. DSE Graph does not verify the custom vertex ids. Standard auto-generated vertex ids are guaranteed to be unique.

  1. Create a vertex label with a custom partitioning key sensor_id. The property key sensor_id must exist prior to use in creating the vertex label and cannot be a multiple cardinality property.

    $ schema.vertexLabel('FridgeSensor').partitionKey('sensor_id').create()
  2. Add a vertex using the vertex label FridgeSensor.

    $ graph.addVertex(label, 'FridgeSensor','sensor_id', '60bcae02-f6e5-11e5-9ce9-5e5517507c66')
  3. Create a vertex label with a custom partitioning key city_id and clustering key sensor_id.

    $ schema.vertexLabel('FridgeSensor').partitionKey('city_id').clusteringKey('sensor_id').create()
  4. Add a vertex using the vertex label FridgeSensor with both a partition key and clustering key.

    $ graph.addVertex(label, 'FridgeSensor','sensor_id', '60bcae02-f6e5-11e5-9ce9-5e5517507c66', 'city_id', 100)
  5. Create a vertex label with a custom composite partition, using both city_id and sensor_id as part of the partitioning key.

    $ schema.vertexLabel('FridgeSensor').partitionKey('city_id', 'sensor_id').create()

Was this helpful?

Give Feedback

How can we improve the documentation?

© 2024 DataStax | Privacy policy | Terms of use

Apache, Apache Cassandra, Cassandra, Apache Tomcat, Tomcat, Apache Lucene, Apache Solr, Apache Hadoop, Hadoop, Apache Pulsar, Pulsar, Apache Spark, Spark, Apache TinkerPop, TinkerPop, Apache Kafka and Kafka are either registered trademarks or trademarks of the Apache Software Foundation or its subsidiaries in Canada, the United States and/or other countries. Kubernetes is the registered trademark of the Linux Foundation.

General Inquiries: +1 (650) 389-6000, info@datastax.com