Skip to content

Commit a49bcfe

Browse files
committed
add p0
1 parent 9c40dcb commit a49bcfe

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

regression-test/suites/nereids_p0/sql_functions/test_default.groovy

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,53 @@ suite("test_default") {
319319
exception "DEFAULT function requires a column reference"
320320
}
321321

322+
def baseDefault = sql """
323+
SELECT DEFAULT(c_bool)
324+
FROM ${tableName}
325+
LIMIT 1
326+
"""
327+
def tableAliasDefault = sql """
328+
SELECT DEFAULT(t.c_bool)
329+
FROM ${tableName} t
330+
LIMIT 1
331+
"""
332+
def aliasDefault = sql """
333+
SELECT DEFAULT(x)
334+
FROM (
335+
SELECT c_bool AS x
336+
FROM ${tableName}
337+
) t
338+
LIMIT 1
339+
"""
340+
def nestedAliasDefault = sql """
341+
SELECT DEFAULT(x)
342+
FROM (
343+
SELECT x
344+
FROM (
345+
SELECT c_bool AS x
346+
FROM ${tableName}
347+
) inner_view
348+
) outer_view
349+
LIMIT 1
350+
"""
351+
def cteAliasDefault = sql """
352+
WITH cte AS (
353+
SELECT c_bool AS x
354+
FROM ${tableName}
355+
)
356+
SELECT DEFAULT(x)
357+
FROM cte
358+
LIMIT 1
359+
"""
360+
assertTrue(aliasDefault == baseDefault,
361+
"DEFAULT() should return the same value for aliased columns in subqueries")
362+
assertTrue(tableAliasDefault == baseDefault,
363+
"DEFAULT() should return the same value when referenced through a table alias")
364+
assertTrue(nestedAliasDefault == baseDefault,
365+
"DEFAULT() should return the same value for nested aliased subqueries")
366+
assertTrue(cteAliasDefault == baseDefault,
367+
"DEFAULT() should return the same value when alias comes from a CTE")
368+
322369
sql "SET enable_fold_constant_by_be = false;"
323370
test {
324371
sql "SELECT DEFAULT(c_bool, c_int) FROM ${tableName} LIMIT 1"

0 commit comments

Comments
 (0)