Hash¶
The hash()
function 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 MurmurHahs2.h
.
NOTE: Roughly, The chance of collision is about 1/10 in the case of 1 billion vertices. The number of edges is irrelevant to the collision possibility.
For Java, call like follows.
MurmurHash2.hash64("to_be_hashed".getBytes(),"to_be_hashed".getBytes().length, 0xc70f6907)
Legacy version compatibility¶
In nGQL 1.0, when nGQL does not support string VIDs, a common practice is to hash the strings first and then use the values as VIDs. But in nGQL 2.0, both string VIDs and integer VIDs are supported, you don't have to use hash()
to make VIDs.
Hash a number¶
nebula> YIELD hash(-123);
+--------------+
| hash(-(123)) |
+--------------+
| -123 |
+--------------+
Hash a string¶
nebula> YIELD hash("to_be_hashed");
+----------------------+
| hash(to_be_hashed) |
+----------------------+
| -1098333533029391540 |
+----------------------+
Hash a list¶
nebula> YIELD hash([1,2,3]);
+----------------+
| hash([1,2,3]) |
+----------------+
| 11093822460243 |
+----------------+
Hash a boolean¶
nebula> YIELD hash(true);
+------------+
| hash(true) |
+------------+
| 1 |
+------------+
nebula> YIELD hash(false);
+-------------+
| hash(false) |
+-------------+
| 0 |
+-------------+
Hash NULL¶
nebula> YIELD hash(NULL);
+------------+
| hash(NULL) |
+------------+
| -1 |
+------------+
Hash an expression¶
nebula> YIELD hash(toLower("HELLO NEBULA"));
+-------------------------------+
| hash(toLower("HELLO NEBULA")) |
+-------------------------------+
| -8481157362655072082 |
+-------------------------------+
Last update: April 1, 2021