Skip to content

Commit

Permalink
add more ops
Browse files Browse the repository at this point in the history
Signed-off-by: jayzhan211 <jayzhan211@gmail.com>
  • Loading branch information
jayzhan211 committed Jun 24, 2024
1 parent abc3c6b commit a94687c
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 18 deletions.
29 changes: 18 additions & 11 deletions datafusion/physical-expr/src/expressions/binary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,23 +265,30 @@ impl PhysicalExpr for BinaryExpr {
let schema = batch.schema();
let input_schema = schema.as_ref();

if left_data_type.is_nested() {
if right_data_type != left_data_type {
return internal_err!("type mismatch");
}
if matches!(
self.op,
Operator::Eq
| Operator::NotEq
| Operator::Lt
| Operator::Gt
| Operator::LtEq
| Operator::GtEq
) {
return apply_cmp_for_nested(self.op, &lhs, &rhs);
}
}

match self.op {
Operator::Plus => return apply(&lhs, &rhs, add_wrapping),
Operator::Minus => return apply(&lhs, &rhs, sub_wrapping),
Operator::Multiply => return apply(&lhs, &rhs, mul_wrapping),
Operator::Divide => return apply(&lhs, &rhs, div),
Operator::Modulo => return apply(&lhs, &rhs, rem),
Operator::Eq => {
if left_data_type.is_nested() {
if right_data_type != left_data_type {
return internal_err!("type mismatch");
}
// apply cmp for nested
return apply_cmp_for_nested(self.op, &lhs, &rhs);
}

return apply_cmp(&lhs, &rhs, eq);
}
Operator::Eq => return apply_cmp(&lhs, &rhs, eq),
Operator::NotEq => return apply_cmp(&lhs, &rhs, neq),
Operator::Lt => return apply_cmp(&lhs, &rhs, lt),
Operator::Gt => return apply_cmp(&lhs, &rhs, gt),
Expand Down
40 changes: 33 additions & 7 deletions datafusion/sqllogictest/test_files/array_query.slt
Original file line number Diff line number Diff line change
Expand Up @@ -41,22 +41,48 @@ SELECT * FROM data;
# Filtering
###########

query ??I
query ??I rowsort
SELECT * FROM data WHERE column1 = [1,2,3];
----
[1, 2, 3] [4, 5] 1
[1, 2, 3] NULL 1
[1, 2, 3] [4, 5] 1

query ??I
SELECT * FROM data WHERE column1 = column2
SELECT * FROM data WHERE column1 != [1,2,3];
----
[2, 3] [2, 3] 1

query error DataFusion error: Arrow error: Invalid argument error: Invalid comparison operation: List\(Field \{ name: "item", data_type: Int64, nullable: true, dict_id: 0, dict_is_ordered: false, metadata: \{\} \}\) != List\(Field \{ name: "item", data_type: Int64, nullable: true, dict_id: 0, dict_is_ordered: false, metadata: \{\} \}\)
SELECT * FROM data WHERE column1 != [1,2,3];

query error DataFusion error: Arrow error: Invalid argument error: Invalid comparison operation: List\(Field \{ name: "item", data_type: Int64, nullable: true, dict_id: 0, dict_is_ordered: false, metadata: \{\} \}\) != List\(Field \{ name: "item", data_type: Int64, nullable: true, dict_id: 0, dict_is_ordered: false, metadata: \{\} \}\)
query ??I
SELECT * FROM data WHERE column1 != column2
----
[1, 2, 3] [4, 5] 1

query ??I rowsort
SELECT * FROM data WHERE column1 < [1,2,3,4];
----
[1, 2, 3] NULL 1
[1, 2, 3] [4, 5] 1

query ??I rowsort
SELECT * FROM data WHERE column1 <= [2, 3];
----
[1, 2, 3] NULL 1
[1, 2, 3] [4, 5] 1
[2, 3] [2, 3] 1

query ??I rowsort
SELECT * FROM data WHERE column1 > [1,2];
----
[1, 2, 3] NULL 1
[1, 2, 3] [4, 5] 1
[2, 3] [2, 3] 1

query ??I rowsort
SELECT * FROM data WHERE column1 >= [1, 2, 3];
----
[1, 2, 3] NULL 1
[1, 2, 3] [4, 5] 1
[2, 3] [2, 3] 1

###########
# Aggregates
Expand Down

0 comments on commit a94687c

Please sign in to comment.