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 86a653aea27 Merge NoUniqueKeyPosition and UnsupportedKeyPosition 
(#27188)
86a653aea27 is described below

commit 86a653aea2758fcdee83447f33c4c487c0ad0093
Author: Liang Zhang <[email protected]>
AuthorDate: Fri Jul 14 12:19:19 2023 +0800

    Merge NoUniqueKeyPosition and UnsupportedKeyPosition (#27188)
    
    * Merge NoUniqueKeyPosition and UnsupportedKeyPosition
    
    * Merge NoUniqueKeyPosition and UnsupportedKeyPosition
---
 .../ingest/position/NoUniqueKeyPosition.java       | 46 ----------------------
 .../ingest/position/PrimaryKeyPositionFactory.java |  2 -
 .../sqlbuilder/PipelineSQLBuilderEngine.java       | 19 ++++-----
 .../core/preparer/InventoryTaskSplitter.java       |  7 ++--
 .../ingest/position/NoUniqueKeyPositionTest.java   | 39 ------------------
 5 files changed, 11 insertions(+), 102 deletions(-)

diff --git 
a/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/common/ingest/position/NoUniqueKeyPosition.java
 
b/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/common/ingest/position/NoUniqueKeyPosition.java
deleted file mode 100644
index 6e9287b5eb6..00000000000
--- 
a/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/common/ingest/position/NoUniqueKeyPosition.java
+++ /dev/null
@@ -1,46 +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.data.pipeline.common.ingest.position;
-
-import 
org.apache.shardingsphere.data.pipeline.api.ingest.position.IngestPosition;
-
-/**
- * No unique key position.
- */
-public final class NoUniqueKeyPosition extends PrimaryKeyPosition<Void> 
implements IngestPosition {
-    
-    @Override
-    public Void getBeginValue() {
-        return null;
-    }
-    
-    @Override
-    public Void getEndValue() {
-        return null;
-    }
-    
-    @Override
-    protected Void convert(final String value) {
-        throw new UnsupportedOperationException();
-    }
-    
-    @Override
-    protected char getType() {
-        return 'n';
-    }
-}
diff --git 
a/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/common/ingest/position/PrimaryKeyPositionFactory.java
 
b/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/common/ingest/position/PrimaryKeyPositionFactory.java
index e24008ddd85..07b75fa3d3c 100644
--- 
a/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/common/ingest/position/PrimaryKeyPositionFactory.java
+++ 
b/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/common/ingest/position/PrimaryKeyPositionFactory.java
@@ -50,8 +50,6 @@ public final class PrimaryKeyPositionFactory {
                 return new 
IntegerPrimaryKeyPosition(Long.parseLong(beginValue), Long.parseLong(endValue));
             case 's':
                 return new StringPrimaryKeyPosition(beginValue, endValue);
-            case 'n':
-                return new NoUniqueKeyPosition();
             case 'u':
                 return new UnsupportedKeyPosition();
             default:
diff --git 
a/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/common/sqlbuilder/PipelineSQLBuilderEngine.java
 
b/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/common/sqlbuilder/PipelineSQLBuilderEngine.java
index dac597fab20..0c945e9bae0 100644
--- 
a/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/common/sqlbuilder/PipelineSQLBuilderEngine.java
+++ 
b/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/common/sqlbuilder/PipelineSQLBuilderEngine.java
@@ -74,15 +74,8 @@ public final class PipelineSQLBuilderEngine {
      */
     public String buildDivisibleInventoryDumpSQL(final String schemaName, 
final String tableName, final List<String> columnNames, final String uniqueKey) 
{
         String qualifiedTableName = 
sqlSegmentBuilder.getQualifiedTableName(schemaName, tableName);
-        String quotedUniqueKey = 
sqlSegmentBuilder.getEscapedIdentifier(uniqueKey);
-        return String.format("SELECT %s FROM %s WHERE %s>=? AND %s<=? ORDER BY 
%s ASC", buildQueryColumns(columnNames), qualifiedTableName, quotedUniqueKey, 
quotedUniqueKey, quotedUniqueKey);
-    }
-    
-    private String buildQueryColumns(final List<String> columnNames) {
-        if (columnNames.isEmpty()) {
-            return "*";
-        }
-        return 
columnNames.stream().map(sqlSegmentBuilder::getEscapedIdentifier).collect(Collectors.joining(","));
+        String escapedUniqueKey = 
sqlSegmentBuilder.getEscapedIdentifier(uniqueKey);
+        return String.format("SELECT %s FROM %s WHERE %s>=? AND %s<=? ORDER BY 
%s ASC", buildQueryColumns(columnNames), qualifiedTableName, escapedUniqueKey, 
escapedUniqueKey, escapedUniqueKey);
     }
     
     /**
@@ -96,8 +89,12 @@ public final class PipelineSQLBuilderEngine {
      */
     public String buildNoLimitedDivisibleInventoryDumpSQL(final String 
schemaName, final String tableName, final List<String> columnNames, final 
String uniqueKey) {
         String qualifiedTableName = 
sqlSegmentBuilder.getQualifiedTableName(schemaName, tableName);
-        String quotedUniqueKey = 
sqlSegmentBuilder.getEscapedIdentifier(uniqueKey);
-        return String.format("SELECT %s FROM %s WHERE %s>=? ORDER BY %s ASC", 
buildQueryColumns(columnNames), qualifiedTableName, quotedUniqueKey, 
quotedUniqueKey);
+        String escapedUniqueKey = 
sqlSegmentBuilder.getEscapedIdentifier(uniqueKey);
+        return String.format("SELECT %s FROM %s WHERE %s>=? ORDER BY %s ASC", 
buildQueryColumns(columnNames), qualifiedTableName, escapedUniqueKey, 
escapedUniqueKey);
+    }
+    
+    private String buildQueryColumns(final List<String> columnNames) {
+        return columnNames.isEmpty() ? "*" : 
columnNames.stream().map(sqlSegmentBuilder::getEscapedIdentifier).collect(Collectors.joining(","));
     }
     
     /**
diff --git 
a/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/preparer/InventoryTaskSplitter.java
 
b/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/preparer/InventoryTaskSplitter.java
index f773649c86b..81de591f8f7 100644
--- 
a/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/preparer/InventoryTaskSplitter.java
+++ 
b/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/preparer/InventoryTaskSplitter.java
@@ -32,7 +32,6 @@ import 
org.apache.shardingsphere.data.pipeline.common.context.InventoryIncrement
 import 
org.apache.shardingsphere.data.pipeline.common.context.InventoryIncrementalProcessContext;
 import 
org.apache.shardingsphere.data.pipeline.common.datasource.PipelineDataSourceWrapper;
 import 
org.apache.shardingsphere.data.pipeline.common.ingest.position.IntegerPrimaryKeyPosition;
-import 
org.apache.shardingsphere.data.pipeline.common.ingest.position.NoUniqueKeyPosition;
 import 
org.apache.shardingsphere.data.pipeline.common.ingest.position.PlaceholderPosition;
 import 
org.apache.shardingsphere.data.pipeline.common.ingest.position.StringPrimaryKeyPosition;
 import 
org.apache.shardingsphere.data.pipeline.common.ingest.position.UnsupportedKeyPosition;
@@ -166,7 +165,7 @@ public final class InventoryTaskSplitter {
         long tableRecordsCount = 
InventoryRecordsCountCalculator.getTableRecordsCount(dumperConfig, dataSource);
         jobItemContext.updateInventoryRecordsCount(tableRecordsCount);
         if (!dumperConfig.hasUniqueKey()) {
-            return Collections.singletonList(new NoUniqueKeyPosition());
+            return Collections.singleton(new UnsupportedKeyPosition());
         }
         List<PipelineColumnMetaData> uniqueKeyColumns = 
dumperConfig.getUniqueKeyColumns();
         if (1 == uniqueKeyColumns.size()) {
@@ -176,10 +175,10 @@ public final class InventoryTaskSplitter {
             }
             if (PipelineJdbcUtils.isStringColumn(firstColumnDataType)) {
                 // TODO Support string unique key table splitting. Ascii 
characters ordering are different in different versions of databases.
-                return Collections.singletonList(new 
StringPrimaryKeyPosition(null, null));
+                return Collections.singleton(new 
StringPrimaryKeyPosition(null, null));
             }
         }
-        return Collections.singletonList(new UnsupportedKeyPosition());
+        return Collections.singleton(new UnsupportedKeyPosition());
     }
     
     private Collection<IngestPosition> 
getPositionByIntegerUniqueKeyRange(final InventoryDumperConfiguration 
dumperConfig, final long tableRecordsCount,
diff --git 
a/kernel/data-pipeline/core/src/test/java/org/apache/shardingsphere/data/pipeline/common/ingest/position/NoUniqueKeyPositionTest.java
 
b/kernel/data-pipeline/core/src/test/java/org/apache/shardingsphere/data/pipeline/common/ingest/position/NoUniqueKeyPositionTest.java
deleted file mode 100644
index 3fb87a760de..00000000000
--- 
a/kernel/data-pipeline/core/src/test/java/org/apache/shardingsphere/data/pipeline/common/ingest/position/NoUniqueKeyPositionTest.java
+++ /dev/null
@@ -1,39 +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.data.pipeline.common.ingest.position;
-
-import org.junit.jupiter.api.Test;
-
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.junit.jupiter.api.Assertions.assertNull;
-
-class NoUniqueKeyPositionTest {
-    
-    @Test
-    void assertInit() {
-        NoUniqueKeyPosition position = (NoUniqueKeyPosition) 
PrimaryKeyPositionFactory.newInstance("n,,");
-        assertNull(position.getBeginValue());
-        assertNull(position.getEndValue());
-    }
-    
-    @Test
-    void assertToString() {
-        assertThat(new NoUniqueKeyPosition().toString(), is("n,,"));
-    }
-}

Reply via email to