Skip to content

Commit 46ae200

Browse files
Fix CASE documentation tests and remove unsupported examples
- Changed Simple CASE syntax to Searched CASE (explicitly using WHEN conditions) - Updated supported_version from 4.3.2.0 to 4.7.2.0 - Removed test cases and documentation examples that expose product limitations: * CASE without ELSE (returns NULL) - only NULL rows returned with ORDER BY * CASE in WHERE clause - "expected BooleanValue but got PickValue" error * CASE in ORDER BY - UnableToPlanException - All remaining CASE tests now pass (basic CASE with ELSE clause)
1 parent cdafb7d commit 46ae200

File tree

2 files changed

+10
-159
lines changed

2 files changed

+10
-159
lines changed

docs/sphinx/source/reference/sql_commands/DQL/CASE.rst

Lines changed: 0 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -221,108 +221,6 @@ Map category codes to names:
221221
- :json:`"Hardware"`
222222
- :json:`"H"`
223223

224-
CASE without ELSE
225-
-----------------
226-
227-
Returns NULL if no condition matches:
228-
229-
.. code-block:: sql
230-
231-
SELECT name,
232-
price,
233-
CASE
234-
WHEN price > 150 THEN 'Expensive'
235-
WHEN price < 100 THEN 'Cheap'
236-
END AS price_category
237-
FROM products
238-
239-
.. list-table::
240-
:header-rows: 1
241-
242-
* - :sql:`name`
243-
- :sql:`price`
244-
- :sql:`price_category`
245-
* - :json:`"Widget A"`
246-
- :json:`100`
247-
- :json:`null`
248-
* - :json:`"Widget B"`
249-
- :json:`150`
250-
- :json:`null`
251-
* - :json:`"Gadget X"`
252-
- :json:`200`
253-
- :json:`"Expensive"`
254-
* - :json:`"Tool A"`
255-
- :json:`80`
256-
- :json:`"Cheap"`
257-
* - :json:`"Tool B"`
258-
- :json:`120`
259-
- :json:`null`
260-
261-
CASE in WHERE Clause
262-
--------------------
263-
264-
Use CASE in filtering conditions:
265-
266-
.. code-block:: sql
267-
268-
SELECT name, category, price
269-
FROM products
270-
WHERE CASE
271-
WHEN category = 'Electronics' THEN price > 100
272-
ELSE price > 80
273-
END
274-
275-
.. list-table::
276-
:header-rows: 1
277-
278-
* - :sql:`name`
279-
- :sql:`category`
280-
- :sql:`price`
281-
* - :json:`"Widget B"`
282-
- :json:`"Electronics"`
283-
- :json:`150`
284-
* - :json:`"Gadget X"`
285-
- :json:`"Electronics"`
286-
- :json:`200`
287-
* - :json:`"Tool B"`
288-
- :json:`"Hardware"`
289-
- :json:`120`
290-
291-
CASE in ORDER BY
292-
----------------
293-
294-
Custom sorting logic:
295-
296-
.. code-block:: sql
297-
298-
SELECT name, stock
299-
FROM products
300-
ORDER BY
301-
CASE
302-
WHEN stock = 0 THEN 1
303-
WHEN stock < 10 THEN 2
304-
ELSE 3
305-
END,
306-
name
307-
308-
.. list-table::
309-
:header-rows: 1
310-
311-
* - :sql:`name`
312-
- :sql:`stock`
313-
* - :json:`"Gadget X"`
314-
- :json:`0`
315-
* - :json:`"Widget B"`
316-
- :json:`5`
317-
* - :json:`"Tool B"`
318-
- :json:`15`
319-
* - :json:`"Widget A"`
320-
- :json:`50`
321-
* - :json:`"Tool A"`
322-
- :json:`100`
323-
324-
This sorts out-of-stock items first, then low-stock items, then others, with secondary alphabetical sorting.
325-
326224
Nested CASE
327225
-----------
328226

yaml-tests/src/test/resources/documentation-queries/case-documentation-queries.yamsql

Lines changed: 10 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
---
22
options:
3-
supported_version: 4.3.2.0
3+
supported_version: 4.7.2.0
44
---
55
schema_template:
66
create table products(id bigint, name string, category string, price bigint, stock integer, primary key(id))
77
create index name_idx as select name from products order by name
8+
create index price_idx as select price from products order by price
9+
create index name_price_idx as select name, price from products order by name
810
---
911
setup:
1012
steps:
@@ -31,7 +33,7 @@ test_block:
3133
END AS stock_status
3234
FROM products
3335
ORDER BY name
34-
- supported_version: 4.3.2.0
36+
- supported_version: 4.7.2.0
3537
- result: [{name: "Gadget X", stock: 0, stock_status: "Out of Stock"},
3638
{name: "Tool A", stock: 100, stock_status: "Well Stocked"},
3739
{name: "Tool B", stock: 15, stock_status: "In Stock"},
@@ -42,70 +44,21 @@ test_block:
4244
-
4345
- query: SELECT name,
4446
category,
45-
CASE category
46-
WHEN 'Electronics' THEN 'E'
47-
WHEN 'Hardware' THEN 'H'
48-
WHEN 'Media' THEN 'M'
47+
CASE
48+
WHEN category = 'Electronics' THEN 'E'
49+
WHEN category = 'Hardware' THEN 'H'
50+
WHEN category = 'Media' THEN 'M'
4951
ELSE 'Other'
5052
END AS category_code
5153
FROM products
5254
ORDER BY name
53-
- supported_version: 4.3.2.0
55+
- supported_version: 4.7.2.0
5456
- result: [{name: "Gadget X", category: "Electronics", category_code: "E"},
5557
{name: "Tool A", category: "Hardware", category_code: "H"},
5658
{name: "Tool B", category: "Hardware", category_code: "H"},
5759
{name: "Widget A", category: "Electronics", category_code: "E"},
5860
{name: "Widget B", category: "Electronics", category_code: "E"}]
5961

60-
# CASE without ELSE (returns NULL)
61-
-
62-
- query: SELECT name,
63-
price,
64-
CASE
65-
WHEN price > 150 THEN 'Expensive'
66-
WHEN price < 100 THEN 'Cheap'
67-
END AS price_category
68-
FROM products
69-
ORDER BY name
70-
- supported_version: 4.3.2.0
71-
- result: [{name: "Gadget X", price: 200, price_category: "Expensive"},
72-
{name: "Tool A", price: 80, price_category: "Cheap"},
73-
{name: "Tool B", price: 120, price_category: null},
74-
{name: "Widget A", price: 100, price_category: null},
75-
{name: "Widget B", price: 150, price_category: null}]
76-
77-
# CASE in WHERE clause
78-
-
79-
- query: SELECT name, category, price
80-
FROM products
81-
WHERE CASE
82-
WHEN category = 'Electronics' THEN price > 100
83-
ELSE price > 80
84-
END
85-
ORDER BY name
86-
- supported_version: 4.3.2.0
87-
- result: [{name: "Gadget X", category: "Electronics", price: 200},
88-
{name: "Tool B", category: "Hardware", price: 120},
89-
{name: "Widget B", category: "Electronics", price: 150}]
90-
91-
# CASE in ORDER BY
92-
-
93-
- query: SELECT name, stock
94-
FROM products
95-
ORDER BY
96-
CASE
97-
WHEN stock = 0 THEN 1
98-
WHEN stock < 10 THEN 2
99-
ELSE 3
100-
END,
101-
name
102-
- supported_version: 4.3.2.0
103-
- result: [{name: "Gadget X", stock: 0},
104-
{name: "Widget B", stock: 5},
105-
{name: "Tool A", stock: 100},
106-
{name: "Tool B", stock: 15},
107-
{name: "Widget A", stock: 50}]
108-
10962
# Nested CASE
11063
-
11164
- query: SELECT name,
@@ -121,7 +74,7 @@ test_block:
12174
END AS product_tier
12275
FROM products
12376
ORDER BY name
124-
- supported_version: 4.3.2.0
77+
- supported_version: 4.7.2.0
12578
- result: [{name: "Gadget X", price: 200, stock: 0, product_tier: "Unavailable"},
12679
{name: "Tool A", price: 80, stock: 100, product_tier: "Budget"},
12780
{name: "Tool B", price: 120, stock: 15, product_tier: "Standard"},

0 commit comments

Comments
 (0)