CSV data file format

Updated at:

This topic describes the Comma-Separated Values (CSV) data file format for importing data into a Graph Database (GDB) instance.

Background information

CSV data files follow the RFC 4180 specification. For more information, see Common Format and MIME Type for Comma-Separated Values (CSV) Files.

Important

All files must be encoded in UTF-8 format.

Usage notes

  • Place vertices and edges in separate files.

    Note

    The loader can load multiple vertex files and multiple edge files in a single load task.

  • For each load task, all files to be loaded must be in the same folder of a bucket. You cannot use file names or file name extensions to distinguish vertex files from edge files.

  • Each file must contain a header row. This row consists of comma-separated system and property column headings.

    The header row is the first row of the data file and ends with \n or \r\n. The row does not support special characters such as double quotation marks and line feeds. All characters except the comma (,) separator are parsed as header content.

System column headings

Header type

Parameter/Syntax

Required

Description

Point Title

~id

Yes

The ID of the vertex.

~label

Yes

The label of the vertex. Only a single label is supported.

Edge header

~id

Yes

The ID of the edge.

~from

Yes

The ID of the source vertex.

~to

Yes

The ID of the destination vertex.

~label

Yes

The label of the edge. Only a single label is supported.

Property column headings

  • To specify an attribute column for a regular property, use the following syntax. The type name is case-insensitive.

    propertyname:type
    Important
    • Column headings cannot contain spaces. Therefore, property names cannot contain spaces.

    • Properties do not support the List data type. A property can have only one value.

    Example: Specify the column heading for a property named age of the Int type.

    Each row in the file must have an integer value in this column or be left empty.

    age:Int
  • To specify an attribute column for a SET property, use one of the following syntaxes.

    Important

    In Graph Database (GDB), only vertices support SET properties. Edges do not support SET properties. An error occurs if you set a SET property for an edge.

    # Compatible with the default format for regular single-value properties.
    propertyname:type
    
    # Regular single-value property.
    propertyname:type(single)
    
    # SET property. The data row contains a single value.
    propertyname:type(set)
    
    # SET property. The data row contains multiple values.
    propertyname:type[]
    
    # SET property. The data row contains multiple values.
    propertyname:type(set)[]

Row format

Item

Description

Separators

Fields in a row are separated by commas. Rows are separated by line feeds (\n) or carriage return line feeds (\r\n).

Blank fields

Blank fields are allowed for non-required columns, such as user-defined properties. Blank fields still require comma separators.

Vertex ID

The ~id values of all vertices in each vertex file must be unique. Multiple vertex rows that have the same ~id value apply to a single vertex in the graph.

Edge ID

The ~id values of all edges in each edge file must be unique. Multiple edge rows that have the same ~id value apply to a single edge in the graph.

Labels

Labels are case-sensitive strings.

String values

Quotation marks are optional. If a string contains special characters such as commas, you must enclose the string in double quotation marks ("").

propertyname:type(set)

SET property field. This indicates that the data field is a property value of the propertyname property and the type is type.

Important

When you overwrite a SET property, a property value is appended. If the original property is a regular property, it becomes a SET property after the update.

propertyname:type(set)[]

SET property field. This indicates that the data field is an array of property values for the propertyname property. The array elements are of the type type. Array elements are separated by semicolons (;).

Property overwrite logic

Original property logic

New property logic

Result

Regular property

Regular property

The original property value is overwritten. The last written value is retained.

Regular property

SET property

The property is updated to a SET property. The original property value is merged as a value in the SET.

SET property

SET property

The SET property is appended. The property values are the union of the old and new values.

SET property

Regular property

The property is updated to a regular property. The property value is the last written value.

CSV file format specifications

The format specifications for SET properties are as follows:

  • Single-value field for a SET property: The format is the same as the original parsing format. The parsed value is treated as a single element of the SET property.

  • Array field for a SET property: Use semicolons (;) to separate array elements. For example, an integer array field can be 32;45;12.

  • Array field for a SET property: You can enclose the entire field in double quotation marks (""). The double quotation marks at the beginning and end of the field are removed during parsing. For example, an integer array field can be "32;45;12".

  • If an array field for a SET property is a string, an array element cannot contain a semicolon (;) because semicolons are parsed as element separators.

Data types

Property value type

Field type

Value range

Bool or Boolean

Boolean

  • FALSE or false

  • TRUE or true

Integer

char

-128 to 127

short

-32768 to 32767

int

-2^31 to 2^31 - 1

long

-2^63 to 2^63 - 1

Decimal

Note

Decimal notation or scientific notation is supported. (+/-)INFINITY or NaN is not supported.

float

32-bit IEEE 754 floating-point

double

64-bit IEEE 754 floating-point

String

string

  • Double quotation marks are optional.

  • If a string contains special characters, such as commas (,), line feeds (\r\n or \n), or double quotation marks (""), you must enclose the string in double quotation marks (""). Example: "Hello,World"

  • If a string enclosed in double quotation marks contains double quotation marks, escape the inner double quotation marks with two double quotation marks based on CSV rules. Example: "Hello""World"""

  • If a string does not contain special characters, you do not need to enclose it in double quotation marks.

  • Zero-length empty strings are supported and are represented as "". A blank field that is not enclosed in double quotation marks indicates that no value exists and is treated as nullptr.

General examples

  • Graph Database (GDB) data file (TinkerPop modern graph)

    示意图

  • The CSV data files are as follows:

    Dotfile

    ~id

    ~label

    name:string

    lang:string

    age:int

    1

    person

    marko

    29

    2

    person

    vadas

    27

    3

    software

    lop

    java

    4

    person

    josh

    32

    5

    software

    ripple

    java

    6

    person

    peter

    35

    Edge file

    ~id

    ~from

    ~to

    ~label

    weight:double

    7

    1

    2

    knows

    0.5

    8

    1

    4

    knows

    1.0

    9

    1

    3

    created

    0.4

    10

    4

    5

    created

    1.0

    11

    4

    3

    created

    0.4

    12

    6

    3

    created

    0.2

SET property examples

CSV data file

~id

~label

fruits:string(set)[]

codes:long(set)[]

1

person

apple;pear

22

2

person

banana;bitterorange

25;81

3

person

"cherry;blackberry;grape"

3;12

4

person

"54;11"