Dropping graph schema

Schema can be dropped (deleted) using the drop() step; see user-defined type (UDT), vertexLabel, and edgeLabel for more information.

Procedure

  • Drop all schema

  • To drop the schema and all data without dropping the graph, use a drop() step. Running describe() after will verify that the schema is dropped. After the schema is dropped, new schema and data can be loaded to the graph.

    To drop all schema:

    schema.drop()
    ==> OK
  • Drop user-defined type (UDT)

  • To drop schema for a particular UDT, specify the UDT and then use the drop() step:

    schema.type('location_details').
       ifExists().
       drop()
    
    schema.type('address').
       ifExists().
       drop()
    
    schema.type('fullname').
       ifExists().
       drop()

    Three UDTs are dropped with three commands.

  • Drop vertex label or vertex label property

    • To drop schema for a particular vertex label, specify the vertex label and then use the drop() step:

      schema.vertexLabel('person').
        ifExists().
        drop()
  • To drop schema for a particular vertex label property key, specify the property key and then use the drop() step:

    schema.vertexLabel('person').
        dropProperty('gender').
        alter()

    To drop a property key for a vertex label that has a materialized view index, additional steps are required to prevent data loss or cluster errors. Drop any materialized view indexes for the vertex label, drop the property key, and then rebuild the schema for the materialized view indexes. The MV index data will be recreated from the base table, with the exception of the data for the dropped property key.

  • Drop edge label or edge label property

  • To drop schema for a particular edge label, specify the edge label and then use the drop() step:

    schema.edgeLabel('ate').
      ifExists().
      drop()
  • To drop schema for a particular edge label property key, specify the property key and then use the drop() step:

    schema.edgeLabel('authored').
        dropProperty('one').
        dropProperty('two').
        alter()
    To drop a property key for an edge label that has a materialized view index, additional steps are required to prevent data loss or cluster errors. Drop any materialized indexes for the edge label, drop the property key, and then rebuild the schema for the materialized view indexes. The MV index data will be recreated from the base table, with the exception of the data for the dropped property key.
  • Drop index

  • To drop a vertex label index from the schema:

    schema.vertexLabel('person').
        materializedView('person_by_gender').
        ifExists().
        drop()
  • Remove only one property from a search index:

    schema.vertexLabel('store').
        searchIndex().
        dropProperty('name').
        alter()
  • Clean up

    • If schema changes cause inconsistencies in the graph data, OLAP analytic operations can be blocked and queries will not run. Use the graph cleanup tool to remove any orphaned edge or unattached vertex properties that cause problems. To use this command, DSE Analytics must be running on the cluster.

      For example, after removing an edge label:

      graph.schema().edgeLabel("emailed").drop()

      Set the graph test_graph to analytics mode and run a cleanup:

      // Set the graph to OLAP mode
      :remote config alias g test_graph.a
      =// Run the cleanup
      graph.cleanUp()

      The results details the cleanup actions:

      ==>
      Edges with unknown labels deleted:      8
      Orphaned edges deleted:                 0
      Unattached vertex properties deleted:   0
      Graph cleanup finished at 20 seconds
      
      Please run `nodetool repair -pr test_graph` on each cluster node to finish the cleanup

      Note that a nodetool repair command will be required post-cleanup.

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