You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by "sandynz (via GitHub)" <gi...@apache.org> on 2023/04/12 12:43:08 UTC

[GitHub] [shardingsphere] sandynz commented on a diff in pull request #25144: Fix the error of incremental tasks caused by datetime containing zero value in MySQL

sandynz commented on code in PR #25144:
URL: https://github.com/apache/shardingsphere/pull/25144#discussion_r1164079234


##########
db-protocol/mysql/src/main/java/org/apache/shardingsphere/db/protocol/mysql/packet/binlog/row/column/value/time/MySQLDatetime2BinlogProtocolValue.java:
##########
@@ -48,6 +48,9 @@ private long readDatetimeV2FromPayload(final MySQLPacketPayload payload) {
     
     private Serializable readDatetime(final MySQLBinlogColumnDef columnDef, final long datetime, final MySQLPacketPayload payload) {
         long datetimeWithoutSign = datetime & (0x8000000000L - 1);
+        if (0 == datetimeWithoutSign) {
+            return MySQLTimeValueUtils.DATETIME_OF_ZERO;
+        }

Review Comment:
   How many values `long datetime` could be? Seems all of them will be `0` after `& (0x8000000000L - 1)`, and `0000-00-00 00:00:00` should be only one value, so I'm not sure whether it's correct or not.
   
   It's better to find related official document and put it here, then we could discuss about it.
   



##########
test/e2e/operation/pipeline/src/test/java/org/apache/shardingsphere/test/e2e/data/pipeline/cases/migration/general/MySQLTimeTypesMigrationE2EIT.java:
##########
@@ -0,0 +1,73 @@
+/*
+ * 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.test.e2e.data.pipeline.cases.migration.general;
+
+
+import org.apache.shardingsphere.data.pipeline.scenario.migration.MigrationJobType;
+import org.apache.shardingsphere.infra.database.type.dialect.MySQLDatabaseType;
+import org.apache.shardingsphere.test.e2e.data.pipeline.cases.PipelineContainerComposer;
+import org.apache.shardingsphere.test.e2e.data.pipeline.cases.migration.AbstractMigrationE2EIT;
+import org.apache.shardingsphere.test.e2e.data.pipeline.framework.param.PipelineE2ECondition;
+import org.apache.shardingsphere.test.e2e.data.pipeline.framework.param.PipelineE2ESettings;
+import org.apache.shardingsphere.test.e2e.data.pipeline.framework.param.PipelineE2ETestCaseArgumentsProvider;
+import org.apache.shardingsphere.test.e2e.data.pipeline.framework.param.PipelineTestParameter;
+import org.junit.jupiter.api.condition.EnabledIf;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.ArgumentsSource;
+
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+
+/**
+ * E2E IT for time types of MySQL, includes:
+ * 1) datetime.
+ * 2) timestamp.
+ * 3) date
+ */
+@PipelineE2ESettings(fetchSingle = true, database = @PipelineE2ESettings.PipelineE2EDatabaseSettings(type = "MySQL", scenarioFiles = "env/common/none.xml"))
+public class MySQLTimeTypesMigrationE2EIT extends AbstractMigrationE2EIT {
+    
+    @ParameterizedTest(name = "{0}")
+    @EnabledIf("isEnabled")
+    @ArgumentsSource(PipelineE2ETestCaseArgumentsProvider.class)
+    void assertIllegalTimeTypesValueMigrationSuccess(final PipelineTestParameter testParam) throws Exception {
+        try (PipelineContainerComposer containerComposer = new PipelineContainerComposer(testParam, new MigrationJobType())) {
+            String sql = "CREATE TABLE `time_e2e` ( `id` int NOT NULL, `t_timestamp` timestamp NULL DEFAULT NULL, `t_datetime` datetime DEFAULT NULL, `t_date` date DEFAULT NULL, `t_year` year DEFAULT NULL, PRIMARY KEY (`id`)) ENGINE=InnoDB;";
+            containerComposer.sourceExecuteWithLog(sql);
+            try (Connection connection = containerComposer.getSourceDataSource().getConnection()) {
+                PreparedStatement preparedStatement = connection.prepareStatement("INSERT INTO `time_e2e`(id, t_timestamp, t_datetime, t_date, t_year) VALUES (?, ?, ?, ?, ?)");
+                preparedStatement.setObject(1, 1);
+                preparedStatement.setObject(2, "0000-00-00 00:00:00");
+                preparedStatement.setObject(3, "0000-00-00 00:00:00");
+                preparedStatement.setObject(4, "0000-00-00");
+                preparedStatement.setObject(5, "0000");
+                preparedStatement.execute();
+            }
+            addMigrationSourceResource(containerComposer);
+            addMigrationTargetResource(containerComposer);
+            startMigration(containerComposer, "time_e2e", "time_e2e");
+            String jobId = listJobId(containerComposer).get(0);

Review Comment:
   It's better to add incremental task in E2E to verify related modification



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org