datafusion_sql/expr/
binary_op.rs

1// Licensed to the Apache Software Foundation (ASF) under one
2// or more contributor license agreements.  See the NOTICE file
3// distributed with this work for additional information
4// regarding copyright ownership.  The ASF licenses this file
5// to you under the Apache License, Version 2.0 (the
6// "License"); you may not use this file except in compliance
7// with the License.  You may obtain a copy of the License at
8//
9//   http://www.apache.org/licenses/LICENSE-2.0
10//
11// Unless required by applicable law or agreed to in writing,
12// software distributed under the License is distributed on an
13// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14// KIND, either express or implied.  See the License for the
15// specific language governing permissions and limitations
16// under the License.
17
18use crate::planner::{ContextProvider, SqlToRel};
19use datafusion_common::{not_impl_err, Result};
20use datafusion_expr::Operator;
21use sqlparser::ast::BinaryOperator;
22
23impl<S: ContextProvider> SqlToRel<'_, S> {
24    pub(crate) fn parse_sql_binary_op(&self, op: BinaryOperator) -> Result<Operator> {
25        match op {
26            BinaryOperator::Gt => Ok(Operator::Gt),
27            BinaryOperator::GtEq => Ok(Operator::GtEq),
28            BinaryOperator::Lt => Ok(Operator::Lt),
29            BinaryOperator::LtEq => Ok(Operator::LtEq),
30            BinaryOperator::Eq => Ok(Operator::Eq),
31            BinaryOperator::NotEq => Ok(Operator::NotEq),
32            BinaryOperator::Plus => Ok(Operator::Plus),
33            BinaryOperator::Minus => Ok(Operator::Minus),
34            BinaryOperator::Multiply => Ok(Operator::Multiply),
35            BinaryOperator::Divide => Ok(Operator::Divide),
36            BinaryOperator::Modulo => Ok(Operator::Modulo),
37            BinaryOperator::And => Ok(Operator::And),
38            BinaryOperator::Or => Ok(Operator::Or),
39            BinaryOperator::PGRegexMatch => Ok(Operator::RegexMatch),
40            BinaryOperator::PGRegexIMatch => Ok(Operator::RegexIMatch),
41            BinaryOperator::PGRegexNotMatch => Ok(Operator::RegexNotMatch),
42            BinaryOperator::PGRegexNotIMatch => Ok(Operator::RegexNotIMatch),
43            BinaryOperator::PGLikeMatch => Ok(Operator::LikeMatch),
44            BinaryOperator::PGILikeMatch => Ok(Operator::ILikeMatch),
45            BinaryOperator::PGNotLikeMatch => Ok(Operator::NotLikeMatch),
46            BinaryOperator::PGNotILikeMatch => Ok(Operator::NotILikeMatch),
47            BinaryOperator::BitwiseAnd => Ok(Operator::BitwiseAnd),
48            BinaryOperator::BitwiseOr => Ok(Operator::BitwiseOr),
49            BinaryOperator::Xor => Ok(Operator::BitwiseXor),
50            BinaryOperator::BitwiseXor => Ok(Operator::BitwiseXor),
51            BinaryOperator::PGBitwiseXor => Ok(Operator::BitwiseXor),
52            BinaryOperator::PGBitwiseShiftRight => Ok(Operator::BitwiseShiftRight),
53            BinaryOperator::PGBitwiseShiftLeft => Ok(Operator::BitwiseShiftLeft),
54            BinaryOperator::StringConcat => Ok(Operator::StringConcat),
55            BinaryOperator::ArrowAt => Ok(Operator::ArrowAt),
56            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),
62            BinaryOperator::Spaceship => Ok(Operator::IsNotDistinctFrom),
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),
72        }
73    }
74}