fix tests
diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/receiver/transform/converter/ValueConverter.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/receiver/transform/converter/ValueConverter.java index 4947a94..a2ed11f 100644 --- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/receiver/transform/converter/ValueConverter.java +++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/receiver/transform/converter/ValueConverter.java
@@ -523,30 +523,51 @@ ///////////// TEXT ////////////// public static boolean convertTextToBoolean(final Binary value) { + if (value == null) { + return false; + } return Boolean.parseBoolean(value.toString()); } public static int convertTextToInt32(final Binary value) { + if (value == null) { + return 0; + } return (int) parseDouble(value.toString()); } public static long convertTextToInt64(final Binary value) { + if (value == null) { + return 0L; + } return (long) parseDouble(value.toString()); } public static float convertTextToFloat(final Binary value) { + if (value == null) { + return 0.0f; + } return parseFloat(value.toString()); } public static double convertTextToDouble(final Binary value) { + if (value == null) { + return 0.0; + } return parseDouble(value.toString()); } public static long convertTextToTimestamp(final Binary value) { + if (value == null) { + return 0L; + } return parseTimestamp(value.toString()); } public static int convertTextToDate(final Binary value) { + if (value == null) { + return 0; + } return parseDate(value.toString()); } @@ -649,30 +670,51 @@ ///////////// BLOB ////////////// public static boolean convertBlobToBoolean(final Binary value) { + if (value == null) { + return false; + } return Boolean.parseBoolean(value.toString()); } public static int convertBlobToInt32(final Binary value) { + if (value == null) { + return 0; + } return (int) parseDouble(value.toString()); } public static long convertBlobToInt64(final Binary value) { + if (value == null) { + return 0L; + } return (long) parseDouble(value.toString()); } public static float convertBlobToFloat(final Binary value) { + if (value == null) { + return 0.0f; + } return parseFloat(value.toString()); } public static double convertBlobToDouble(final Binary value) { + if (value == null) { + return 0.0; + } return parseDouble(value.toString()); } public static long convertBlobToTimestamp(final Binary value) { + if (value == null) { + return 0L; + } return parseTimestamp(value.toString()); } public static int convertBlobToDate(final Binary value) { + if (value == null) { + return 0; + } return parseDate(value.toString()); } @@ -687,30 +729,51 @@ ///////////// STRING ////////////// public static boolean convertStringToBoolean(final Binary value) { + if (value == null) { + return false; + } return Boolean.parseBoolean(value.toString()); } public static int convertStringToInt32(final Binary value) { + if (value == null) { + return 0; + } return (int) parseDouble(value.toString()); } public static long convertStringToInt64(final Binary value) { + if (value == null) { + return 0L; + } return (long) parseDouble(value.toString()); } public static float convertStringToFloat(final Binary value) { + if (value == null) { + return 0.0f; + } return parseFloat(value.toString()); } public static double convertStringToDouble(final Binary value) { + if (value == null) { + return 0.0; + } return parseDouble(value.toString()); } public static long convertStringToTimestamp(final Binary value) { + if (value == null) { + return 0L; + } return parseTimestamp(value.toString()); } public static int convertStringToDate(final Binary value) { + if (value == null) { + return 0; + } return parseDate(value.toString()); }
diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/receiver/transform/statement/PipeConvertedInsertTabletStatement.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/receiver/transform/statement/PipeConvertedInsertTabletStatement.java index 2ee370b..3f6f4af 100644 --- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/receiver/transform/statement/PipeConvertedInsertTabletStatement.java +++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/receiver/transform/statement/PipeConvertedInsertTabletStatement.java
@@ -19,6 +19,7 @@ package org.apache.iotdb.db.pipe.receiver.transform.statement; +import org.apache.iotdb.db.pipe.receiver.transform.converter.ArrayConverter; import org.apache.iotdb.db.queryengine.plan.statement.crud.InsertTabletStatement; import org.apache.tsfile.annotations.TableModel; @@ -102,7 +103,7 @@ measurements[columnIndex], dataTypes[columnIndex], dataType); - columns.castTo(columnIndex, dataType); + columns.castTo(columnIndex, dataType, ArrayConverter::convert); dataTypes[columnIndex] = dataType; return true; }
diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/statement/crud/InsertTabletStatement.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/statement/crud/InsertTabletStatement.java index a804ec4..24190dc 100644 --- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/statement/crud/InsertTabletStatement.java +++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/statement/crud/InsertTabletStatement.java
@@ -229,7 +229,7 @@ @Override protected boolean checkAndCastDataType(int columnIndex, TSDataType dataType) { if (dataType.isCompatible(dataTypes[columnIndex])) { - columns.castTo(columnIndex, dataType); + columns.castTo(columnIndex, dataType, null); dataTypes[columnIndex] = dataType; return true; } @@ -877,7 +877,7 @@ return size; } - void castTo(int colIndex, TSDataType newType); + void castTo(int colIndex, TSDataType newType, ArrayConvertor convertor); void insertColumn(int pos, ColumnSchema columnSchema); @@ -903,6 +903,11 @@ // for compatibility only, do no use it in new code @Deprecated Object[] toTwoDArray(); + + @FunctionalInterface + interface ArrayConvertor { + Object convert(TSDataType from, TSDataType to, Object value); + } } public static class TwoDArrayValueView implements ValueView { @@ -1175,8 +1180,14 @@ } @Override - public void castTo(int colIndex, TSDataType newType) { - values[colIndex] = newType.castFromArray(dataTypes.get()[colIndex], values[colIndex]); + public void castTo(int colIndex, TSDataType newType, ArrayConvertor arrayConvertor) { + if (arrayConvertor == null) { + values[colIndex] = newType.castFromArray(dataTypes.get()[colIndex], values[colIndex]); + } else { + values[colIndex] = + arrayConvertor.convert(dataTypes.get()[colIndex], newType, values[colIndex]); + } + dataTypes()[colIndex] = newType; } @Override @@ -1704,14 +1715,20 @@ } @Override - public void castTo(int colIndex, TSDataType newType) { + public void castTo(int colIndex, TSDataType newType, ArrayConvertor arrayConvertor) { for (int i = 0; i < values[colIndex].length; i++) { Object originalArray = values[colIndex][i]; - values[colIndex][i] = newType.castFromArray(dataTypes.get()[colIndex], originalArray); + if (arrayConvertor == null) { + values[colIndex][i] = newType.castFromArray(dataTypes.get()[colIndex], originalArray); + } else { + values[colIndex][i] = + arrayConvertor.convert(dataTypes()[colIndex], newType, originalArray); + } if (originalArray != values[colIndex][i]) { release(originalArray); } } + dataTypes()[colIndex] = newType; } @Override @@ -1808,6 +1825,7 @@ singleArraySize); current += copyLength; + pos += copyLength; } } @@ -1853,9 +1871,7 @@ currentTVListPos += copyLength; } } - tvList.markNotInsertedColumns(tabletStart, tabletEnd); - LOGGER.info( - "Put {} values into list {}", tabletEnd - tabletStart, System.identityHashCode(tvList)); + tvList.markNotInsertedColumns(tvListPos, tvListPos + (tabletEnd - tabletStart)); } @Override @@ -1968,9 +1984,9 @@ } @Override - public void castTo(int colIndex, TSDataType newType) { + public void castTo(int colIndex, TSDataType newType, ArrayConvertor arrayConvertor) { synchronized (innerValue) { - innerValue.castTo(realIndexes.get(colIndex), newType); + innerValue.castTo(realIndexes.get(colIndex), newType, arrayConvertor); } }
diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/load/converter/LoadConvertedInsertTabletStatement.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/load/converter/LoadConvertedInsertTabletStatement.java index 0100533..22b2c9e 100644 --- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/load/converter/LoadConvertedInsertTabletStatement.java +++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/load/converter/LoadConvertedInsertTabletStatement.java
@@ -19,6 +19,7 @@ package org.apache.iotdb.db.storageengine.load.converter; +import org.apache.iotdb.db.pipe.receiver.transform.converter.ArrayConverter; import org.apache.iotdb.db.pipe.receiver.transform.statement.PipeConvertedInsertTabletStatement; import org.apache.iotdb.db.queryengine.plan.statement.crud.InsertTabletStatement; @@ -53,7 +54,7 @@ measurements[columnIndex], dataTypes[columnIndex], dataType); - columns.castTo(columnIndex, dataType); + columns.castTo(columnIndex, dataType, ArrayConverter::convert); dataTypes[columnIndex] = dataType; return true; }
diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/utils/datastructure/AlignedTVList.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/utils/datastructure/AlignedTVList.java index 060c05e..b23774e 100644 --- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/utils/datastructure/AlignedTVList.java +++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/utils/datastructure/AlignedTVList.java
@@ -899,7 +899,7 @@ results, tvListPos); } - markNotInsertedColumns(start, end); + markNotInsertedColumns(tvListPos, tvListPos + (end - start)); } @SuppressWarnings("squid:S3776") // Suppress high Cognitive Complexity warning