jt2594838 commented on code in PR #18606:
URL: https://github.com/apache/iotdb/pull/18606#discussion_r3977856338


##########
example/session/src/main/java/org/apache/iotdb/DataMigrationExample.java:
##########
@@ -60,6 +64,21 @@ public class DataMigrationExample {
   // concurrent thread of loading timeseries data
   private static final int CONCURRENCY = 5;
 
+  private static final TypeService<ColumnValueGetter> 
COLUMN_VALUE_GETTER_SERVICE =
+      type ->
+          switch (type.getTypeEnum()) {
+            case BOOLEAN -> DataIterator::getBoolean;
+            case INT32 -> DataIterator::getInt;
+            case INT64, TIMESTAMP -> DataIterator::getLong;
+            case FLOAT -> DataIterator::getFloat;
+            case DOUBLE -> DataIterator::getDouble;
+            case TEXT, STRING -> DataIterator::getString;
+            case DATE, BLOB, OBJECT -> DataIterator::getObject;
+            case ROW, UNKNOWN, VECTOR ->

Review Comment:
   Migration column readers now use TypeService with explicit rejection of ROW, 
UNKNOWN and VECTOR. An unsupported type raises a localized 
UnSupportedDataTypeException and reaches the existing device-failure handler; 
the previous null-result/log-and-continue fallback is removed. The example and 
its reactor dependencies compile successfully.



##########
iotdb-client/cli/src/main/java/org/apache/iotdb/cli/AbstractCli.java:
##########
@@ -56,6 +59,38 @@
 
 public abstract class AbstractCli {
 
+  static String timestampPrecision = "ms";
+  static String timeFormat = RpcUtils.DEFAULT_TIME_FORMAT;
+
+  private static final TypeService<SqlValueGetter> SQL_VALUE_GETTER_SERVICE =
+      type ->
+          switch (type.getTypeEnum()) {
+            case BOOLEAN, INT32, INT64, FLOAT, DOUBLE, TEXT, STRING, OBJECT ->
+                (resultSet, columnIndex, zoneId) -> 
resultSet.getString(columnIndex);
+            case BLOB ->
+                (resultSet, columnIndex, zoneId) -> {
+                  byte[] value = resultSet.getBytes(columnIndex);
+                  return value == null ? null : 
BytesUtils.parseBlobByteArrayToString(value);
+                };
+            case DATE ->
+                (resultSet, columnIndex, zoneId) -> {
+                  int value = resultSet.getInt(columnIndex);
+                  return resultSet.wasNull() ? null : 
DateUtils.formatDate(value);
+                };
+            case TIMESTAMP ->
+                (resultSet, columnIndex, zoneId) -> {
+                  long value = resultSet.getLong(columnIndex);
+                  return resultSet.wasNull()
+                      ? null
+                      : RpcUtils.formatDatetime(timeFormat, 
timestampPrecision, value, zoneId);
+                };
+            case ROW, UNKNOWN, VECTOR ->

Review Comment:
   CLI value formatting now dispatches through TypeService with an exhaustive 
enum switch. ROW, UNKNOWN and VECTOR explicitly throw 
UnSupportedDataTypeException using the English/Chinese CLI message, so 
unsupported output types cannot silently become null. Supported 
DATE/TIMESTAMP/BLOB null handling and formatting are preserved. AbstractCliTest 
passes (6 tests).



##########
iotdb-client/cli/src/main/java/org/apache/iotdb/tool/data/AbstractDataTool.java:
##########
@@ -88,6 +91,35 @@
 
 public abstract class AbstractDataTool {
 
+  private static final TypeService<ValueParser> VALUE_PARSER_SERVICE =
+      type ->
+          switch (type.getTypeEnum()) {
+            case TEXT, STRING ->
+                value -> {
+                  if (value.startsWith("\"") && value.endsWith("\"")) {
+                    return value.substring(1, value.length() - 1);
+                  }
+                  return value;
+                };
+            case BOOLEAN ->
+                value ->
+                    !"true".equalsIgnoreCase(value) && 
!"false".equalsIgnoreCase(value)
+                        ? null
+                        : Boolean.parseBoolean(value);
+            case INT32 -> value -> Integer.parseInt(value);
+            case INT64, TIMESTAMP -> value -> Long.parseLong(value);
+            case FLOAT -> value -> Float.parseFloat(value);
+            case DOUBLE -> value -> Double.parseDouble(value);
+            case DATE -> value -> LocalDate.parse(value);
+            case BLOB ->
+                value -> new 
Binary(parseHexStringToByteArray(value.replaceFirst("0x", "")));
+            case OBJECT, ROW, UNKNOWN, VECTOR ->

Review Comment:
   Import value parsing now dispatches through TypeService. OBJECT, ROW, 
UNKNOWN and VECTOR are explicitly rejected using the localized unsupported-type 
exception; the default null-producing parser is removed. NumberFormatException 
handling still returns null for invalid numeric input. The CLI/tool test run 
passes all 9 tests.



##########
iotdb-client/jdbc/src/main/java/org/apache/iotdb/jdbc/IoTDBAbstractDatabaseMetadata.java:
##########
@@ -52,6 +56,25 @@
 public abstract class IoTDBAbstractDatabaseMetadata implements 
DatabaseMetaData {
 
   private static final Logger LOGGER = 
LoggerFactory.getLogger(IoTDBAbstractDatabaseMetadata.class);
+
+  private static final TypeService<ColumnValueWriter> 
COLUMN_VALUE_WRITER_SERVICE =
+      type ->
+          switch (type.getTypeEnum()) {
+            case TEXT, STRING, BLOB, OBJECT ->
+                (builder, value) ->
+                    builder.writeBinary(new Binary(value.toString(), 
TSFileConfig.STRING_CHARSET));
+            case FLOAT -> (builder, value) -> builder.writeFloat((float) 
value);
+            case INT32, DATE -> (builder, value) -> builder.writeInt((int) 
value);
+            case INT64, TIMESTAMP -> (builder, value) -> 
builder.writeLong((long) value);
+            case DOUBLE -> (builder, value) -> builder.writeDouble((double) 
value);
+            case BOOLEAN -> (builder, value) -> builder.writeBoolean((boolean) 
value);
+            case ROW, UNKNOWN, VECTOR ->

Review Comment:
   JDBC metadata column writing now dispatches through TypeService. ROW, 
UNKNOWN and VECTOR explicitly throw UnSupportedDataTypeException using matching 
English/Chinese message keys, replacing the logging-only default branch. 
IoTDBDatabaseMetadataTest passes all 5 tests, and both locale source reactor 
builds succeed.



##########
external-service-impl/rest/src/main/java/org/apache/iotdb/rest/protocol/utils/InsertRowDataUtils.java:
##########
@@ -31,6 +33,58 @@
 
 public class InsertRowDataUtils {
 
+  private static final TypeService<ValueConverter> VALUE_CONVERTER_SERVICE =
+      type ->
+          switch (type.getTypeEnum()) {
+            case BOOLEAN ->
+                (value, index, mismatchedInfo) -> {
+                  if (!(value instanceof Boolean)) {
+                    mismatchedInfo.put(index, value);
+                  }
+                  return value;
+                };
+            case INT32, DATE ->
+                (value, index, mismatchedInfo) -> {
+                  if (value instanceof Number number) {
+                    return number.intValue();
+                  }
+                  mismatchedInfo.put(index, value);
+                  return value;
+                };
+            case INT64, TIMESTAMP ->
+                (value, index, mismatchedInfo) -> {
+                  if (value instanceof Number number) {
+                    return number.longValue();
+                  }
+                  mismatchedInfo.put(index, value);
+                  return value;
+                };
+            case FLOAT ->
+                (value, index, mismatchedInfo) -> {
+                  if (value instanceof Number number) {
+                    return number.floatValue();
+                  }
+                  mismatchedInfo.put(index, value);
+                  return value;
+                };
+            case DOUBLE ->
+                (value, index, mismatchedInfo) -> {
+                  if (value instanceof Number number) {
+                    return number.doubleValue();
+                  }
+                  mismatchedInfo.put(index, value);
+                  return value;
+                };
+            case TEXT, BLOB, STRING ->
+                (value, index, mismatchedInfo) ->
+                    new 
Binary(value.toString().getBytes(StandardCharsets.UTF_8));
+            case OBJECT, ROW, UNKNOWN, VECTOR ->

Review Comment:
   REST row conversion now uses an exhaustive TypeService switch. OBJECT, ROW, 
UNKNOWN and VECTOR explicitly retain the existing IoTDBConnectionException 
behavior, and numeric converters use instanceof pattern variables while 
preserving mismatch reporting. All 19 REST tests pass.



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to