Meta-property of properties

A meta-property allows a property to store another property.

  • Meta-property

  • Create schema for a meta-properties start_date and end_date and create an author vertex label with the property country:

    schema.propertyKey("name").Text().single().create()
    schema.propertyKey('start_date').Date().create()
    schema.propertyKey('end_date').Date().create()
    schema.propertyKey('country').Text().multiple().properties('start_date','end_date').create()
    schema.vertexLabel("author").properties("name", 'country').create()

    The meta-properties start_date and end_date are first created as propertyKeys. Then the meta-properties are assigned to the property country using the properties() method.

    ==>{item_mult=[cheddar cheese, cheese], name=[item1]}
    ==>{item_mult=[Greek yogurt, key lime yogurt, yogurt], name=[item2]}
  • Now create a vertex:

    julia=graph.addVertex(label,'author', 'name', 'Julia Child')
    props=julia.property(list,'country','France')
    props.property('start_date', '1950-01-01')
    props.property('end_date', '1960-12-31')
    props2 = julia.property(list, 'country', 'USA')
    props2.property('start_date', '1961-01-01')
    props2.property('end_date', '1984-06-23')

    This vertex for Julia Child has two values for the property country, each of which has values for the two meta-properties.

    An alternative vertex creation statement is:

    g.addV('author').
      property('name', 'Emeril Lagasse').
      property('country', 'France', 'start_date', '1973-10-01', 'end_date','1973-09-09').
      property('country', 'USA, 'start_date', '1973-10-01', 'end_date', '2017-03-10')

    Either method is acceptable.

  • Explore the inserted properties:

    First, find the listed countries that any author has lived in:

    g.V().properties()
    ==>vp[name->Julia Child]
    ==>vp[country->France]
    ==>vp[country->USA]
    ==>vp[name->Emeril]
    ==>vp[country->France]
    ==>vp[country->USA]

    Next, list all the meta-properties of any listed country:

    g.V().properties().properties()
    ==>p[start_date->1950-01-01]
    ==>p[end_date->1960-12-31]
    ==>p[start_date->1961-01-01]
    ==>p[end_date->1984-06-23]
    ==>p[start_date->1970-04-05]
    ==>p[end_date->1973-09-09]
    ==>p[start_date->1973-02-02]
    ==>p[end_date->2017-03-01]

    Find specific meta-property values for a given country by adding the hasValue() method:

    g.V().properties('country').hasValue('France').properties()
    ==>p[start_date->1950-01-01]
    ==>p[end_date->1960-12-31]
    ==>p[start_date->1970-04-05]
    ==>p[end_date->1973-09-09]

    Find just the values of the meta-properties:

    g.V().properties('country').hasValue('France').properties().value()
    ==>1950-01-01
    ==>1960-12-31
    ==>1970-04-05
    ==>1973-09-09

    Find the starting date in which an author moved to each country:

    g.V().as('author').
        properties('country').as('country').
        has('start_date').as('start_living_in').
    select('author','country','start_living_in').
        by('name').
        by(value).
        by('start_date')

    This query uses the designator author to store the author’s name, then traverses the country property for each country lived in, designated country. From each country, the start date is found by an additional traversal and designated as started_living_in.Finally, all three values are selected for each full path traversal and the results are printed, using the designators to map the values. Entering this query into DSE Studio yields the following results:

    {
      "author": "Julia Child",
      "country": "France",
      "start_living_in": "1950-01-01"
    },
    {
      "author": "Julia Child",
      "country": "USA",
      "start_living_in": "1961-01-01"
    },
    {
      "author": "Emeril",
      "country": "France",
      "start_living_in": "1970-04-05"
    },
    {
      "author": "Emeril",
      "country": "USA",
      "start_living_in": "1973-02-02"
    }

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