Skip to content

[TINKERPOP-3261] Enable multiple labels on vertex with configurable label cardinality#3483

Open
xiazcy wants to merge 4 commits into
masterfrom
multi-label-experiment
Open

[TINKERPOP-3261] Enable multiple labels on vertex with configurable label cardinality#3483
xiazcy wants to merge 4 commits into
masterfrom
multi-label-experiment

Conversation

@xiazcy

@xiazcy xiazcy commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

Introduces configurable label cardinality for graph elements. Vertex cardinality is user-configurable; edge cardinality defaults to ONE and is not yet exposed as a configuration option but uses the same underlying infrastructure.

Vertices can now have zero, one, or many labels controlled by LabelCardinality (defaults to ONE for full backward compatibility). New traversal steps labels(), addLabel(), dropLabel(), and dropLabels() enable label retrieval and mutation. Edge labels remain fixed at cardinality ONE.

Notes on design:

  • LabelCardinality is a pure data descriptor enum with min()/max()/mutable fields. Validation logic lives in a separate LabelCardinalityValidator utility.
  • mergeV() uses append-only semantics for onMatch labels (no implicit replacement).
  • hasLabel('a','b') is OR semantics, use hasLabel('a').hasLabel('b') for AND semantics.
  • with("multilabel") is source-level setting for backwards compatibility. Configures elementMap()/valueMap() to return labels as a Set instead of a single String by default.
  • Older serialization formats (GraphSON V1/V2/V3, Gryo) silently use label() which returns one non-deterministic label. Only GraphBinary and GraphSON V4 preserve the full label set.

Commits:

  1. Core data model, steps, and grammar - LabelCardinality enum, Element.labels(), addLabel()/dropLabels() steps, LabelsStep, LabelsDropVerificationStrategy, MergeVertex multi-label, elementMap()/valueMap() label output via with("multilabel")/with("singlelabel"), GremlinLang propagation, grammar rules, GraphBinary V4 serialization, Java test infrastructure (@MultiLabel/@MultiLabelDefault/@SingleLabelDefault tags)
  2. TinkerGraph reference implementation - TinkerVertex multi-label storage (CopyOnWriteArraySet), vertexLabelCardinality configuration property, unit tests
  3. GLV implementations (Go, Python, JS, .NET) - GremlinLang with("multilabel")/with("singlelabel") propagation in all GLVs (both strategy-creation and strategy-exists paths), Go With() now variadic (single-arg works), feature test matrix with @MultiLabel/@MultiLabelDefault tags, existing tests use with("singlelabel") for provider safety, Docker server config, Cucumber infrastructure
  4. Documentation - Upgrade docs (users + providers), reference docs (elementMap/valueMap/labels/addLabel), TinkerGraph config, provider semantics, for-committers gherkin tags, CHANGELOG

Configuration

To Enable multi-label in TinkerGraph:
gremlin.tinkergraph.vertexLabelCardinality=ZERO_OR_MORE

Testing

  • Feature tests (Gherkin): Labels.feature, AddLabel.feature, DropLabel.feature, ElementMap.feature, ValueMap.feature (multi-label matrix)
  • Unit tests: LabelMutationStepTest, LabelCardinalityTest, LabelReplacePatternValidationTest, MergeVMultiLabelTest, TinkerVertexMultiLabelTest

VOTE +1

@xiazcy xiazcy force-pushed the multi-label-experiment branch 5 times, most recently from ac8825a to 9d2e0fe Compare June 27, 2026 00:33
@xiazcy xiazcy marked this pull request as ready for review June 27, 2026 00:34
xiazcy added 4 commits June 26, 2026 18:26
- LabelCardinality enum (ONE, ONE_OR_MORE, ZERO_OR_MORE) on Graph.Features
- Element.labels() returns Set<String>, addLabel()/dropLabels() mutation steps
- LabelsStep for g.V().labels() traversal
- LabelCardinalityValidator for constraint enforcement
- LabelsDropVerificationStrategy prevents accidental label removal
- MergeVertex supports multi-label via T.label list in merge map
- elementMap()/valueMap() label output controlled by with("multilabel")/with("singlelabel")
- GremlinLang propagates with("multilabel")/with("singlelabel") in gremlin text
- Grammar rules for addLabel(), dropLabels(), labels(), addV(String...)
- Java test infrastructure: World.getMultiLabelGraphTraversalSource(),
  @MultiLabel/@MultiLabelDefault/@SingleLabelDefault tags
- GraphBinary V4 serialization for multi-label vertices/edges
- TinkerVertex stores labels as CopyOnWriteArraySet
- TinkerGraph.vertexLabelCardinality configuration property
- addLabel/dropLabels wired to TinkerVertex mutation
- Unit tests for label cardinality, mutation, merge, and GremlinLang
- GremlinLang with("multilabel")/with("singlelabel") propagation in all GLVs
- Fix: render options in gremlin text both when OptionsStrategy is first created
  and when it already exists (from prior with() calls like with("language",...))
- Go: With() method now variadic (single-arg g.With("multilabel") works)
- Feature tests: full matrix for valueMap/elementMap with @multilabel,
  @MultiLabelDefault, @SingleLabelDefault tags
- Existing valueMap/elementMap tests use with("singlelabel") for provider safety
- Test infrastructure: @MultiLabelDefault uses gmultilabel + with("multilabel")
  programmatically (no server-side YAML config needed)
- Docker gremlin-server-integration.yaml: multilabel graph config
- Cucumber support in all GLVs: terrain/world/steps handle multilabel graphs
- Upgrade docs: user guide for with("multilabel")/with("singlelabel"),
  provider guide for LabelCardinality and step overrides
- Reference docs: elementMap/valueMap label format, TinkerGraph configuration
- Provider semantics: valueMap with-options section
- For-committers: @MultiLabel/@MultiLabelDefault/@SingleLabelDefault gherkin tags
- CHANGELOG entry
@xiazcy xiazcy force-pushed the multi-label-experiment branch from 9d2e0fe to be5072e Compare June 27, 2026 01:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant