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

zhonghongsheng 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 9fceb28  For #14605: The binary type is abnormal during the data 
migration data check phase (#14676)
9fceb28 is described below

commit 9fceb288cb9e9799a300dc21876f589cbf5a4b29
Author: ReyYang <[email protected]>
AuthorDate: Tue Jan 11 10:50:48 2022 +0800

    For #14605: The binary type is abnormal during the data migration data 
check phase (#14676)
---
 .../driver/jdbc/type/memory/JDBCRowsLoader.java    |  3 +-
 .../type/memory/JDBCMemoryQueryResultTest.java     | 18 ++++-----
 ...AbstractStreamingSingleTableDataCalculator.java |  2 +-
 .../DataMatchSingleTableDataCalculator.java        | 45 +++++++++++++++++++++-
 4 files changed, 55 insertions(+), 13 deletions(-)

diff --git 
a/shardingsphere-infra/shardingsphere-infra-executor/src/main/java/org/apache/shardingsphere/infra/executor/sql/execute/result/query/impl/driver/jdbc/type/memory/JDBCRowsLoader.java
 
b/shardingsphere-infra/shardingsphere-infra-executor/src/main/java/org/apache/shardingsphere/infra/executor/sql/execute/result/query/impl/driver/jdbc/type/memory/JDBCRowsLoader.java
index 92cba4c..fdc111c 100644
--- 
a/shardingsphere-infra/shardingsphere-infra-executor/src/main/java/org/apache/shardingsphere/infra/executor/sql/execute/result/query/impl/driver/jdbc/type/memory/JDBCRowsLoader.java
+++ 
b/shardingsphere-infra/shardingsphere-infra-executor/src/main/java/org/apache/shardingsphere/infra/executor/sql/execute/result/query/impl/driver/jdbc/type/memory/JDBCRowsLoader.java
@@ -97,10 +97,11 @@ public final class JDBCRowsLoader {
             case Types.CLOB:
                 return resultSet.getClob(columnIndex);
             case Types.BLOB:
+                return resultSet.getBlob(columnIndex);
             case Types.BINARY:
             case Types.VARBINARY:
             case Types.LONGVARBINARY:
-                return resultSet.getBlob(columnIndex);
+                return resultSet.getBytes(columnIndex);
             case Types.ARRAY:
                 return resultSet.getArray(columnIndex);
             default:
diff --git 
a/shardingsphere-infra/shardingsphere-infra-executor/src/test/java/org/apache/shardingsphere/infra/executor/sql/execute/result/query/impl/driver/jdbc/type/memory/JDBCMemoryQueryResultTest.java
 
b/shardingsphere-infra/shardingsphere-infra-executor/src/test/java/org/apache/shardingsphere/infra/executor/sql/execute/result/query/impl/driver/jdbc/type/memory/JDBCMemoryQueryResultTest.java
index 7fabb24..7e014bc 100644
--- 
a/shardingsphere-infra/shardingsphere-infra-executor/src/test/java/org/apache/shardingsphere/infra/executor/sql/execute/result/query/impl/driver/jdbc/type/memory/JDBCMemoryQueryResultTest.java
+++ 
b/shardingsphere-infra/shardingsphere-infra-executor/src/test/java/org/apache/shardingsphere/infra/executor/sql/execute/result/query/impl/driver/jdbc/type/memory/JDBCMemoryQueryResultTest.java
@@ -276,33 +276,33 @@ public final class JDBCMemoryQueryResultTest {
     @Test
     public void assertGetValueByBinary() throws SQLException {
         ResultSet resultSet = getMockedResultSet(Types.BINARY);
-        Blob value = mock(Blob.class);
-        when(resultSet.getBlob(1)).thenReturn(value);
+        byte[] value = new byte[10];
+        when(resultSet.getBytes(1)).thenReturn(value);
         JDBCMemoryQueryResult actual = new JDBCMemoryQueryResult(resultSet);
         assertTrue(actual.next());
-        assertThat(actual.getValue(1, Blob.class), is(value));
+        assertThat(actual.getValue(1, byte[].class), is(value));
         assertFalse(actual.next());
     }
     
     @Test
     public void assertGetValueByVarBinary() throws SQLException {
         ResultSet resultSet = getMockedResultSet(Types.VARBINARY);
-        Blob value = mock(Blob.class);
-        when(resultSet.getBlob(1)).thenReturn(value);
+        byte[] value = new byte[10];
+        when(resultSet.getBytes(1)).thenReturn(value);
         JDBCMemoryQueryResult actual = new JDBCMemoryQueryResult(resultSet);
         assertTrue(actual.next());
-        assertThat(actual.getValue(1, Blob.class), is(value));
+        assertThat(actual.getValue(1, byte[].class), is(value));
         assertFalse(actual.next());
     }
     
     @Test
     public void assertGetValueByLongVarBinary() throws SQLException {
         ResultSet resultSet = getMockedResultSet(Types.LONGVARBINARY);
-        Blob value = mock(Blob.class);
-        when(resultSet.getBlob(1)).thenReturn(value);
+        byte[] value = new byte[10];
+        when(resultSet.getBytes(1)).thenReturn(value);
         JDBCMemoryQueryResult actual = new JDBCMemoryQueryResult(resultSet);
         assertTrue(actual.next());
-        assertThat(actual.getValue(1, Blob.class), is(value));
+        assertThat(actual.getValue(1, byte[].class), is(value));
         assertFalse(actual.next());
     }
     
diff --git 
a/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/core/spi/check/consistency/AbstractStreamingSingleTableDataCalculator.java
 
b/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/core/spi/check/consistency/AbstractStreamingSingleTableDataCalculator.java
index ba7b031..a973020 100644
--- 
a/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/core/spi/check/consistency/AbstractStreamingSingleTableDataCalculator.java
+++ 
b/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/core/spi/check/consistency/AbstractStreamingSingleTableDataCalculator.java
@@ -82,7 +82,7 @@ public abstract class 
AbstractStreamingSingleTableDataCalculator extends Abstrac
             Optional<Object> nextResult = this.nextResult;
             
dataCalculateParameter.setPreviousCalculatedResult(nextResult.orElse(null));
             this.nextResult = null;
-            return nextResult;
+            return nextResult.orElse(null);
         }
         
         private void calculateIfNecessary() {
diff --git 
a/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/core/spi/check/consistency/DataMatchSingleTableDataCalculator.java
 
b/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/core/spi/check/consistency/DataMatchSingleTableDataCalculator.java
index c10dcf5..d02b736 100644
--- 
a/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/core/spi/check/consistency/DataMatchSingleTableDataCalculator.java
+++ 
b/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/core/spi/check/consistency/DataMatchSingleTableDataCalculator.java
@@ -18,11 +18,12 @@
 package org.apache.shardingsphere.data.pipeline.core.spi.check.consistency;
 
 import com.google.common.base.Strings;
-import lombok.EqualsAndHashCode;
 import lombok.Getter;
 import lombok.NonNull;
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.builder.EqualsBuilder;
+import org.apache.commons.lang3.builder.HashCodeBuilder;
 import 
org.apache.shardingsphere.data.pipeline.api.check.consistency.DataCalculateParameter;
 import 
org.apache.shardingsphere.data.pipeline.core.exception.PipelineDataConsistencyCheckFailedException;
 import 
org.apache.shardingsphere.data.pipeline.spi.sqlbuilder.PipelineSQLBuilder;
@@ -37,6 +38,7 @@ import java.sql.ResultSetMetaData;
 import java.sql.SQLException;
 import java.util.ArrayList;
 import java.util.Collection;
+import java.util.Iterator;
 import java.util.Optional;
 import java.util.Properties;
 
@@ -115,7 +117,6 @@ public final class DataMatchSingleTableDataCalculator 
extends AbstractStreamingS
     
     @RequiredArgsConstructor
     @Getter
-    @EqualsAndHashCode
     private static final class CalculatedResult {
         
         @NonNull
@@ -124,5 +125,45 @@ public final class DataMatchSingleTableDataCalculator 
extends AbstractStreamingS
         private final int recordCount;
         
         private final Collection<Collection<Object>> records;
+    
+        @Override
+        public boolean equals(final Object o) {
+            if (this == o) {
+                return true;
+            }
+            if (!(o instanceof CalculatedResult)) {
+                return false;
+            }
+        
+            final CalculatedResult that = (CalculatedResult) o;
+    
+            boolean equalsFirst = new EqualsBuilder().append(getRecordCount(), 
that.getRecordCount()).append(getMaxUniqueKeyValue(), 
that.getMaxUniqueKeyValue()).isEquals();
+            if (!equalsFirst) {
+                return false;
+            }
+            
+            Iterator<Collection<Object>> thisIterator = 
this.records.iterator();
+            Iterator<Collection<Object>> thatIterator = 
that.records.iterator();
+            while (thisIterator.hasNext() && thatIterator.hasNext()) {
+                Collection<Object> thisNext = thisIterator.next();
+                Collection<Object> thatNext = thatIterator.next();
+                if (thisNext.size() != thatNext.size()) {
+                    return false;
+                }
+                Iterator<Object> thisNextIterator = thisNext.iterator();
+                Iterator<Object> thatNextIterator = thatNext.iterator();
+                while (thisNextIterator.hasNext() && 
thatNextIterator.hasNext()) {
+                    if (!new EqualsBuilder().append(thisNextIterator.next(), 
thatNextIterator.next()).isEquals()) {
+                        return false;
+                    }
+                }
+            }
+            return true;
+        }
+    
+        @Override
+        public int hashCode() {
+            return new HashCodeBuilder(17, 
37).append(getMaxUniqueKeyValue()).append(getRecordCount()).append(getRecords()).toHashCode();
+        }
     }
 }

Reply via email to