Apache DataFusion SQL Query Engine
test: add IN list slt coverage for temporal, Decimal128 and Interval types (#23875)
Andrew Lamb062cbcbc6b7c
diff --git a/datafusion/sqllogictest/test_files/in_list.slt b/datafusion/sqllogictest/test_files/in_list.sltindex 335266a4c3..dbdad2056f 100644--- a/datafusion/sqllogictest/test_files/in_list.slt+++ b/datafusion/sqllogictest/test_files/in_list.slt@@ -170,6 +170,22 @@ minus_one false false false false false false false falseone true false true false true false true falsezero false true false true false true false true+# Seventeen item IN list (shorter lists have specialized implementation)+query TBB+SELECT+ label,+ i8 IN (-128, -120, -100, -80, -60, -40, -20, -10, -5, -3, -2, 2, 3, 5, 20, 40, 11),+ u8 IN (2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 13, 14, 16, 20, 0, 11, 255)+FROM in_list_ints+ORDER BY label+----+eleven true true+max false true+min true true+minus_one false false+one false false+zero false true+# Cleanupstatement okDROP TABLE in_list_ints;@@ -329,6 +345,237 @@ Float64 match true true falseFloat64 no_match false NULL falseFloat64 nulls NULL NULL NULL+# Nine element Float16 IN list (shorter lists have specialized code)+query TB+SELECT+ label,+ f16 IN (arrow_cast(1.0, 'Float16'), arrow_cast(2.0, 'Float16'), arrow_cast(3.0, 'Float16'),+ arrow_cast(4.0, 'Float16'), arrow_cast(5.0, 'Float16'), arrow_cast(6.0, 'Float16'),+ arrow_cast(8.0, 'Float16'), arrow_cast(9.0, 'Float16'), arrow_cast(11.0, 'Float16'))+FROM in_list_floats+ORDER BY label+----+match true+no_match false+nulls NULL+# Cleanupstatement okDROP TABLE in_list_floats++####+## Temporal IN List Specializations+####++statement ok+CREATE TABLE in_list_temporal AS+SELECT+ label,+ arrow_cast(value, 'Date32') AS d32,+ arrow_cast(value, 'Date64') AS d64,+ arrow_cast(arrow_cast(value, 'Int32'), 'Time32(Second)') AS t32s,+ arrow_cast(value, 'Time64(Nanosecond)') AS t64ns,+ arrow_cast(value, 'Timestamp(Nanosecond, None)') AS ts_ns,+ arrow_cast(value, 'Timestamp(Second, Some("UTC"))') AS ts_s_utc,+ arrow_cast(value, 'Duration(Second)') AS dur_s+FROM (VALUES+ ('match', 11),+ ('no_match', 7),+ ('nulls', NULL)+) AS t(label, value);++# Basic Temporal IN Lists+query TBBBBBBB+SELECT+ label,+ d32 IN (arrow_cast(3, 'Date32'), arrow_cast(4, 'Date32'), arrow_cast(5, 'Date32'), arrow_cast(11, 'Date32')),+ d64 IN (arrow_cast(3, 'Date64'), arrow_cast(4, 'Date64'), arrow_cast(5, 'Date64'), arrow_cast(11, 'Date64')),+ t32s IN (arrow_cast(arrow_cast(3, 'Int32'), 'Time32(Second)'), arrow_cast(arrow_cast(4, 'Int32'), 'Time32(Second)'), arrow_cast(arrow_cast(5, 'Int32'), 'Time32(Second)'), arrow_cast(arrow_cast(11, 'Int32'), 'Time32(Second)')),+ t64ns IN (arrow_cast(3, 'Time64(Nanosecond)'), arrow_cast(4, 'Time64(Nanosecond)'), arrow_cast(5, 'Time64(Nanosecond)'), arrow_cast(11, 'Time64(Nanosecond)')),+ ts_ns IN (arrow_cast(3, 'Timestamp(Nanosecond, None)'), arrow_cast(4, 'Timestamp(Nanosecond, None)'), arrow_cast(5, 'Timestamp(Nanosecond, None)'), arrow_cast(11, 'Timestamp(Nanosecond, None)')),+ ts_s_utc IN (arrow_cast(3, 'Timestamp(Second, Some("UTC"))'), arrow_cast(4, 'Timestamp(Second, Some("UTC"))'), arrow_cast(5, 'Timestamp(Second, Some("UTC"))'), arrow_cast(11, 'Timestamp(Second, Some("UTC"))')),+ dur_s IN (arrow_cast(3, 'Duration(Second)'), arrow_cast(4, 'Duration(Second)'), arrow_cast(5, 'Duration(Second)'), arrow_cast(11, 'Duration(Second)'))+FROM in_list_temporal+ORDER BY label+----+match true true true true true true true+no_match false false false false false false false+nulls NULL NULL NULL NULL NULL NULL NULL++# The same lists with NOT IN.+query TBBBBBBB+SELECT+ label,+ d32 NOT IN (arrow_cast(3, 'Date32'), arrow_cast(4, 'Date32'), arrow_cast(5, 'Date32'), arrow_cast(11, 'Date32')),+ d64 NOT IN (arrow_cast(3, 'Date64'), arrow_cast(4, 'Date64'), arrow_cast(5, 'Date64'), arrow_cast(11, 'Date64')),+ t32s NOT IN (arrow_cast(arrow_cast(3, 'Int32'), 'Time32(Second)'), arrow_cast(arrow_cast(4, 'Int32'), 'Time32(Second)'), arrow_cast(arrow_cast(5, 'Int32'), 'Time32(Second)'), arrow_cast(arrow_cast(11, 'Int32'), 'Time32(Second)')),+ t64ns NOT IN (arrow_cast(3, 'Time64(Nanosecond)'), arrow_cast(4, 'Time64(Nanosecond)'), arrow_cast(5, 'Time64(Nanosecond)'), arrow_cast(11, 'Time64(Nanosecond)')),+ ts_ns NOT IN (arrow_cast(3, 'Timestamp(Nanosecond, None)'), arrow_cast(4, 'Timestamp(Nanosecond, None)'), arrow_cast(5, 'Timestamp(Nanosecond, None)'), arrow_cast(11, 'Timestamp(Nanosecond, None)')),+ ts_s_utc NOT IN (arrow_cast(3, 'Timestamp(Second, Some("UTC"))'), arrow_cast(4, 'Timestamp(Second, Some("UTC"))'), arrow_cast(5, 'Timestamp(Second, Some("UTC"))'), arrow_cast(11, 'Timestamp(Second, Some("UTC"))')),+ dur_s NOT IN (arrow_cast(3, 'Duration(Second)'), arrow_cast(4, 'Duration(Second)'), arrow_cast(5, 'Duration(Second)'), arrow_cast(11, 'Duration(Second)'))+FROM in_list_temporal+ORDER BY label+----+match false false false false false false false+no_match true true true true true true true+nulls NULL NULL NULL NULL NULL NULL NULL++# Null IN list values return true for matches and NULL for non-matches.+query TBBBBBBB+SELECT+ label,+ d32 IN (NULL, arrow_cast(3, 'Date32'), arrow_cast(4, 'Date32'), arrow_cast(11, 'Date32')),+ d64 IN (NULL, arrow_cast(3, 'Date64'), arrow_cast(4, 'Date64'), arrow_cast(11, 'Date64')),+ t32s IN (NULL, arrow_cast(arrow_cast(3, 'Int32'), 'Time32(Second)'), arrow_cast(arrow_cast(4, 'Int32'), 'Time32(Second)'), arrow_cast(arrow_cast(11, 'Int32'), 'Time32(Second)')),+ t64ns IN (NULL, arrow_cast(3, 'Time64(Nanosecond)'), arrow_cast(4, 'Time64(Nanosecond)'), arrow_cast(11, 'Time64(Nanosecond)')),+ ts_ns IN (NULL, arrow_cast(3, 'Timestamp(Nanosecond, None)'), arrow_cast(4, 'Timestamp(Nanosecond, None)'), arrow_cast(11, 'Timestamp(Nanosecond, None)')),+ ts_s_utc IN (NULL, arrow_cast(3, 'Timestamp(Second, Some("UTC"))'), arrow_cast(4, 'Timestamp(Second, Some("UTC"))'), arrow_cast(11, 'Timestamp(Second, Some("UTC"))')),+ dur_s IN (NULL, arrow_cast(3, 'Duration(Second)'), arrow_cast(4, 'Duration(Second)'), arrow_cast(11, 'Duration(Second)'))+FROM in_list_temporal+ORDER BY label+----+match true true true true true true true+no_match NULL NULL NULL NULL NULL NULL NULL+nulls NULL NULL NULL NULL NULL NULL NULL++# A NULL in the list turns off some specializations+query TBBBBBBB+SELECT+ label,+ d32 IN (NULL, arrow_cast(11, 'Date32')),+ d64 IN (NULL, arrow_cast(11, 'Date64')),+ t32s IN (NULL, arrow_cast(arrow_cast(11, 'Int32'), 'Time32(Second)')),+ t64ns IN (NULL, arrow_cast(11, 'Time64(Nanosecond)')),+ ts_ns IN (NULL, arrow_cast(11, 'Timestamp(Nanosecond, None)')),+ ts_s_utc IN (NULL, arrow_cast(11, 'Timestamp(Second, Some("UTC"))')),+ dur_s IN (NULL, arrow_cast(11, 'Duration(Second)'))+FROM in_list_temporal+ORDER BY label+----+match true true true true true true true+no_match NULL NULL NULL NULL NULL NULL NULL+nulls NULL NULL NULL NULL NULL NULL NULL++# Cleanup+statement ok+DROP TABLE in_list_temporal++####+## Decimal128 IN List Specializations+####++statement ok+CREATE TABLE in_list_decimal AS+SELECT * FROM (VALUES+ ('match', arrow_cast(11, 'Decimal128(10, 2)')),+ ('no_match', arrow_cast(7, 'Decimal128(10, 2)')),+ ('nulls', NULL)+) AS t(label, d128);++query T+SELECT arrow_typeof(d128) FROM in_list_decimal LIMIT 1+----+Decimal128(10, 2)++# Four non-null values and five non-null values (test different specializations)+query TBB+SELECT+ label,+ d128 IN (arrow_cast(3, 'Decimal128(10, 2)'), arrow_cast(4, 'Decimal128(10, 2)'), arrow_cast(5, 'Decimal128(10, 2)'), arrow_cast(11, 'Decimal128(10, 2)')),+ d128 IN (arrow_cast(3, 'Decimal128(10, 2)'), arrow_cast(4, 'Decimal128(10, 2)'), arrow_cast(5, 'Decimal128(10, 2)'), arrow_cast(11, 'Decimal128(10, 2)'), arrow_cast(13, 'Decimal128(10, 2)'))+FROM in_list_decimal+ORDER BY label+----+match true true+no_match false false+nulls NULL NULL++# The same lists with NOT IN.+query TBB+SELECT+ label,+ d128 NOT IN (arrow_cast(3, 'Decimal128(10, 2)'), arrow_cast(4, 'Decimal128(10, 2)'), arrow_cast(5, 'Decimal128(10, 2)'), arrow_cast(11, 'Decimal128(10, 2)')),+ d128 NOT IN (arrow_cast(3, 'Decimal128(10, 2)'), arrow_cast(4, 'Decimal128(10, 2)'), arrow_cast(5, 'Decimal128(10, 2)'), arrow_cast(11, 'Decimal128(10, 2)'), arrow_cast(13, 'Decimal128(10, 2)'))+FROM in_list_decimal+ORDER BY label+----+match false false+no_match true true+nulls NULL NULL++# Null IN list values, including short lists with a single non-null value.+query TBB+SELECT+ label,+ d128 IN (NULL, arrow_cast(3, 'Decimal128(10, 2)'), arrow_cast(4, 'Decimal128(10, 2)'), arrow_cast(11, 'Decimal128(10, 2)')),+ d128 IN (NULL, arrow_cast(11, 'Decimal128(10, 2)'))+FROM in_list_decimal+ORDER BY label+----+match true true+no_match NULL NULL+nulls NULL NULL++# Cleanup+statement ok+DROP TABLE in_list_decimal++####+## Interval IN List Specializations+####++statement ok+CREATE TABLE in_list_interval AS+SELECT * FROM (VALUES+ ('match', INTERVAL '11 months'),+ ('no_match', INTERVAL '7 months'),+ ('nulls', NULL)+) AS t(label, imdn);++query T+SELECT arrow_typeof(imdn) FROM in_list_interval LIMIT 1+----+Interval(MonthDayNano)++# Four non-null values and five non-null values (test different specializations)+query TBB+SELECT+ label,+ imdn IN (INTERVAL '3 months', INTERVAL '4 months', INTERVAL '5 months', INTERVAL '11 months'),+ imdn IN (INTERVAL '3 months', INTERVAL '4 months', INTERVAL '5 months', INTERVAL '11 months', INTERVAL '13 months')+FROM in_list_interval+ORDER BY label+----+match true true+no_match false false+nulls NULL NULL++# The same lists with NOT IN.+query TBB+SELECT+ label,+ imdn NOT IN (INTERVAL '3 months', INTERVAL '4 months', INTERVAL '5 months', INTERVAL '11 months'),+ imdn NOT IN (INTERVAL '3 months', INTERVAL '4 months', INTERVAL '5 months', INTERVAL '11 months', INTERVAL '13 months')+FROM in_list_interval+ORDER BY label+----+match false false+no_match true true+nulls NULL NULL++# Null IN list values, including short lists with a single non-null value.+query TBB+SELECT+ label,+ imdn IN (NULL, INTERVAL '3 months', INTERVAL '4 months', INTERVAL '11 months'),+ imdn IN (NULL, INTERVAL '11 months')+FROM in_list_interval+ORDER BY label+----+match true true+no_match NULL NULL+nulls NULL NULL++# Cleanup+statement ok+DROP TABLE in_list_interval