nuno-faria commented on code in PR #23875:
URL: https://github.com/apache/datafusion/pull/23875#discussion_r3677902925
##########
datafusion/sqllogictest/test_files/in_list.slt:
##########
@@ -329,6 +345,183 @@ Float64 match true true false
Float64 no_match false NULL false
Float64 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
+
# Cleanup
statement ok
DROP TABLE in_list_floats
+
+####
+## Temporal IN List Specializations
+####
+
+statement ok
+CREATE TABLE in_list_temporal AS
+SELECT
+ label,
+ arrow_cast(arrow_cast(value, 'Int32'), 'Date32') AS d32,
+ arrow_cast(arrow_cast(value, 'Int64'), 'Date64') AS d64,
+ arrow_cast(arrow_cast(value, 'Int32'), 'Time32(Second)') AS t32s,
+ arrow_cast(arrow_cast(value, 'Int64'), 'Time64(Nanosecond)') AS
t64ns,
+ arrow_cast(arrow_cast(value, 'Int64'), 'Timestamp(Nanosecond, None)') AS
ts_ns,
+ arrow_cast(arrow_cast(value, 'Int64'), 'Timestamp(Second, Some("UTC"))') AS
ts_s_utc,
+ arrow_cast(arrow_cast(value, 'Int64'), 'Duration(Second)') AS dur_s
Review Comment:
nit: The aliases are not aligned, if that was the idea 😄.
##########
datafusion/sqllogictest/test_files/in_list.slt:
##########
@@ -329,6 +345,183 @@ Float64 match true true false
Float64 no_match false NULL false
Float64 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
+
# Cleanup
statement ok
DROP TABLE in_list_floats
+
+####
+## Temporal IN List Specializations
+####
+
+statement ok
+CREATE TABLE in_list_temporal AS
+SELECT
+ label,
+ arrow_cast(arrow_cast(value, 'Int32'), 'Date32') AS d32,
+ arrow_cast(arrow_cast(value, 'Int64'), 'Date64') AS d64,
+ arrow_cast(arrow_cast(value, 'Int32'), 'Time32(Second)') AS t32s,
+ arrow_cast(arrow_cast(value, 'Int64'), 'Time64(Nanosecond)') AS
t64ns,
+ arrow_cast(arrow_cast(value, 'Int64'), 'Timestamp(Nanosecond, None)') AS
ts_ns,
+ arrow_cast(arrow_cast(value, 'Int64'), 'Timestamp(Second, Some("UTC"))') AS
ts_s_utc,
+ arrow_cast(arrow_cast(value, 'Int64'), '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(arrow_cast(3, 'Int32'), 'Date32'),
arrow_cast(arrow_cast(4, 'Int32'), 'Date32'), arrow_cast(arrow_cast(5,
'Int32'), 'Date32'), arrow_cast(arrow_cast(11, 'Int32'), 'Date32')),
+ d64 IN (arrow_cast(arrow_cast(3, 'Int64'), 'Date64'),
arrow_cast(arrow_cast(4, 'Int64'), 'Date64'), arrow_cast(arrow_cast(5,
'Int64'), 'Date64'), arrow_cast(arrow_cast(11, 'Int64'), '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(arrow_cast(3, 'Int64'), 'Time64(Nanosecond)'),
arrow_cast(arrow_cast(4, 'Int64'), 'Time64(Nanosecond)'),
arrow_cast(arrow_cast(5, 'Int64'), 'Time64(Nanosecond)'),
arrow_cast(arrow_cast(11, 'Int64'), 'Time64(Nanosecond)')),
+ ts_ns IN (arrow_cast(arrow_cast(3, 'Int64'), 'Timestamp(Nanosecond,
None)'), arrow_cast(arrow_cast(4, 'Int64'), 'Timestamp(Nanosecond, None)'),
arrow_cast(arrow_cast(5, 'Int64'), 'Timestamp(Nanosecond, None)'),
arrow_cast(arrow_cast(11, 'Int64'), 'Timestamp(Nanosecond, None)')),
+ ts_s_utc IN (arrow_cast(arrow_cast(3, 'Int64'), 'Timestamp(Second,
Some("UTC"))'), arrow_cast(arrow_cast(4, 'Int64'), 'Timestamp(Second,
Some("UTC"))'), arrow_cast(arrow_cast(5, 'Int64'), 'Timestamp(Second,
Some("UTC"))'), arrow_cast(arrow_cast(11, 'Int64'), 'Timestamp(Second,
Some("UTC"))')),
+ dur_s IN (arrow_cast(arrow_cast(3, 'Int64'), 'Duration(Second)'),
arrow_cast(arrow_cast(4, 'Int64'), 'Duration(Second)'),
arrow_cast(arrow_cast(5, 'Int64'), 'Duration(Second)'),
arrow_cast(arrow_cast(11, 'Int64'), 'Duration(Second)'))
Review Comment:
In this test and the others, I don't think the double `arrow_cast` is
needed, only for Time32:
```sql
> select arrow_cast(3, 'Date32');
+-------------------------------------+
| arrow_cast(Int64(3),Utf8("Date32")) |
+-------------------------------------+
| 1970-01-04 |
+-------------------------------------+
> select arrow_cast(3, 'Time32');
Execution error: Unsupported type 'Time32'. Must be a supported arrow type
name such as 'Int32' or 'Timestamp(ns)'. Error finding next token
```
##########
datafusion/sqllogictest/test_files/in_list.slt:
##########
@@ -329,6 +345,183 @@ Float64 match true true false
Float64 no_match false NULL false
Float64 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
+
# Cleanup
statement ok
DROP TABLE in_list_floats
+
+####
+## Temporal IN List Specializations
+####
+
+statement ok
+CREATE TABLE in_list_temporal AS
+SELECT
+ label,
+ arrow_cast(arrow_cast(value, 'Int32'), 'Date32') AS d32,
+ arrow_cast(arrow_cast(value, 'Int64'), 'Date64') AS d64,
+ arrow_cast(arrow_cast(value, 'Int32'), 'Time32(Second)') AS t32s,
+ arrow_cast(arrow_cast(value, 'Int64'), 'Time64(Nanosecond)') AS
t64ns,
+ arrow_cast(arrow_cast(value, 'Int64'), 'Timestamp(Nanosecond, None)') AS
ts_ns,
+ arrow_cast(arrow_cast(value, 'Int64'), 'Timestamp(Second, Some("UTC"))') AS
ts_s_utc,
+ arrow_cast(arrow_cast(value, 'Int64'), '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(arrow_cast(3, 'Int32'), 'Date32'),
arrow_cast(arrow_cast(4, 'Int32'), 'Date32'), arrow_cast(arrow_cast(5,
'Int32'), 'Date32'), arrow_cast(arrow_cast(11, 'Int32'), 'Date32')),
+ d64 IN (arrow_cast(arrow_cast(3, 'Int64'), 'Date64'),
arrow_cast(arrow_cast(4, 'Int64'), 'Date64'), arrow_cast(arrow_cast(5,
'Int64'), 'Date64'), arrow_cast(arrow_cast(11, 'Int64'), '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(arrow_cast(3, 'Int64'), 'Time64(Nanosecond)'),
arrow_cast(arrow_cast(4, 'Int64'), 'Time64(Nanosecond)'),
arrow_cast(arrow_cast(5, 'Int64'), 'Time64(Nanosecond)'),
arrow_cast(arrow_cast(11, 'Int64'), 'Time64(Nanosecond)')),
+ ts_ns IN (arrow_cast(arrow_cast(3, 'Int64'), 'Timestamp(Nanosecond,
None)'), arrow_cast(arrow_cast(4, 'Int64'), 'Timestamp(Nanosecond, None)'),
arrow_cast(arrow_cast(5, 'Int64'), 'Timestamp(Nanosecond, None)'),
arrow_cast(arrow_cast(11, 'Int64'), 'Timestamp(Nanosecond, None)')),
+ ts_s_utc IN (arrow_cast(arrow_cast(3, 'Int64'), 'Timestamp(Second,
Some("UTC"))'), arrow_cast(arrow_cast(4, 'Int64'), 'Timestamp(Second,
Some("UTC"))'), arrow_cast(arrow_cast(5, 'Int64'), 'Timestamp(Second,
Some("UTC"))'), arrow_cast(arrow_cast(11, 'Int64'), 'Timestamp(Second,
Some("UTC"))')),
+ dur_s IN (arrow_cast(arrow_cast(3, 'Int64'), 'Duration(Second)'),
arrow_cast(arrow_cast(4, 'Int64'), 'Duration(Second)'),
arrow_cast(arrow_cast(5, 'Int64'), 'Duration(Second)'),
arrow_cast(arrow_cast(11, 'Int64'), '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(arrow_cast(3, 'Int32'), 'Date32'),
arrow_cast(arrow_cast(4, 'Int32'), 'Date32'), arrow_cast(arrow_cast(5,
'Int32'), 'Date32'), arrow_cast(arrow_cast(11, 'Int32'), 'Date32')),
+ d64 NOT IN (arrow_cast(arrow_cast(3, 'Int64'), 'Date64'),
arrow_cast(arrow_cast(4, 'Int64'), 'Date64'), arrow_cast(arrow_cast(5,
'Int64'), 'Date64'), arrow_cast(arrow_cast(11, 'Int64'), '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(arrow_cast(3, 'Int64'), 'Time64(Nanosecond)'),
arrow_cast(arrow_cast(4, 'Int64'), 'Time64(Nanosecond)'),
arrow_cast(arrow_cast(5, 'Int64'), 'Time64(Nanosecond)'),
arrow_cast(arrow_cast(11, 'Int64'), 'Time64(Nanosecond)')),
+ ts_ns NOT IN (arrow_cast(arrow_cast(3, 'Int64'), 'Timestamp(Nanosecond,
None)'), arrow_cast(arrow_cast(4, 'Int64'), 'Timestamp(Nanosecond, None)'),
arrow_cast(arrow_cast(5, 'Int64'), 'Timestamp(Nanosecond, None)'),
arrow_cast(arrow_cast(11, 'Int64'), 'Timestamp(Nanosecond, None)')),
+ ts_s_utc NOT IN (arrow_cast(arrow_cast(3, 'Int64'), 'Timestamp(Second,
Some("UTC"))'), arrow_cast(arrow_cast(4, 'Int64'), 'Timestamp(Second,
Some("UTC"))'), arrow_cast(arrow_cast(5, 'Int64'), 'Timestamp(Second,
Some("UTC"))'), arrow_cast(arrow_cast(11, 'Int64'), 'Timestamp(Second,
Some("UTC"))')),
+ dur_s NOT IN (arrow_cast(arrow_cast(3, 'Int64'), 'Duration(Second)'),
arrow_cast(arrow_cast(4, 'Int64'), 'Duration(Second)'),
arrow_cast(arrow_cast(5, 'Int64'), 'Duration(Second)'),
arrow_cast(arrow_cast(11, 'Int64'), '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(arrow_cast(3, 'Int32'), 'Date32'),
arrow_cast(arrow_cast(4, 'Int32'), 'Date32'), arrow_cast(arrow_cast(11,
'Int32'), 'Date32')),
+ d64 IN (NULL, arrow_cast(arrow_cast(3, 'Int64'), 'Date64'),
arrow_cast(arrow_cast(4, 'Int64'), 'Date64'), arrow_cast(arrow_cast(11,
'Int64'), '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(arrow_cast(3, 'Int64'), 'Time64(Nanosecond)'),
arrow_cast(arrow_cast(4, 'Int64'), 'Time64(Nanosecond)'),
arrow_cast(arrow_cast(11, 'Int64'), 'Time64(Nanosecond)')),
+ ts_ns IN (NULL, arrow_cast(arrow_cast(3, 'Int64'), 'Timestamp(Nanosecond,
None)'), arrow_cast(arrow_cast(4, 'Int64'), 'Timestamp(Nanosecond, None)'),
arrow_cast(arrow_cast(11, 'Int64'), 'Timestamp(Nanosecond, None)')),
+ ts_s_utc IN (NULL, arrow_cast(arrow_cast(3, 'Int64'), 'Timestamp(Second,
Some("UTC"))'), arrow_cast(arrow_cast(4, 'Int64'), 'Timestamp(Second,
Some("UTC"))'), arrow_cast(arrow_cast(11, 'Int64'), 'Timestamp(Second,
Some("UTC"))')),
+ dur_s IN (NULL, arrow_cast(arrow_cast(3, 'Int64'), 'Duration(Second)'),
arrow_cast(arrow_cast(4, 'Int64'), 'Duration(Second)'),
arrow_cast(arrow_cast(11, 'Int64'), '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(arrow_cast(11, 'Int32'), 'Date32')),
+ d64 IN (NULL, arrow_cast(arrow_cast(11, 'Int64'), 'Date64')),
+ t32s IN (NULL, arrow_cast(arrow_cast(11, 'Int32'), 'Time32(Second)')),
+ t64ns IN (NULL, arrow_cast(arrow_cast(11, 'Int64'),
'Time64(Nanosecond)')),
+ ts_ns IN (NULL, arrow_cast(arrow_cast(11, 'Int64'),
'Timestamp(Nanosecond, None)')),
+ ts_s_utc IN (NULL, arrow_cast(arrow_cast(11, 'Int64'), 'Timestamp(Second,
Some("UTC"))')),
+ dur_s IN (NULL, arrow_cast(arrow_cast(11, 'Int64'), '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_wide AS
+SELECT * FROM (VALUES
+ ('match', arrow_cast(11, 'Decimal128(10, 2)'), INTERVAL '11 months'),
+ ('no_match', arrow_cast(7, 'Decimal128(10, 2)'), INTERVAL '7 months'),
+ ('nulls', NULL, NULL)
+) AS t(label, d128, imdn);
+
+query TT
+SELECT arrow_typeof(d128), arrow_typeof(imdn) FROM in_list_wide LIMIT 1
+----
+Decimal128(10, 2) Interval(MonthDayNano)
Review Comment:
Should `Decimal128` and `INTERVAL` maybe be split into different tests?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]