You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@iotdb.apache.org by "2b3c511 (via GitHub)" <gi...@apache.org> on 2024/03/28 08:24:14 UTC

[PR] Add the import and export function of SQl files on the basis of CSV import and export scripts [iotdb]

2b3c511 opened a new pull request, #12248:
URL: https://github.com/apache/iotdb/pull/12248

   Add the import and export function of SQl files on the basis of CSV import and export scripts


-- 
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: reviews-unsubscribe@iotdb.apache.org

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


Re: [PR] Add the import and export function of SQl files on the basis of CSV import and export scripts [iotdb]

Posted by "CloudWise-Lukemiao (via GitHub)" <gi...@apache.org>.
CloudWise-Lukemiao commented on PR #12248:
URL: https://github.com/apache/iotdb/pull/12248#issuecomment-2026946649

   LGTM


-- 
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: reviews-unsubscribe@iotdb.apache.org

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


Re: [PR] Add the import and export function of SQl files on the basis of CSV import and export scripts [iotdb]

Posted by "HTHou (via GitHub)" <gi...@apache.org>.
HTHou merged PR #12248:
URL: https://github.com/apache/iotdb/pull/12248


-- 
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: reviews-unsubscribe@iotdb.apache.org

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


Re: [PR] Add the import and export function of SQl files on the basis of CSV import and export scripts [iotdb]

Posted by "CloudWise-Lukemiao (via GitHub)" <gi...@apache.org>.
CloudWise-Lukemiao commented on code in PR #12248:
URL: https://github.com/apache/iotdb/pull/12248#discussion_r1542666111


##########
iotdb-client/cli/src/main/java/org/apache/iotdb/tool/ImportCsv.java:
##########
@@ -442,6 +461,46 @@ private static void importFromSingleFile(File file) {
     }
   }
 
+  private static void importFromSqlFile(File file) {
+    try (BufferedReader br = new BufferedReader(new FileReader(file.getAbsolutePath()))) {
+      String line;
+      while ((line = br.readLine()) != null) {
+        executeSql(line);
+      }
+      ioTPrinter.println(file.getName() + " Import completely!");
+    } catch (IOException e) {
+      ioTPrinter.println("SQL file read exception because: " + e.getMessage());
+    }
+  }
+
+  private static void executeSql(String sql) {
+    try {
+      Statement statement = getConnection().createStatement();

Review Comment:
   After use, it needs to be closed



##########
iotdb-client/cli/src/main/java/org/apache/iotdb/tool/ExportCsv.java:
##########
@@ -337,31 +368,81 @@ private static void dumpFromSqlFile(String filePath) throws IOException {
    * @param index used to create dump file name
    */
   private static void dumpResult(String sql, int index) {
+    if (EXPORT_SQL_TYPE_NAME.equalsIgnoreCase(exportType)) {
+      legalCheck(sql);
+    }
     final String path = targetDirectory + targetFile + index;
     try {
       SessionDataSet sessionDataSet = session.executeQueryStatement(sql, timeout);
       List<Object> headers = new ArrayList<>();
       List<String> names = sessionDataSet.getColumnNames();
       List<String> types = sessionDataSet.getColumnTypes();
-      if (Boolean.TRUE.equals(needDataTypePrinted)) {
-        for (int i = 0; i < names.size(); i++) {
-          if (!"Time".equals(names.get(i)) && !"Device".equals(names.get(i))) {
-            headers.add(String.format("%s(%s)", names.get(i), types.get(i)));
-          } else {
-            headers.add(names.get(i));
+      if (EXPORT_SQL_TYPE_NAME.equalsIgnoreCase(exportType)) {
+        writeSqlFile(sessionDataSet, path, names, linesPerFile);
+      } else {
+        if (Boolean.TRUE.equals(needDataTypePrinted)) {
+          for (int i = 0; i < names.size(); i++) {
+            if (!"Time".equals(names.get(i)) && !"Device".equals(names.get(i))) {
+              headers.add(String.format("%s(%s)", names.get(i), types.get(i)));
+            } else {
+              headers.add(names.get(i));
+            }
           }
+        } else {
+          headers.addAll(names);
         }
-      } else {
-        headers.addAll(names);
+        writeCsvFile(sessionDataSet, path, headers, linesPerFile);
       }
-      writeCsvFile(sessionDataSet, path, headers, linesPerFile);
       sessionDataSet.closeOperationHandle();
       ioTPrinter.println("Export completely!");
     } catch (StatementExecutionException | IoTDBConnectionException | IOException e) {
       ioTPrinter.println("Cannot dump result because: " + e.getMessage());
     }
   }
 
+  private static void legalCheck(String sql) {
+    String sqlLower = sql.toLowerCase();
+    if (sqlLower.contains("count(")

Review Comment:
   Please use regular expressions to determine incomplete coverage by including strings, such as count (*), where there are one or more spaces after count。eg: `  public static boolean hasAggregateFunction(String sqlQuery) {
           String aggregatePattern = "\\b(COUNT|SUM|AVG|MIN|MAX)\\b\\s*\\(";
           Pattern pattern = Pattern.compile(aggregatePattern, Pattern.CASE_INSENSITIVE);
           Matcher matcher = pattern.matcher(sqlQuery.toUpperCase(Locale.ROOT));
           return matcher.find();
       }`



-- 
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: reviews-unsubscribe@iotdb.apache.org

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