You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by ha...@apache.org on 2022/11/25 09:29:35 UTC
[iotdb] branch master updated: [IOTDB-5028] Using `show timeseries` to query the schema in import-csv (#8130)
This is an automated email from the ASF dual-hosted git repository.
haonan 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 9f12b58c0b [IOTDB-5028] Using `show timeseries` to query the schema in import-csv (#8130)
9f12b58c0b is described below
commit 9f12b58c0ba3a34541cb496371dea28915c52d71
Author: Xuan Ronaldo <xu...@qq.com>
AuthorDate: Fri Nov 25 17:29:30 2022 +0800
[IOTDB-5028] Using `show timeseries` to query the schema in import-csv (#8130)
---
.../main/java/org/apache/iotdb/tool/ImportCsv.java | 65 +++++++++++++---------
1 file changed, 40 insertions(+), 25 deletions(-)
diff --git a/cli/src/main/java/org/apache/iotdb/tool/ImportCsv.java b/cli/src/main/java/org/apache/iotdb/tool/ImportCsv.java
index 51ece1e394..71b14915a6 100644
--- a/cli/src/main/java/org/apache/iotdb/tool/ImportCsv.java
+++ b/cli/src/main/java/org/apache/iotdb/tool/ImportCsv.java
@@ -21,6 +21,7 @@ package org.apache.iotdb.tool;
import org.apache.iotdb.commons.exception.IllegalPathException;
import org.apache.iotdb.commons.utils.PathUtils;
+import org.apache.iotdb.db.mpp.common.header.ColumnHeaderConstant;
import org.apache.iotdb.db.qp.constant.SQLConstant;
import org.apache.iotdb.db.qp.utils.DateTimeUtils;
import org.apache.iotdb.exception.ArgsErrorException;
@@ -30,6 +31,8 @@ import org.apache.iotdb.session.Session;
import org.apache.iotdb.session.SessionDataSet;
import org.apache.iotdb.tsfile.common.constant.TsFileConstant;
import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
+import org.apache.iotdb.tsfile.read.common.Field;
+import org.apache.iotdb.tsfile.read.common.RowRecord;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.CommandLineParser;
@@ -436,10 +439,9 @@ public class ImportCsv extends AbstractCsvTool {
parseHeaders(headerNames, deviceAndMeasurementNames, headerTypeMap, headerNameMap);
Set<String> devices = deviceAndMeasurementNames.keySet();
- String devicesStr = StringUtils.join(devices, ",");
if (headerTypeMap.isEmpty()) {
try {
- queryType(devicesStr, headerTypeMap, "Time");
+ queryType(devices, headerTypeMap, "Time");
} catch (IoTDBConnectionException e) {
e.printStackTrace();
}
@@ -601,7 +603,15 @@ public class ImportCsv extends AbstractCsvTool {
if (!typeQueriedDevice.contains(deviceName.get())) {
try {
if (headerTypeMap.isEmpty()) {
- hasResult = queryType(deviceName.get(), headerTypeMap, "Device");
+ hasResult =
+ queryType(
+ new HashSet<String>() {
+ {
+ add(deviceName.get());
+ }
+ },
+ headerTypeMap,
+ "Device");
}
typeQueriedDevice.add(deviceName.get());
} catch (IoTDBConnectionException e) {
@@ -817,32 +827,37 @@ public class ImportCsv extends AbstractCsvTool {
* @throws StatementExecutionException
*/
private static boolean queryType(
- String deviceNames, HashMap<String, TSDataType> headerTypeMap, String alignedType)
+ Set<String> deviceNames, HashMap<String, TSDataType> headerTypeMap, String alignedType)
throws IoTDBConnectionException {
- String sql = "select * from " + deviceNames + " limit 1";
- SessionDataSet sessionDataSet = null;
- try {
- sessionDataSet = session.executeQueryStatement(sql);
- } catch (StatementExecutionException e) {
- System.out.println("Meet error when query the type of timeseries because " + e.getMessage());
- return false;
- }
- List<String> columnNames = sessionDataSet.getColumnNames();
- List<String> columnTypes = sessionDataSet.getColumnTypes();
- if (columnNames.size() == 1) {
- return false;
- } else {
- for (int i = 1; i < columnNames.size(); i++) {
- if (Objects.equals(alignedType, "Time")) {
- headerTypeMap.put(columnNames.get(i), getType(columnTypes.get(i)));
- } else if (Objects.equals(alignedType, "Device")) {
- String[] split = columnNames.get(i).split("\\.");
- String measurement = split[split.length - 1];
- headerTypeMap.put(measurement, getType(columnTypes.get(i)));
+ boolean hasResult = false;
+ for (String deviceName : deviceNames) {
+ String sql = "show timeseries " + deviceName + ".*";
+ SessionDataSet sessionDataSet = null;
+ try {
+ sessionDataSet = session.executeQueryStatement(sql);
+ int tsIndex = sessionDataSet.getColumnNames().indexOf(ColumnHeaderConstant.TIMESERIES);
+ int dtIndex = sessionDataSet.getColumnNames().indexOf(ColumnHeaderConstant.DATATYPE);
+ while (sessionDataSet.hasNext()) {
+ hasResult = true;
+ RowRecord record = sessionDataSet.next();
+ List<Field> fields = record.getFields();
+ String timeseries = fields.get(tsIndex).getStringValue();
+ String dataType = fields.get(dtIndex).getStringValue();
+ if (Objects.equals(alignedType, "Time")) {
+ headerTypeMap.put(timeseries, getType(dataType));
+ } else if (Objects.equals(alignedType, "Device")) {
+ String[] split = PathUtils.splitPathToDetachedNodes(timeseries);
+ String measurement = split[split.length - 1];
+ headerTypeMap.put(measurement, getType(dataType));
+ }
}
+ } catch (StatementExecutionException | IllegalPathException e) {
+ System.out.println(
+ "Meet error when query the type of timeseries because " + e.getMessage());
+ return false;
}
- return true;
}
+ return hasResult;
}
/**