SAMPLE¶
The SAMPLE
clause takes samples evenly in the result set and returns the specified amount of data.
SAMPLE
can be used in GO
statements only. The syntax is as follows:
<go_statement> SAMPLE <sample_list>;
sample_list
is a list. Elements in the list must be natural numbers, and the number of elements must be the same as the maximum number of STEPS
in the GO
statement. The following takes GO 1 TO 3 STEPS FROM "A" OVER * SAMPLE <sample_list>
as an example to introduce this usage of SAMPLE
in detail.
- The list
sample_list
must contain 3 natural numbers, such asGO 1 TO 3 STEPS FROM "A" OVER * SAMPLE [1,2,4]
. 1
inSAMPLE [1,2,4]
means that the system automatically selects 1 edge to continue traversal in the first step.2
means to select 2 edges to continue traversal in the second step.4
indicates that 4 edges are selected to continue traversal in the third step. If there is no matched edge in a certain step or the number of matched edges is less than the specified number, the actual number will be returned.- Because
GO 1 TO 3 STEPS
means to return all the traversal results from the first to third steps, all the red edges and their source and destination vertices in the figure below will be matched by thisGO
statement. And the yellow edges represent there is no path selected when the GO statement traverses. If it is notGO 1 TO 3 STEPS
butGO 3 STEPS
, it will only match the red edges of the third step and the vertices at both ends.
In the basketballplayer dataset, the example is as follows:
nebula> GO 3 STEPS FROM "player100" \
OVER * \
YIELD properties($$).name AS NAME, properties($$).age AS Age \
SAMPLE [1,2,3];
+-----------------+----------+
| NAME | Age |
+-----------------+----------+
| "Tony Parker" | 36 |
| "Manu Ginobili" | 41 |
| "Spurs" | __NULL__ |
+-----------------+----------+
nebula> GO 1 TO 3 STEPS FROM "player100" \
OVER * \
YIELD properties($$).name AS NAME, properties($$).age AS Age \
SAMPLE [2,2,2];
+-----------------+----------+
| NAME | Age |
+-----------------+----------+
| "Manu Ginobili" | 41 |
| "Spurs" | __NULL__ |
| "Tim Duncan" | 42 |
| "Spurs" | __NULL__ |
| "Manu Ginobili" | 41 |
| "Spurs" | __NULL__ |
+-----------------+----------+
Last update:
October 25, 2023