This is an automated email from the ASF dual-hosted git repository.
critas pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/iotdb.git
The following commit(s) were added to refs/heads/master by this push:
new 699487f7f12 Adapt TIMESTAMP type when import data (#15378)
699487f7f12 is described below
commit 699487f7f12e9d84b794a087740ff6a4d4982fa7
Author: Summer <[email protected]>
AuthorDate: Tue Apr 22 17:48:27 2025 +0800
Adapt TIMESTAMP type when import data (#15378)
* adapt TIMESTAMP type when import data
* adapte schema type when timeseries created
* adapte schema type when timeseries created
---------
Co-authored-by: 2b3c511 <[email protected]>
---
.../apache/iotdb/tool/data/AbstractDataTool.java | 12 +++++
.../org/apache/iotdb/tool/data/ImportDataTree.java | 57 ++++++++++++++++------
2 files changed, 53 insertions(+), 16 deletions(-)
diff --git
a/iotdb-client/cli/src/main/java/org/apache/iotdb/tool/data/AbstractDataTool.java
b/iotdb-client/cli/src/main/java/org/apache/iotdb/tool/data/AbstractDataTool.java
index eeaf5a542b0..35f28bec05c 100644
---
a/iotdb-client/cli/src/main/java/org/apache/iotdb/tool/data/AbstractDataTool.java
+++
b/iotdb-client/cli/src/main/java/org/apache/iotdb/tool/data/AbstractDataTool.java
@@ -301,6 +301,8 @@ public abstract class AbstractDataTool {
}
if (isBoolean(strValue)) {
return Constants.TYPE_INFER_KEY_DICT.get(Constants.DATATYPE_BOOLEAN);
+ } else if (isTimeStamp(strValue)) {
+ return Constants.TYPE_INFER_KEY_DICT.get(Constants.DATATYPE_TIMESTAMP);
} else if (isNumber(strValue)) {
if (!strValue.contains(TsFileConstant.PATH_SEPARATOR)) {
if (isConvertFloatPrecisionLack(StringUtils.trim(strValue))) {
@@ -316,6 +318,8 @@ public abstract class AbstractDataTool {
// "NaN" is returned if the NaN Literal is given in Parser
} else if (Constants.DATATYPE_NAN.equals(strValue)) {
return Constants.TYPE_INFER_KEY_DICT.get(Constants.DATATYPE_NAN);
+ } else if (isDate(strValue)) {
+ return Constants.TYPE_INFER_KEY_DICT.get(Constants.DATATYPE_DATE);
} else if (isBlob(strValue)) {
return Constants.TYPE_INFER_KEY_DICT.get(Constants.DATATYPE_BLOB);
} else if (strValue.length() <= 512) {
@@ -325,6 +329,14 @@ public abstract class AbstractDataTool {
}
}
+ private static boolean isDate(String s) {
+ return s.equalsIgnoreCase(Constants.DATATYPE_DATE);
+ }
+
+ private static boolean isTimeStamp(String s) {
+ return s.equalsIgnoreCase(Constants.DATATYPE_TIMESTAMP);
+ }
+
static boolean isNumber(String s) {
if (s == null || s.equals(Constants.DATATYPE_NAN)) {
return false;
diff --git
a/iotdb-client/cli/src/main/java/org/apache/iotdb/tool/data/ImportDataTree.java
b/iotdb-client/cli/src/main/java/org/apache/iotdb/tool/data/ImportDataTree.java
index e61016ae13c..ec673f5ff27 100644
---
a/iotdb-client/cli/src/main/java/org/apache/iotdb/tool/data/ImportDataTree.java
+++
b/iotdb-client/cli/src/main/java/org/apache/iotdb/tool/data/ImportDataTree.java
@@ -228,14 +228,17 @@ public class ImportDataTree extends AbstractImportData {
if (!"".equals(value)) {
TSDataType type;
if (!headerTypeMap.containsKey(header)) {
- type = typeInfer(value);
- if (type != null) {
- headerTypeMap.put(header, type);
- } else {
- ioTPrinter.printf(
- "Line '%s', column '%s': '%s' unknown type%n",
- recordObj.getRecordNumber(), header, value);
- isFail = true;
+ queryType(header, headerTypeMap);
+ if (!headerTypeMap.containsKey(header)) {
+ type = typeInfer(value);
+ if (type != null) {
+ headerTypeMap.put(header, type);
+ } else {
+ ioTPrinter.printf(
+ "Line '%s', column '%s': '%s' unknown type%n",
+ recordObj.getRecordNumber(), header, value);
+ isFail = true;
+ }
}
}
type = headerTypeMap.get(header);
@@ -340,14 +343,16 @@ public class ImportDataTree extends AbstractImportData {
}
typeQueriedDevice.add(deviceName.get());
}
- type = typeInfer(value);
- if (type != null) {
- headerTypeMap.put(headerNameWithoutType, type);
- } else {
- ioTPrinter.printf(
- "Line '%s', column '%s': '%s' unknown type%n",
- recordObj.getRecordNumber(), headerNameWithoutType,
value);
- isFail.set(true);
+ if (!headerTypeMap.containsKey(headerNameWithoutType)) {
+ type = typeInfer(value);
+ if (type != null) {
+ headerTypeMap.put(headerNameWithoutType, type);
+ } else {
+ ioTPrinter.printf(
+ "Line '%s', column '%s': '%s' unknown type%n",
+ recordObj.getRecordNumber(), headerNameWithoutType,
value);
+ isFail.set(true);
+ }
}
}
type = headerTypeMap.get(headerNameWithoutType);
@@ -473,4 +478,24 @@ public class ImportDataTree extends AbstractImportData {
}
}
}
+
+ private static void queryType(String series, HashMap<String, TSDataType>
headerTypeMap) {
+ String sql = "show timeseries " + series;
+ try (SessionDataSetWrapper sessionDataSetWrapper =
sessionPool.executeQueryStatement(sql)) {
+ int tsIndex =
sessionDataSetWrapper.getColumnNames().indexOf(ColumnHeaderConstant.TIMESERIES);
+ int dtIndex =
sessionDataSetWrapper.getColumnNames().indexOf(ColumnHeaderConstant.DATATYPE);
+ while (sessionDataSetWrapper.hasNext()) {
+ RowRecord rowRecord = sessionDataSetWrapper.next();
+ List<Field> fields = rowRecord.getFields();
+ String timeseries = fields.get(tsIndex).getStringValue();
+ String dataType = fields.get(dtIndex).getStringValue();
+ if (Objects.equals(series, timeseries)) {
+ headerTypeMap.put(timeseries, getType(dataType));
+ }
+ }
+ } catch (StatementExecutionException | IoTDBConnectionException e) {
+ ioTPrinter.println("Meet error when query the type of timeseries because
" + e.getMessage());
+ System.exit(1);
+ }
+ }
}