vertexLabel
How to create a vertex label.
Synopsis
schema.vertexLabel('vertexLabel').
[ materializedView('indexName'). | secondaryIndex('indexName'). | searchIndex('indexName'). ]
[ by('propertyName'). ]
[ waitForIndex(). ]
[ tableName('tableName'). ]
[fromExistingTable('tableName') ]
[ ifNotExists(). ]
partitionBy('propertyName', propertyType). [ ... ]
[ clusterBy('propertyName', propertyType). ... ]
[ property('propertyName', propertyType [ , static | , ( Desc | Asc )] ). ]
[ create() | describe() | drop() | ( addProperty | dropProperty )('propertyName', propertyType).alter() ]
Description
A vertex label specifies a type of vertex that can be stored in DataStax Graph (DSG). A
vertex label must have a defined partition key, and can have, in addition, properties,
clustering keys, and indexes defined. The
partitionBy
and
clusteringBy
are used to specify a vertex id, identifying the partition
storage location and order within the partition, respectively.CAUTION: DataStax Graph limits the number of vertex
and edge labels to 200 per graph.
- materializedView, secondaryIndex, searchIndex
-
Set an index for a vertex label.
- ifNotExists
- Check for lack of current existence with
ifNotExists()
before creating a new vertex label. - tableName
- Specify a table name for the CQL table that holds the vertex label data.
- partitionBy
-
Specify a vertex label partition location. The value consists of one or more properties, with multiple properties forming a composite partition key. Which partition the data will be stored on is defined with this step.
- clusteringBy
-
Specify whether a vertex label can have any clustering columns. The value consists of one or more properties that specify how data will be stored within a partition.
- property
- Properties can be defined for vertices and edges. Allowed characters for the name
are alphabetical or underscore. Properties can also be declared
static
to correspond to a static CQL table column. - create
- Create a vertex label.
- describe
- Describe a vertex label.
- drop
- Drop a vertex label.
- addProperty.alter, dropProperty.alter
- Add or drop a property by altering a previously created vertex label.
- fromExistingTable
- Convert an existing CQL table into a vertex label.
Examples
Create a vertex label
person
with a single
partitionBy
:schema.vertexLabel('person'). ifNotExists(). partitionBy('person_id', Uuid). property('name', Text). property('gender', Text). property('nickname', setOf(Text)). property('cal_goal', Int). property('macro_goal', listOf(Int)). property('country', listOf(tupleOf(Text, Date, Date))). property('badge', mapOf(Text, Date)). create()This vertex label is created if it doesn't already exist, has a single partition
person_id
, and several properties of varying data types.Create a vertex label
person
with a compound partition key, two
partitionBy
steps:schema.vertexLabel('meal'). ifNotExists(). partitionBy('type', Text). partitionBy( 'meal_id', Int). create()
Create a vertex label
person
with a composite primary key, three
partitionBy
steps and a clusterBy
step:schema.vertexLabel('fridge_sensor'). ifNotExists(). partitionBy('state_id', Int). partitionBy('city_id', Int). partitionBy('zipcode_id', Int). clusterBy('sensor_id', Int). property('name', Text). create()
Create a vertex label
shopping_list
with a
tableName
:schema.vertexLabel('shopping_list'). tableName('my_shopping'). ifNotExists(). partitionBy('shoplist_id', Int). create()The CQL table will be named
my_shopping
, while the vertex label is
shopping_list
.Convert a CQL table into a vertex
label:
schema.vertexLabel('recipe'). fromExistingTable('recipe_table'). create()
Add a property to a vertex
label:
schema.vertexLabel('book'). addProperty('book_discount', Text). alter()
A quick reference to indexes is included here, see indexes for more thorough information.
Create a materialized view index on a vertex
label:
schema.vertexLabel('person'). materializedView('person_by_name'). ifNotExists(). partitionBy('name'). create()
Create a secondary index on a vertex
label:
schema.vertexLabel('person'). secondaryIndex('person_2i_by_nickname'). ifNotExists(). by('nickname'). indexValues(). create()
Create a search index on a vertex
label:
schema.vertexLabel('recipe'). searchIndex(). ifNotExists(). by('instructions').asText(). by('name'). by('cuisine'). waitForIndex(30). create()The
waitForIndex
step can be added to any index creation, to allow a pause
for index building to occur.Get the schema creation command for all vertex labels using the
describe()
command:schema.vertexLabels().describe()
Get the schema creation command for a vertex label using the
describe()
command:schema.vertexLabel('person').describe()
Drop a vertex
label:
schema.vertexLabel('book'). ifExists(). drop()
Drop a property from a vertex
label:
schema.vertexLabel('person'). dropProperty('gender'). alter()
Drop an index for a vertex
label:
schema.vertexLabel('person'). materializedView('person_by_gender'). ifExists(). drop()
Drop an index for a vertex
label:
schema.vertexLabel('store'). searchIndex(). dropProperty('name'). alter()