Skip to content

Commit 2fe7da8

Browse files
committed
slt for new operators
Signed-off-by: Ruihang Xia <waynestxia@gmail.com>
1 parent 1550c84 commit 2fe7da8

File tree

3 files changed

+74
-10
lines changed

3 files changed

+74
-10
lines changed

datafusion/expr-common/src/type_coercion/binary.rs

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ use arrow::datatypes::{
3030
};
3131
use datafusion_common::types::NativeType;
3232
use datafusion_common::{
33-
exec_err, internal_err, plan_datafusion_err, plan_err, Diagnostic, Result, Span,
34-
Spans,
33+
exec_err, internal_err, not_impl_err, plan_datafusion_err, plan_err, Diagnostic,
34+
Result, Span, Spans,
3535
};
3636
use itertools::Itertools;
3737

@@ -181,13 +181,20 @@ impl<'a> BinaryTypeCoercer<'a> {
181181
)
182182
})
183183
}
184-
AtArrow | ArrowAt | Arrow | LongArrow | HashArrow | HashLongArrow | AtAt | HashMinus |
185-
AtQuestion | Question | QuestionAnd | QuestionPipe |IntegerDivide=> {
186-
// These operators check for whether one array is contained in another or other JSON operations.
187-
// The result type is boolean. Signature::comparison defines this signature.
188-
array_coercion(self.lhs, self.rhs).map(Signature::comparison).ok_or_else(|| {
184+
AtArrow | ArrowAt => {
185+
// Array contains or search (similar to LIKE) operation
186+
array_coercion(self.lhs, self.rhs)
187+
.or_else(|| like_coercion(self.lhs, self.rhs)).map(Signature::comparison).ok_or_else(|| {
188+
plan_datafusion_err!(
189+
"Cannot infer common argument type for operation {} {} {}", self.lhs, self.op, self.rhs
190+
)
191+
})
192+
}
193+
AtAt => {
194+
// text search has similar signature to LIKE
195+
like_coercion(self.lhs, self.rhs).map(Signature::comparison).ok_or_else(|| {
189196
plan_datafusion_err!(
190-
"Cannot infer common array type for operation {} {} {}", self.lhs, self.op, self.rhs
197+
"Cannot infer common argument type for AtAt operation {} {} {}", self.lhs, self.op, self.rhs
191198
)
192199
})
193200
}
@@ -248,6 +255,10 @@ impl<'a> BinaryTypeCoercer<'a> {
248255
"Cannot coerce arithmetic expression {} {} {} to valid types", self.lhs, self.op, self.rhs
249256
)
250257
}
258+
},
259+
IntegerDivide | Arrow | LongArrow | HashArrow | HashLongArrow
260+
| HashMinus | AtQuestion | Question | QuestionAnd | QuestionPipe => {
261+
not_impl_err!("Operator {} is not yet supported", self.op)
251262
}
252263
};
253264
result.map_err(|err| {

datafusion/physical-expr/src/expressions/binary.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ use arrow::compute::{cast, ilike, like, nilike, nlike};
3333
use arrow::datatypes::*;
3434
use arrow::error::ArrowError;
3535
use datafusion_common::cast::as_boolean_array;
36-
use datafusion_common::{internal_err, Result, ScalarValue};
36+
use datafusion_common::{internal_err, not_impl_err, Result, ScalarValue};
3737
use datafusion_expr::binary::BinaryTypeCoercer;
3838
use datafusion_expr::interval_arithmetic::{apply_operator, Interval};
3939
use datafusion_expr::sort_properties::ExprProperties;
@@ -796,7 +796,10 @@ impl BinaryExpr {
796796
AtArrow | ArrowAt | Arrow | LongArrow | HashArrow | HashLongArrow | AtAt
797797
| HashMinus | AtQuestion | Question | QuestionAnd | QuestionPipe
798798
| IntegerDivide => {
799-
unreachable!("These operators should be rewritten to functions")
799+
not_impl_err!(
800+
"Binary operator '{:?}' is not supported in the physical expr",
801+
self.op
802+
)
800803
}
801804
}
802805
}

datafusion/sqllogictest/test_files/expr.slt

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1648,6 +1648,56 @@ true
16481648
true
16491649
true
16501650

1651+
#### Other binary operators
1652+
1653+
# ArrowAt for strings
1654+
query error
1655+
select 'foo' <@ 'bar'
1656+
1657+
# AtArrow for strings
1658+
query error
1659+
select 'foo' @> 'bar'
1660+
1661+
# AtAt for strings
1662+
query error
1663+
select 'foo' @@ 'bar'
1664+
1665+
# Arrow for arrays
1666+
query error
1667+
select make_array(1,2,3) -> 2
1668+
1669+
# LongArrow for arrays
1670+
query error
1671+
select make_array(1,2,3) ->> 2
1672+
1673+
# HashArrow for structs
1674+
query error
1675+
select struct(1,2,3) #> 0
1676+
1677+
# HashLongArrow for structs
1678+
query error
1679+
select struct(1,2,3) #>> 0
1680+
1681+
# HashMinus for structs
1682+
query error
1683+
select struct(1,2,3) #- 0
1684+
1685+
# AtQuestion for JSON/structs
1686+
query error
1687+
select struct(1,2,3) @? 'a.b.c'
1688+
1689+
# Question for JSON/structs
1690+
query error
1691+
select struct(1,2,3) ? 'a.b.c'
1692+
1693+
# QuestionPipe for JSON/structs
1694+
query error
1695+
select struct(1,2,3) ?| array['a','b','c']
1696+
1697+
# QuestionAnd for JSON/structs
1698+
query error
1699+
select struct(1,2,3) ?& array['a','b','c']
1700+
16511701
#### binary_mathematical_operator_with_null_lt
16521702

16531703
# 1. Integer and NULL

0 commit comments

Comments
 (0)