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

panjuan 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 c28b542  Remove BinarySQLOperator (#12706)
c28b542 is described below

commit c28b5425bd34c6c053f9437df102d56cd229573d
Author: Liang Zhang <[email protected]>
AuthorDate: Sat Sep 25 15:02:06 2021 +0800

    Remove BinarySQLOperator (#12706)
---
 .../impl/BinaryOperationExpressionConverter.java   | 29 +++++++++-
 .../infra/optimize/operator/BinarySQLOperator.java | 64 ----------------------
 2 files changed, 26 insertions(+), 67 deletions(-)

diff --git 
a/shardingsphere-infra/shardingsphere-infra-optimize/src/main/java/org/apache/shardingsphere/infra/optimize/converter/segment/expression/impl/BinaryOperationExpressionConverter.java
 
b/shardingsphere-infra/shardingsphere-infra-optimize/src/main/java/org/apache/shardingsphere/infra/optimize/converter/segment/expression/impl/BinaryOperationExpressionConverter.java
index f68de30..fa99a27 100644
--- 
a/shardingsphere-infra/shardingsphere-infra-optimize/src/main/java/org/apache/shardingsphere/infra/optimize/converter/segment/expression/impl/BinaryOperationExpressionConverter.java
+++ 
b/shardingsphere-infra/shardingsphere-infra-optimize/src/main/java/org/apache/shardingsphere/infra/optimize/converter/segment/expression/impl/BinaryOperationExpressionConverter.java
@@ -19,27 +19,50 @@ package 
org.apache.shardingsphere.infra.optimize.converter.segment.expression.im
 
 import com.google.common.base.Preconditions;
 import org.apache.calcite.sql.SqlBasicCall;
+import org.apache.calcite.sql.SqlBinaryOperator;
 import org.apache.calcite.sql.SqlNode;
+import org.apache.calcite.sql.fun.SqlStdOperatorTable;
 import org.apache.calcite.sql.parser.SqlParserPos;
 import 
org.apache.shardingsphere.infra.optimize.converter.segment.SQLSegmentConverter;
 import 
org.apache.shardingsphere.infra.optimize.converter.segment.expression.ExpressionConverter;
-import org.apache.shardingsphere.infra.optimize.operator.BinarySQLOperator;
 import 
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.BinaryOperationExpression;
 import 
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.ExpressionSegment;
 
+import java.util.Map;
 import java.util.Optional;
+import java.util.TreeMap;
 
 /**
  * Binary operation expression converter.
  */
 public final class BinaryOperationExpressionConverter implements 
SQLSegmentConverter<BinaryOperationExpression, SqlNode> {
     
+    private static final Map<String, SqlBinaryOperator> REGISTRY = new 
TreeMap<>(String.CASE_INSENSITIVE_ORDER);
+    
+    static {
+        register(SqlStdOperatorTable.EQUALS);
+        register(SqlStdOperatorTable.GREATER_THAN);
+        register(SqlStdOperatorTable.GREATER_THAN_OR_EQUAL);
+        register(SqlStdOperatorTable.LESS_THAN);
+        register(SqlStdOperatorTable.LESS_THAN_OR_EQUAL);
+        register(SqlStdOperatorTable.AND);
+    }
+    
+    private static void register(final SqlBinaryOperator sqlBinaryOperator) {
+        REGISTRY.put(sqlBinaryOperator.getName(), sqlBinaryOperator);
+    }
+    
     @Override
     public Optional<SqlNode> convert(final BinaryOperationExpression segment) {
-        BinarySQLOperator operator = 
BinarySQLOperator.value(segment.getOperator());
+        SqlBinaryOperator operator = getOperator(segment.getOperator());
         SqlNode left = convertExpression(segment.getLeft());
         SqlNode right = convertExpression(segment.getRight());
-        return Optional.of(new SqlBasicCall(operator.getSqlBinaryOperator(), 
new SqlNode[] {left, right}, SqlParserPos.ZERO));
+        return Optional.of(new SqlBasicCall(operator, new SqlNode[] {left, 
right}, SqlParserPos.ZERO));
+    }
+    
+    private SqlBinaryOperator getOperator(final String operator) {
+        Preconditions.checkState(REGISTRY.containsKey(operator), "Unsupported 
SQL operator: `%s`", operator);
+        return REGISTRY.get(operator);
     }
     
     private SqlNode convertExpression(final ExpressionSegment segment) {
diff --git 
a/shardingsphere-infra/shardingsphere-infra-optimize/src/main/java/org/apache/shardingsphere/infra/optimize/operator/BinarySQLOperator.java
 
b/shardingsphere-infra/shardingsphere-infra-optimize/src/main/java/org/apache/shardingsphere/infra/optimize/operator/BinarySQLOperator.java
deleted file mode 100644
index 04bf0bf..0000000
--- 
a/shardingsphere-infra/shardingsphere-infra-optimize/src/main/java/org/apache/shardingsphere/infra/optimize/operator/BinarySQLOperator.java
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
- * 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.infra.optimize.operator;
-
-import lombok.Getter;
-import lombok.RequiredArgsConstructor;
-import org.apache.calcite.sql.SqlBinaryOperator;
-import org.apache.calcite.sql.fun.SqlStdOperatorTable;
-
-/**
- * Binary SQL operator.
- */
-@RequiredArgsConstructor
-public enum BinarySQLOperator {
-    
-    EQUALS("=", SqlStdOperatorTable.EQUALS),
-    
-    GREATER_THAN(">", SqlStdOperatorTable.GREATER_THAN),
-    
-    GREATER_EQUALS_THAN(">=", SqlStdOperatorTable.GREATER_THAN_OR_EQUAL),
-    
-    LESS_THAN("<", SqlStdOperatorTable.LESS_THAN),
-    
-    LESS_EQUALS_THAN("<=", SqlStdOperatorTable.LESS_THAN_OR_EQUAL),
-    
-    AND("AND", SqlStdOperatorTable.AND),
-    
-    NONE("", null);
-    
-    private final String operator;
-    
-    @Getter
-    private final SqlBinaryOperator sqlBinaryOperator;
-    
-    /**
-     * Convert string to binary SQL operator.
-     * 
-     * @param sqlOperator SQL operator type
-     * @return converted binary SQL operator
-     */
-    public static BinarySQLOperator value(final String sqlOperator) {
-        for (BinarySQLOperator each : values()) {
-            if (each.operator.equalsIgnoreCase(sqlOperator)) {
-                return each;
-            }
-        }
-        throw new UnsupportedOperationException("unsupported sql operator: " + 
sqlOperator);
-    }
-}

Reply via email to