Skip to content

Commit 1550c84

Browse files
committed
include some BinaryOperator from sqlparser
Signed-off-by: Ruihang Xia <waynestxia@gmail.com>
1 parent 19dd46d commit 1550c84

File tree

6 files changed

+128
-11
lines changed

6 files changed

+128
-11
lines changed

datafusion/expr-common/src/operator.rs

Lines changed: 69 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,28 @@ pub enum Operator {
8686
AtArrow,
8787
/// Arrow at, like `<@`
8888
ArrowAt,
89+
/// Arrow, like `->`
90+
Arrow,
91+
/// Long arrow, like `->>`
92+
LongArrow,
93+
/// Hash arrow, like `#>`
94+
HashArrow,
95+
/// Hash long arrow, like `#>>`
96+
HashLongArrow,
97+
/// At at, like `@@`
98+
AtAt,
99+
/// Integer division operator, like `DIV` from MySQL or `//` from DuckDB
100+
IntegerDivide,
101+
/// Hash Minis, like `#-`
102+
HashMinus,
103+
/// At question, like `@?`
104+
AtQuestion,
105+
/// Question, like `?`
106+
Question,
107+
/// Question and, like `?&`
108+
QuestionAnd,
109+
/// Question pipe, like `?|`
110+
QuestionPipe,
89111
}
90112

91113
impl Operator {
@@ -123,7 +145,18 @@ impl Operator {
123145
| Operator::BitwiseShiftLeft
124146
| Operator::StringConcat
125147
| Operator::AtArrow
126-
| Operator::ArrowAt => None,
148+
| Operator::ArrowAt
149+
| Operator::Arrow
150+
| Operator::LongArrow
151+
| Operator::HashArrow
152+
| Operator::HashLongArrow
153+
| Operator::AtAt
154+
| Operator::IntegerDivide
155+
| Operator::HashMinus
156+
| Operator::AtQuestion
157+
| Operator::Question
158+
| Operator::QuestionAnd
159+
| Operator::QuestionPipe => None,
127160
}
128161
}
129162

@@ -216,7 +249,18 @@ impl Operator {
216249
| Operator::BitwiseXor
217250
| Operator::BitwiseShiftRight
218251
| Operator::BitwiseShiftLeft
219-
| Operator::StringConcat => None,
252+
| Operator::StringConcat
253+
| Operator::Arrow
254+
| Operator::LongArrow
255+
| Operator::HashArrow
256+
| Operator::HashLongArrow
257+
| Operator::AtAt
258+
| Operator::IntegerDivide
259+
| Operator::HashMinus
260+
| Operator::AtQuestion
261+
| Operator::Question
262+
| Operator::QuestionAnd
263+
| Operator::QuestionPipe => None,
220264
}
221265
}
222266

@@ -245,7 +289,18 @@ impl Operator {
245289
| Operator::BitwiseXor
246290
| Operator::StringConcat
247291
| Operator::AtArrow
248-
| Operator::ArrowAt => 30,
292+
| Operator::ArrowAt
293+
| Operator::Arrow
294+
| Operator::LongArrow
295+
| Operator::HashArrow
296+
| Operator::HashLongArrow
297+
| Operator::AtAt
298+
| Operator::IntegerDivide
299+
| Operator::HashMinus
300+
| Operator::AtQuestion
301+
| Operator::Question
302+
| Operator::QuestionAnd
303+
| Operator::QuestionPipe => 30,
249304
Operator::Plus | Operator::Minus => 40,
250305
Operator::Multiply | Operator::Divide | Operator::Modulo => 45,
251306
}
@@ -286,6 +341,17 @@ impl fmt::Display for Operator {
286341
Operator::StringConcat => "||",
287342
Operator::AtArrow => "@>",
288343
Operator::ArrowAt => "<@",
344+
Operator::Arrow => "->",
345+
Operator::LongArrow => "->>",
346+
Operator::HashArrow => "#>",
347+
Operator::HashLongArrow => "#>>",
348+
Operator::AtAt => "@@",
349+
Operator::IntegerDivide => "DIV",
350+
Operator::HashMinus => "#-",
351+
Operator::AtQuestion => "@?",
352+
Operator::Question => "?",
353+
Operator::QuestionAnd => "?&",
354+
Operator::QuestionPipe => "?|",
289355
};
290356
write!(f, "{display}")
291357
}

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -181,17 +181,17 @@ impl<'a> BinaryTypeCoercer<'a> {
181181
)
182182
})
183183
}
184-
AtArrow | ArrowAt => {
185-
// ArrowAt and AtArrow check for whether one array is contained in another.
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.
186187
// The result type is boolean. Signature::comparison defines this signature.
187-
// Operation has nothing to do with comparison
188188
array_coercion(self.lhs, self.rhs).map(Signature::comparison).ok_or_else(|| {
189189
plan_datafusion_err!(
190-
"Cannot infer common array type for arrow operation {} {} {}", self.lhs, self.op, self.rhs
190+
"Cannot infer common array type for operation {} {} {}", self.lhs, self.op, self.rhs
191191
)
192192
})
193193
}
194-
Plus | Minus | Multiply | Divide | Modulo => {
194+
Plus | Minus | Multiply | Divide | Modulo => {
195195
let get_result = |lhs, rhs| {
196196
use arrow::compute::kernels::numeric::*;
197197
let l = new_empty_array(lhs);

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -793,8 +793,10 @@ impl BinaryExpr {
793793
BitwiseShiftRight => bitwise_shift_right_dyn(left, right),
794794
BitwiseShiftLeft => bitwise_shift_left_dyn(left, right),
795795
StringConcat => concat_elements(left, right),
796-
AtArrow | ArrowAt => {
797-
unreachable!("ArrowAt and AtArrow should be rewritten to function")
796+
AtArrow | ArrowAt | Arrow | LongArrow | HashArrow | HashLongArrow | AtAt
797+
| HashMinus | AtQuestion | Question | QuestionAnd | QuestionPipe
798+
| IntegerDivide => {
799+
unreachable!("These operators should be rewritten to functions")
798800
}
799801
}
800802
}

datafusion/sql/src/expr/binary_op.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,29 @@ impl<S: ContextProvider> SqlToRel<'_, S> {
4646
BinaryOperator::PGNotILikeMatch => Ok(Operator::NotILikeMatch),
4747
BinaryOperator::BitwiseAnd => Ok(Operator::BitwiseAnd),
4848
BinaryOperator::BitwiseOr => Ok(Operator::BitwiseOr),
49+
BinaryOperator::Xor => Ok(Operator::BitwiseXor),
4950
BinaryOperator::BitwiseXor => Ok(Operator::BitwiseXor),
5051
BinaryOperator::PGBitwiseXor => Ok(Operator::BitwiseXor),
5152
BinaryOperator::PGBitwiseShiftRight => Ok(Operator::BitwiseShiftRight),
5253
BinaryOperator::PGBitwiseShiftLeft => Ok(Operator::BitwiseShiftLeft),
5354
BinaryOperator::StringConcat => Ok(Operator::StringConcat),
5455
BinaryOperator::ArrowAt => Ok(Operator::ArrowAt),
5556
BinaryOperator::AtArrow => Ok(Operator::AtArrow),
57+
BinaryOperator::Arrow => Ok(Operator::Arrow),
58+
BinaryOperator::LongArrow => Ok(Operator::LongArrow),
59+
BinaryOperator::HashArrow => Ok(Operator::HashArrow),
60+
BinaryOperator::HashLongArrow => Ok(Operator::HashLongArrow),
61+
BinaryOperator::AtAt => Ok(Operator::AtAt),
5662
BinaryOperator::Spaceship => Ok(Operator::IsNotDistinctFrom),
57-
_ => not_impl_err!("Unsupported SQL binary operator {op:?}"),
63+
BinaryOperator::DuckIntegerDivide | BinaryOperator::MyIntegerDivide => {
64+
Ok(Operator::IntegerDivide)
65+
}
66+
BinaryOperator::HashMinus => Ok(Operator::HashMinus),
67+
BinaryOperator::AtQuestion => Ok(Operator::AtQuestion),
68+
BinaryOperator::Question => Ok(Operator::Question),
69+
BinaryOperator::QuestionAnd => Ok(Operator::QuestionAnd),
70+
BinaryOperator::QuestionPipe => Ok(Operator::QuestionPipe),
71+
_ => not_impl_err!("Unsupported binary operator: {:?}", op),
5872
}
5973
}
6074
}

datafusion/sql/src/unparser/expr.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -914,6 +914,19 @@ impl Unparser<'_> {
914914
BinaryOperator::StringConcat => Ok(Operator::StringConcat),
915915
BinaryOperator::AtArrow => Ok(Operator::AtArrow),
916916
BinaryOperator::ArrowAt => Ok(Operator::ArrowAt),
917+
BinaryOperator::Arrow => Ok(Operator::Arrow),
918+
BinaryOperator::LongArrow => Ok(Operator::LongArrow),
919+
BinaryOperator::HashArrow => Ok(Operator::HashArrow),
920+
BinaryOperator::HashLongArrow => Ok(Operator::HashLongArrow),
921+
BinaryOperator::AtAt => Ok(Operator::AtAt),
922+
BinaryOperator::DuckIntegerDivide | BinaryOperator::MyIntegerDivide => {
923+
Ok(Operator::IntegerDivide)
924+
}
925+
BinaryOperator::HashMinus => Ok(Operator::HashMinus),
926+
BinaryOperator::AtQuestion => Ok(Operator::AtQuestion),
927+
BinaryOperator::Question => Ok(Operator::Question),
928+
BinaryOperator::QuestionAnd => Ok(Operator::QuestionAnd),
929+
BinaryOperator::QuestionPipe => Ok(Operator::QuestionPipe),
917930
_ => not_impl_err!("unsupported operation: {op:?}"),
918931
}
919932
}
@@ -951,6 +964,17 @@ impl Unparser<'_> {
951964
Operator::StringConcat => Ok(BinaryOperator::StringConcat),
952965
Operator::AtArrow => Ok(BinaryOperator::AtArrow),
953966
Operator::ArrowAt => Ok(BinaryOperator::ArrowAt),
967+
Operator::Arrow => Ok(BinaryOperator::Arrow),
968+
Operator::LongArrow => Ok(BinaryOperator::LongArrow),
969+
Operator::HashArrow => Ok(BinaryOperator::HashArrow),
970+
Operator::HashLongArrow => Ok(BinaryOperator::HashLongArrow),
971+
Operator::AtAt => Ok(BinaryOperator::AtAt),
972+
Operator::IntegerDivide => Ok(BinaryOperator::DuckIntegerDivide),
973+
Operator::HashMinus => Ok(BinaryOperator::HashMinus),
974+
Operator::AtQuestion => Ok(BinaryOperator::AtQuestion),
975+
Operator::Question => Ok(BinaryOperator::Question),
976+
Operator::QuestionAnd => Ok(BinaryOperator::QuestionAnd),
977+
Operator::QuestionPipe => Ok(BinaryOperator::QuestionPipe),
954978
}
955979
}
956980

datafusion/substrait/src/logical_plan/producer.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1127,6 +1127,17 @@ pub fn operator_to_name(op: Operator) -> &'static str {
11271127
Operator::StringConcat => "str_concat",
11281128
Operator::AtArrow => "at_arrow",
11291129
Operator::ArrowAt => "arrow_at",
1130+
Operator::Arrow => "arrow",
1131+
Operator::LongArrow => "long_arrow",
1132+
Operator::HashArrow => "hash_arrow",
1133+
Operator::HashLongArrow => "hash_long_arrow",
1134+
Operator::AtAt => "at_at",
1135+
Operator::IntegerDivide => "integer_divide",
1136+
Operator::HashMinus => "hash_minus",
1137+
Operator::AtQuestion => "at_question",
1138+
Operator::Question => "question",
1139+
Operator::QuestionAnd => "question_and",
1140+
Operator::QuestionPipe => "question_pipe",
11301141
Operator::BitwiseXor => "bitwise_xor",
11311142
Operator::BitwiseShiftRight => "bitwise_shift_right",
11321143
Operator::BitwiseShiftLeft => "bitwise_shift_left",

0 commit comments

Comments
 (0)