graflo.db.nebula.util¶
NebulaGraph utility functions.
Type mapping, filter rendering, value escaping, and schema-propagation helpers.
Attributes¶
DEFAULT_NEBULA_TYPE = 'string'
module-attribute
¶
FIELD_TYPE_TO_NEBULA = {FieldType.INT: 'int64', FieldType.UINT: 'int64', FieldType.FLOAT: 'float', FieldType.DOUBLE: 'double', FieldType.BOOL: 'bool', FieldType.STRING: 'string', FieldType.DATETIME: 'string', FieldType.UUID: 'string'}
module-attribute
¶
NEBULA_TYPE_TO_FIELD_TYPE = {'int': FieldType.INT, 'int8': FieldType.INT, 'int16': FieldType.INT, 'int32': FieldType.INT, 'int64': FieldType.INT, 'float': FieldType.FLOAT, 'double': FieldType.DOUBLE, 'bool': FieldType.BOOL, 'string': FieldType.STRING, 'date': FieldType.DATETIME, 'time': FieldType.DATETIME, 'datetime': FieldType.DATETIME, 'timestamp': FieldType.DATETIME}
module-attribute
¶
VID_SEPARATOR = '::'
module-attribute
¶
logger = logging.getLogger(__name__)
module-attribute
¶
Classes¶
Functions:¶
edge_rank(props, identity_fields)
¶
The rank of an edge whose identity holds identity_fields besides its endpoints.
NebulaGraph tells edges of one type between the same vertices apart by
rank alone, so such an edge takes a signed 64-bit digest of those values,
rendered as :func:vertex_key renders identities. None (rank 0) when
there are none.
Source code in graflo/db/nebula/util.py
escape_nebula_string(value)
¶
field_type_from_nebula(declared)
¶
Map a DESCRIBE TAG / DESCRIBE EDGE type back to a FieldType.
Returns None for a type this mapping does not cover, so the caller can
leave the field untyped rather than assert a wrong one.
Source code in graflo/db/nebula/util.py
fitted_vid_length(schema, string_length)
¶
Bytes a FIXED_STRING VID needs for every vertex of schema.
A VID is tag::v1::v2… (:func:make_vid); a value whose type bounds its
text takes that bound, any other string_length. Rounded up to 8 bytes.
Without a schema: one string value under a tag of up to 64 bytes.
Source code in graflo/db/nebula/util.py
is_nebula_string_field(field)
¶
Whether field becomes a variable-length string column.
Index DDL must ask the same question the column DDL answered: Nebula
rejects CREATE TAG INDEX on a string column given without a length.
Testing field.type == FieldType.STRING is not that question — an
untyped field, a DATETIME and a UUID all land on string too,
and an index over any of them is rejected as Invalid param!.
Source code in graflo/db/nebula/util.py
key_of_vid(vid)
¶
:func:vertex_key of a VID: what follows the tag. A tag name has no ::.
make_vid(tag, doc, match_keys)
¶
The VID of doc as a vertex of tag, keyed on match_keys.
nebula_type(ft)
¶
Map a scalar graflo FieldType to the corresponding NebulaGraph type name.
LIST is not storable as a Nebula property — use :func:nebula_type_for_field.
Source code in graflo/db/nebula/util.py
nebula_type_for_field(field)
¶
Map a Field to a NebulaGraph DDL type, raising for unsupported types.
render_filters_cypher(filters, doc_name)
¶
Render a FilterExpression as a Cypher WHERE clause (without the keyword).
Source code in graflo/db/nebula/util.py
render_filters_ngql(filters, doc_name)
¶
Render a FilterExpression as an nGQL WHERE clause (without the keyword).
Source code in graflo/db/nebula/util.py
serialize_nebula_value(value)
¶
Serialise a Python value into an nGQL literal string.
Source code in graflo/db/nebula/util.py
tag_vid(tag, key)
¶
The VID of the vertex of tag whose :func:vertex_key is key.
The tag leads the VID because a VID is space-wide: without it, vertices of two tags with the same identity values would be one vertex carrying both tags, and would share their edges.
Source code in graflo/db/nebula/util.py
vertex_key(doc, match_keys)
¶
A vertex's identity values joined with ::: its VID without the tag.
wait_for_schema_propagation(adapter, check_statement, *, max_retries=30, interval=1.0)
¶
Poll check_statement until it succeeds or retries are exhausted.
NebulaGraph propagates schema changes asynchronously across the cluster.
After CREATE SPACE / CREATE TAG / CREATE EDGE, subsequent
statements may fail until propagation completes (typically within two
heartbeat cycles, ~20 s for default settings).
Source code in graflo/db/nebula/util.py
wait_for_space_ready(adapter, space_name, *, max_retries=30, interval=1.0)
¶
Wait until SE `space_name succeeds.