You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by du...@apache.org on 2023/06/09 02:45:19 UTC

[shardingsphere] branch master updated: support for Operators which calcite dont support (#25953)

This is an automated email from the ASF dual-hosted git repository.

duanzhengqiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git


The following commit(s) were added to refs/heads/master by this push:
     new d54aba683ad support for Operators which calcite dont support (#25953)
d54aba683ad is described below

commit d54aba683adad0f917d9224cce5737a154396f29
Author: kanha gupta <92...@users.noreply.github.com>
AuthorDate: Fri Jun 9 08:15:12 2023 +0530

    support for Operators which calcite dont support (#25953)
---
 .../impl/BinaryOperationExpressionConverter.java   |  5 +++
 .../expression/impl/SQLExtensionOperatorTable.java | 37 ++++++++++++++++++++++
 .../test/resources/converter/select-expression.xml | 30 ++++++++++++++++++
 3 files changed, 72 insertions(+)

diff --git a/kernel/sql-federation/core/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/segment/expression/impl/BinaryOperationExpressionConverter.java b/kernel/sql-federation/core/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/segment/expression/impl/BinaryOperationExpressionConverter.java
index 7f2f19513df..c2ba376f073 100644
--- a/kernel/sql-federation/core/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/segment/expression/impl/BinaryOperationExpressionConverter.java
+++ b/kernel/sql-federation/core/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/segment/expression/impl/BinaryOperationExpressionConverter.java
@@ -72,6 +72,11 @@ public final class BinaryOperationExpressionConverter implements SQLSegmentConve
         register(SqlStdOperatorTable.CONCAT);
         register(SqlStdOperatorTable.PATTERN_ALTER);
         register(SqlStdOperatorTable.MOD);
+        register(SQLExtensionOperatorTable.DIV);
+        register(SQLExtensionOperatorTable.CARET);
+        register(SQLExtensionOperatorTable.AMPERSAND);
+        register(SQLExtensionOperatorTable.SIGNED_RIGHT_SHIFT);
+        register(SQLExtensionOperatorTable.SIGNED_LEFT_SHIFT);
     }
     
     private static void register(final SqlOperator sqlOperator) {
diff --git a/kernel/sql-federation/core/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/segment/expression/impl/SQLExtensionOperatorTable.java b/kernel/sql-federation/core/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/segment/expression/impl/SQLExtensionOperatorTable.java
new file mode 100644
index 00000000000..c581e3f7ab9
--- /dev/null
+++ b/kernel/sql-federation/core/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/segment/expression/impl/SQLExtensionOperatorTable.java
@@ -0,0 +1,37 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.sqlfederation.optimizer.converter.segment.expression.impl;
+
+import org.apache.calcite.sql.SqlBinaryOperator;
+import org.apache.calcite.sql.SqlKind;
+
+/**
+ * SQL Extension Operator Table.
+ */
+public final class SQLExtensionOperatorTable {
+    
+    public static final SqlBinaryOperator DIV = new SqlBinaryOperator("DIV", SqlKind.OTHER, 60, true, null, null, null);
+    
+    public static final SqlBinaryOperator CARET = new SqlBinaryOperator("^", SqlKind.OTHER, 30, true, null, null, null);
+    
+    public static final SqlBinaryOperator AMPERSAND = new SqlBinaryOperator("&", SqlKind.OTHER, 24, true, null, null, null);
+    
+    public static final SqlBinaryOperator SIGNED_LEFT_SHIFT = new SqlBinaryOperator("<<", SqlKind.OTHER, 30, true, null, null, null);
+    
+    public static final SqlBinaryOperator SIGNED_RIGHT_SHIFT = new SqlBinaryOperator(">>", SqlKind.OTHER, 30, true, null, null, null);
+}
diff --git a/test/it/optimizer/src/test/resources/converter/select-expression.xml b/test/it/optimizer/src/test/resources/converter/select-expression.xml
new file mode 100644
index 00000000000..1d717a44e6c
--- /dev/null
+++ b/test/it/optimizer/src/test/resources/converter/select-expression.xml
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  ~ Licensed to the Apache Software Foundation (ASF) under one or more
+  ~ contributor license agreements.  See the NOTICE file distributed with
+  ~ this work for additional information regarding copyright ownership.
+  ~ The ASF licenses this file to You under the Apache License, Version 2.0
+  ~ (the "License"); you may not use this file except in compliance with
+  ~ the License.  You may obtain a copy of the License at
+  ~
+  ~     http://www.apache.org/licenses/LICENSE-2.0
+  ~
+  ~ Unless required by applicable law or agreed to in writing, software
+  ~ distributed under the License is distributed on an "AS IS" BASIS,
+  ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  ~ See the License for the specific language governing permissions and
+  ~ limitations under the License.
+  -->
+
+<sql-node-converter-test-cases>
+    <test-cases sql-case-id="select_where_with_bit_expr_with_ampersand" expected-sql="SELECT * FROM `t_order` WHERE (`t_order`.`order_id` &amp; 1)" db-types="MySQL" sql-case-types="LITERAL" />
+    <test-cases sql-case-id="select_where_with_bit_expr_with_ampersand" expected-sql="SELECT * FROM `t_order` WHERE (`t_order`.`order_id` &amp; ?)" db-types="MySQL" sql-case-types="PLACEHOLDER" />
+    <test-cases sql-case-id="select_where_with_bit_expr_with_caret" expected-sql="SELECT * FROM `t_order` WHERE `t_order`.`order_id` ^ 1" db-types="MySQL"  sql-case-types="LITERAL" />
+    <test-cases sql-case-id="select_where_with_bit_expr_with_caret" expected-sql="SELECT * FROM `t_order` WHERE `t_order`.`order_id` ^ ?" db-types="MySQL" sql-case-types="PLACEHOLDER" />
+    <test-cases sql-case-id="select_where_with_bit_expr_with_div" expected-sql="SELECT * FROM `t_order` WHERE `t_order`.`order_id` DIV 1" db-types="MySQL" sql-case-types="LITERAL" />
+    <test-cases sql-case-id="select_where_with_bit_expr_with_div" expected-sql="SELECT * FROM `t_order` WHERE `t_order`.`order_id` DIV ?" db-types="MySQL" sql-case-types="PLACEHOLDER" />
+    <test-cases sql-case-id="select_where_with_bit_expr_with_signed_right_shift" expected-sql="SELECT * FROM `t_order` WHERE `t_order`.`order_id` &gt;&gt; 1" db-types="MySQL" sql-case-types="LITERAL" />
+    <test-cases sql-case-id="select_where_with_bit_expr_with_signed_right_shift" expected-sql="SELECT * FROM `t_order` WHERE `t_order`.`order_id` &gt;&gt; ?" db-types="MySQL" sql-case-types="PLACEHOLDER" />
+    <test-cases sql-case-id="select_where_with_bit_expr_with_signed_left_shift" expected-sql="SELECT * FROM `t_order` WHERE `t_order`.`order_id` &lt;&lt; 1" db-types="MySQL" sql-case-types="LITERAL" />
+    <test-cases sql-case-id="select_where_with_bit_expr_with_signed_left_shift" expected-sql="SELECT * FROM `t_order` WHERE `t_order`.`order_id` &lt;&lt; ?" db-types="MySQL" sql-case-types="PLACEHOLDER" />
+</sql-node-converter-test-cases>