You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by pa...@apache.org on 2021/02/07 04:39:30 UTC

[shardingsphere] branch master updated: code format (#9359)

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 27e7c43  code format (#9359)
27e7c43 is described below

commit 27e7c43ca75ad9da32fc08b022d04eb74fae2465
Author: JingShang Lu <lu...@apache.org>
AuthorDate: Sat Feb 6 20:39:14 2021 -0800

    code format (#9359)
    
    * code format
    
    * fix
---
 .../rewrite/condition/EncryptConditionEngine.java  | 11 +++++----
 .../shadow/condition/ShadowConditionEngine.java    | 16 +++++++------
 .../impl/DropReplicaQueryRuleBackendHandler.java   | 27 +++++++++++-----------
 .../sql/common/extractor/TableExtractor.java       |  3 +--
 .../ddl/impl/AlterIndexStatementAssert.java        |  2 +-
 5 files changed, 31 insertions(+), 28 deletions(-)

diff --git a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-rewrite/src/main/java/org/apache/shardingsphere/encrypt/rewrite/condition/EncryptConditionEngine.java b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-rewrite/src/main/java/org/apache/shardingsphere/encrypt/rewrite/condition/EncryptConditionEngine.java
index 2cce404..06fb4c7 100644
--- a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-rewrite/src/main/java/org/apache/shardingsphere/encrypt/rewrite/condition/EncryptConditionEngine.java
+++ b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-rewrite/src/main/java/org/apache/shardingsphere/encrypt/rewrite/condition/EncryptConditionEngine.java
@@ -67,12 +67,13 @@ public final class EncryptConditionEngine {
         if (!whereSegment.isPresent()) {
             return Collections.emptyList();
         }
-        ExpressionSegment expression = ((WhereAvailable) sqlStatementContext).getWhere().get().getExpr();
-        ExpressionBuilder expressionBuilder = new ExpressionBuilder(expression);
-        Collection<AndPredicate> andPredicates = new LinkedList<>(expressionBuilder.extractAndPredicates().getAndPredicates());
         List<EncryptCondition> result = new LinkedList<>();
-        for (AndPredicate each : andPredicates) {
-            result.addAll(createEncryptConditions(sqlStatementContext, each));
+        if (((WhereAvailable) sqlStatementContext).getWhere().isPresent()) {
+            ExpressionBuilder expressionBuilder = new ExpressionBuilder(((WhereAvailable) sqlStatementContext).getWhere().get().getExpr());
+            Collection<AndPredicate> andPredicates = new LinkedList<>(expressionBuilder.extractAndPredicates().getAndPredicates());
+            for (AndPredicate each : andPredicates) {
+                result.addAll(createEncryptConditions(sqlStatementContext, each));
+            }
         }
         // FIXME process subquery
 //        for (SubqueryPredicateSegment each : sqlStatementContext.getSqlStatement().findSQLSegments(SubqueryPredicateSegment.class)) {
diff --git a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-common/src/main/java/org/apache/shardingsphere/shadow/condition/ShadowConditionEngine.java b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-common/src/main/java/org/apache/shardingsphere/shadow/condition/ShadowConditionEngine.java
index 164fc50..6797b5a 100644
--- a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-common/src/main/java/org/apache/shardingsphere/shadow/condition/ShadowConditionEngine.java
+++ b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-common/src/main/java/org/apache/shardingsphere/shadow/condition/ShadowConditionEngine.java
@@ -60,13 +60,15 @@ public final class ShadowConditionEngine {
         if (!whereSegment.isPresent()) {
             return Optional.empty();
         }
-        ExpressionSegment expression = ((WhereAvailable) sqlStatementContext).getWhere().get().getExpr();
-        ExpressionBuilder expressionBuilder = new ExpressionBuilder(expression);
-        Collection<AndPredicate> andPredicates = new LinkedList<>(expressionBuilder.extractAndPredicates().getAndPredicates());
-        for (AndPredicate each : andPredicates) {
-            Optional<ShadowCondition> condition = createShadowCondition(each);
-            if (condition.isPresent()) {
-                return condition;
+        if (((WhereAvailable) sqlStatementContext).getWhere().isPresent()) {
+            ExpressionSegment expression = ((WhereAvailable) sqlStatementContext).getWhere().get().getExpr();
+            ExpressionBuilder expressionBuilder = new ExpressionBuilder(expression);
+            Collection<AndPredicate> andPredicates = new LinkedList<>(expressionBuilder.extractAndPredicates().getAndPredicates());
+            for (AndPredicate each : andPredicates) {
+                Optional<ShadowCondition> condition = createShadowCondition(each);
+                if (condition.isPresent()) {
+                    return condition;
+                }
             }
         }
         // FIXME process subquery
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/DropReplicaQueryRuleBackendHandler.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/DropReplicaQueryRuleBackendHandler.java
index 7865832..0c2b18e 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/DropReplicaQueryRuleBackendHandler.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/DropReplicaQueryRuleBackendHandler.java
@@ -50,30 +50,31 @@ public final class DropReplicaQueryRuleBackendHandler extends SchemaRequiredBack
     @Override
     public ResponseHeader execute(final String schemaName, final DropReplicaQueryRuleStatement sqlStatement) {
         Collection<String> ruleNames = sqlStatement.getRuleNames();
-        check(schemaName, ruleNames);
-        Collection<RuleConfiguration> rules = drop(schemaName, ruleNames);
-        post(schemaName, rules);
-        return new UpdateResponseHeader(sqlStatement);
-    }
-    
-    private void check(final String schemaName, final Collection<String> ruleNames) {
         Optional<ReplicaQueryRuleConfiguration> replicaQueryRuleConfig = ProxyContext.getInstance().getMetaData(schemaName).getRuleMetaData().getConfigurations().stream()
                 .filter(each -> each instanceof ReplicaQueryRuleConfiguration).map(each -> (ReplicaQueryRuleConfiguration) each).findFirst();
         if (!replicaQueryRuleConfig.isPresent()) {
             throw new ReplicaQueryRuleNotExistedException();
         }
-        Collection<String> replicaQueryNames = replicaQueryRuleConfig.get().getDataSources().stream().map(ReplicaQueryDataSourceRuleConfiguration::getName).collect(Collectors.toList());
+        check(replicaQueryRuleConfig.get(), ruleNames);
+        Optional<YamlReplicaQueryRuleConfiguration> yamlConfig = new YamlRuleConfigurationSwapperEngine().swapToYamlConfigurations(Collections.singletonList(replicaQueryRuleConfig.get())).stream()
+                .map(each -> (YamlReplicaQueryRuleConfiguration) each).findFirst();
+        if (!yamlConfig.isPresent()) {
+            throw new ReplicaQueryRuleNotExistedException();
+        }
+        Collection<RuleConfiguration> rules = drop(yamlConfig.get(), ruleNames);
+        post(schemaName, rules);
+        return new UpdateResponseHeader(sqlStatement);
+    }
+    
+    private void check(final ReplicaQueryRuleConfiguration replicaQueryRuleConfig, final Collection<String> ruleNames) {
+        Collection<String> replicaQueryNames = replicaQueryRuleConfig.getDataSources().stream().map(ReplicaQueryDataSourceRuleConfiguration::getName).collect(Collectors.toList());
         Collection<String> notExistedRuleNames = ruleNames.stream().filter(each -> !replicaQueryNames.contains(each)).collect(Collectors.toList());
         if (!notExistedRuleNames.isEmpty()) {
             throw new ReplicaQueryRuleDataSourcesNotExistedException(notExistedRuleNames);
         }
     }
 
-    private Collection<RuleConfiguration> drop(final String schemaName, final Collection<String> ruleNames) {
-        Collection<RuleConfiguration> replicaQueryRuleConfig = ProxyContext.getInstance().getMetaData(schemaName).getRuleMetaData().getConfigurations().stream()
-                .filter(each -> each instanceof ReplicaQueryRuleConfiguration).map(each -> (ReplicaQueryRuleConfiguration) each).collect(Collectors.toList());
-        YamlReplicaQueryRuleConfiguration yamlConfig = (YamlReplicaQueryRuleConfiguration) new YamlRuleConfigurationSwapperEngine().swapToYamlConfigurations(replicaQueryRuleConfig).stream()
-                .findFirst().get();
+    private Collection<RuleConfiguration> drop(final YamlReplicaQueryRuleConfiguration yamlConfig, final Collection<String> ruleNames) {
         for (String each : ruleNames) {
             yamlConfig.getDataSources().remove(each);
         }
diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/extractor/TableExtractor.java b/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/extractor/TableExtractor.java
index 50f5113..4c572b0 100644
--- a/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/extractor/TableExtractor.java
+++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/extractor/TableExtractor.java
@@ -185,8 +185,7 @@ public final class TableExtractor {
             if (each instanceof ColumnOrderByItemSegment) {
                 Optional<OwnerSegment> owner = ((ColumnOrderByItemSegment) each).getColumn().getOwner();
                 if (owner.isPresent() && needRewrite(owner.get())) {
-                    OwnerSegment segment = ((ColumnOrderByItemSegment) each).getColumn().getOwner().get();
-                    rewriteTables.add(new SimpleTableSegment(segment.getStartIndex(), segment.getStopIndex(), segment.getIdentifier()));
+                    rewriteTables.add(new SimpleTableSegment(owner.get().getStartIndex(), owner.get().getStopIndex(), owner.get().getIdentifier()));
                 }
             }
         }
diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/asserts/statement/ddl/impl/AlterIndexStatementAssert.java b/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/asserts/statement/ddl/impl/AlterIndexStatementAssert.java
index 7e248a2..32cc33d 100644
--- a/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/asserts/statement/ddl/impl/AlterIndexStatementAssert.java
+++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/asserts/statement/ddl/impl/AlterIndexStatementAssert.java
@@ -63,7 +63,7 @@ public final class AlterIndexStatementAssert {
     
     private static void assertIndex(final SQLCaseAssertContext assertContext, final AlterIndexStatement actual, final AlterIndexStatementTestCase expected) {
         // TODO should assert index for all databases(mysql and sqlserver do not parse index right now)
-        if (actual instanceof OracleAlterIndexStatement) {
+        if (actual instanceof OracleAlterIndexStatement && actual.getIndex().isPresent()) {
             IndexAssert.assertIs(assertContext, actual.getIndex().get(), expected.getIndex());
         }
     }