Type conversion functions¶
This topic describes the type conversion functions supported by NebulaGraph.
toBoolean()¶
toBoolean() converts a string value to a boolean value.
Syntax: toBoolean(<value>)
- Result type: Bool
Example:
nebula> UNWIND [true, false, 'true', 'false', NULL] AS b \
RETURN toBoolean(b) AS b;
+----------+
| b |
+----------+
| true |
| false |
| true |
| false |
| __NULL__ |
+----------+
toFloat()¶
toFloat() converts an integer or string value to a floating point number.
Syntax: toFloat(<value>)
- Result type: Float
Example:
nebula> RETURN toFloat(1), toFloat('1.3'), toFloat('1e3'), toFloat('not a number');
+------------+----------------+----------------+-------------------------+
| toFloat(1) | toFloat("1.3") | toFloat("1e3") | toFloat("not a number") |
+------------+----------------+----------------+-------------------------+
| 1.0 | 1.3 | 1000.0 | __NULL__ |
+------------+----------------+----------------+-------------------------+
toString()¶
toString() converts non-compound types of data, such as numbers, booleans, and so on, to strings.
Syntax: toString(<value>)
- Result type: String
Example:
nebula> RETURN toString(9669) AS int2str, toString(null) AS null2str;
+---------+----------+
| int2str | null2str |
+---------+----------+
| "9669" | __NULL__ |
+---------+----------+
toInteger()¶
toInteger() converts a floating point or string value to an integer value.
Syntax: toInteger(<value>)
- Result type: Int
Example:
nebula> RETURN toInteger(1), toInteger('1'), toInteger('1e3'), toInteger('not a number');
+--------------+----------------+------------------+---------------------------+
| toInteger(1) | toInteger("1") | toInteger("1e3") | toInteger("not a number") |
+--------------+----------------+------------------+---------------------------+
| 1 | 1 | 1000 | __NULL__ |
+--------------+----------------+------------------+---------------------------+
toSet()¶
toSet() converts a list or set value to a set value.
Syntax: toSet(<value>)
- Result type: Set
Example:
nebula> RETURN toSet(list[1,2,3,1,2]) AS list2set;
+-----------+
| list2set |
+-----------+
| {3, 1, 2} |
+-----------+
hash()¶
hash() returns the hash value of the argument. The argument can be a number, a string, a list, a boolean, null, or an expression that evaluates to a value of the preceding data types.
The source code of the hash()
function (MurmurHash2), seed (0xc70f6907UL
), and other parameters can be found in MurmurHash2.h
.
For Java, the hash function operates as follows.
MurmurHash2.hash64("to_be_hashed".getBytes(),"to_be_hashed".getBytes().length, 0xc70f6907)
Syntax: hash(<string>)
- Result type: Int
Example:
nebula> RETURN hash("abcde");
+--------------------+
| hash("abcde") |
+--------------------+
| 811036730794841393 |
+--------------------+
nebula> YIELD hash([1,2,3]);
+----------------+
| hash([1,2,3]) |
+----------------+
| 11093822460243 |
+----------------+
nebula> YIELD hash(NULL);
+------------+
| hash(NULL) |
+------------+
| -1 |
+------------+
nebula> YIELD hash(toLower("HELLO NEBULA"));
+-------------------------------+
| hash(toLower("HELLO NEBULA")) |
+-------------------------------+
| -8481157362655072082 |
+-------------------------------+