Skip to content

Commit 02ee33e

Browse files
ahkcsmanasvinibs
andauthored
Add more examples to the where command doc (#4457)
Co-authored-by: Manasvini B S <[email protected]>
1 parent 0b7e86c commit 02ee33e

File tree

1 file changed

+134
-3
lines changed

1 file changed

+134
-3
lines changed

docs/user/ppl/cmd/where.rst

Lines changed: 134 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,21 @@ where
1010

1111

1212
Description
13-
============
13+
===========
1414
| The ``where`` command bool-expression to filter the search result. The ``where`` command only return the result when bool-expression evaluated to true.
1515
1616

1717
Syntax
18-
============
18+
======
1919
where <boolean-expression>
2020

2121
* bool-expression: optional. any expression which could be evaluated to boolean value.
2222

23+
Examples
24+
========
25+
2326
Example 1: Filter result set with condition
24-
===========================================
27+
--------------------------------------------
2528

2629
The example show fetch all the document from accounts index with .
2730

@@ -36,3 +39,131 @@ PPL query::
3639
| 13 | F |
3740
+----------------+--------+
3841

42+
Example 2: Basic Field Comparison
43+
----------------------------------
44+
45+
The example shows how to filter accounts with balance greater than 30000.
46+
47+
PPL query::
48+
49+
os> source=accounts | where balance > 30000 | fields account_number, balance;
50+
fetched rows / total rows = 2/2
51+
+----------------+---------+
52+
| account_number | balance |
53+
|----------------+---------|
54+
| 1 | 39225 |
55+
| 13 | 32838 |
56+
+----------------+---------+
57+
58+
Example 3: Pattern Matching with LIKE
59+
--------------------------------------
60+
61+
Pattern Matching with Underscore (_)
62+
63+
The example demonstrates using LIKE with underscore (_) to match a single character.
64+
65+
PPL query::
66+
67+
os> source=accounts | where LIKE(state, 'M_') | fields account_number, state;
68+
fetched rows / total rows = 1/1
69+
+----------------+-------+
70+
| account_number | state |
71+
|----------------+-------|
72+
| 18 | MD |
73+
+----------------+-------+
74+
75+
Pattern Matching with Percent (%)
76+
77+
The example demonstrates using LIKE with percent (%) to match multiple characters.
78+
79+
PPL query::
80+
81+
os> source=accounts | where LIKE(state, 'V%') | fields account_number, state;
82+
fetched rows / total rows = 1/1
83+
+----------------+-------+
84+
| account_number | state |
85+
|----------------+-------|
86+
| 13 | VA |
87+
+----------------+-------+
88+
89+
Example 4: Multiple Conditions
90+
-------------------------------
91+
92+
The example shows how to combine multiple conditions using AND operator.
93+
94+
PPL query::
95+
96+
os> source=accounts | where age > 30 AND gender = 'M' | fields account_number, age, gender;
97+
fetched rows / total rows = 3/3
98+
+----------------+-----+--------+
99+
| account_number | age | gender |
100+
|----------------+-----+--------|
101+
| 1 | 32 | M |
102+
| 6 | 36 | M |
103+
| 18 | 33 | M |
104+
+----------------+-----+--------+
105+
106+
Example 5: Using IN Operator
107+
-----------------------------
108+
109+
The example demonstrates using IN operator to match multiple values.
110+
111+
PPL query::
112+
113+
os> source=accounts | where state IN ('IL', 'VA') | fields account_number, state;
114+
fetched rows / total rows = 2/2
115+
+----------------+-------+
116+
| account_number | state |
117+
|----------------+-------|
118+
| 1 | IL |
119+
| 13 | VA |
120+
+----------------+-------+
121+
122+
Example 6: NULL Checks
123+
----------------------
124+
125+
The example shows how to filter records with NULL values.
126+
127+
PPL query::
128+
129+
os> source=accounts | where ISNULL(employer) | fields account_number, employer;
130+
fetched rows / total rows = 1/1
131+
+----------------+----------+
132+
| account_number | employer |
133+
|----------------+----------|
134+
| 18 | null |
135+
+----------------+----------+
136+
137+
Example 7: Complex Conditions
138+
------------------------------
139+
140+
The example demonstrates combining multiple conditions with parentheses and logical operators.
141+
142+
PPL query::
143+
144+
os> source=accounts | where (balance > 40000 OR age > 35) AND gender = 'M' | fields account_number, balance, age, gender;
145+
fetched rows / total rows = 1/1
146+
+----------------+---------+-----+--------+
147+
| account_number | balance | age | gender |
148+
|----------------+---------+-----+--------|
149+
| 6 | 5686 | 36 | M |
150+
+----------------+---------+-----+--------+
151+
152+
Example 8: NOT Conditions
153+
--------------------------
154+
155+
The example shows how to use NOT operator to exclude matching records.
156+
157+
PPL query::
158+
159+
os> source=accounts | where NOT state = 'CA' | fields account_number, state;
160+
fetched rows / total rows = 4/4
161+
+----------------+-------+
162+
| account_number | state |
163+
|----------------+-------|
164+
| 1 | IL |
165+
| 6 | TN |
166+
| 13 | VA |
167+
| 18 | MD |
168+
+----------------+-------+
169+

0 commit comments

Comments
 (0)