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 e6e37ccf365 update session source when have no permission in 
ExportSchemaTable (#15355)
e6e37ccf365 is described below

commit e6e37ccf365152eadbe6473515a46f4cc035399b
Author: Summer <[email protected]>
AuthorDate: Fri Apr 18 11:41:54 2025 +0800

    update session source when have no permission in ExportSchemaTable (#15355)
    
    Co-authored-by: 2b3c511 <[email protected]>
---
 .../apache/iotdb/tool/schema/ExportSchemaTable.java   | 19 ++++++++++---------
 1 file changed, 10 insertions(+), 9 deletions(-)

diff --git 
a/iotdb-client/cli/src/main/java/org/apache/iotdb/tool/schema/ExportSchemaTable.java
 
b/iotdb-client/cli/src/main/java/org/apache/iotdb/tool/schema/ExportSchemaTable.java
index 8644dac5adf..e80bdeac82e 100644
--- 
a/iotdb-client/cli/src/main/java/org/apache/iotdb/tool/schema/ExportSchemaTable.java
+++ 
b/iotdb-client/cli/src/main/java/org/apache/iotdb/tool/schema/ExportSchemaTable.java
@@ -132,7 +132,7 @@ public class ExportSchemaTable extends AbstractExportSchema 
{
     }
     if (StringUtils.isNotBlank(table)) {
       if (!tables.containsKey(table)) {
-        ioTPrinter.println(String.format(Constants.TARGET_TABLE_NOT_EXIST_MSG, 
database));
+        ioTPrinter.println(Constants.TARGET_TABLE_EMPTY_MSG);
         System.exit(1);
       }
       tableCommentList.put(table, tables.get(table));
@@ -164,12 +164,13 @@ public class ExportSchemaTable extends 
AbstractExportSchema {
         }
       }
     }
-    if (MapUtils.isNotEmpty(tables)) {
+    if (StringUtils.isNotBlank(table)) {
       if (!tables.containsKey(table)) {
-        ioTPrinter.println(String.format(Constants.TARGET_TABLE_NOT_EXIST_MSG, 
database));
+        ioTPrinter.println(Constants.TARGET_TABLE_EMPTY_MSG);
         System.exit(1);
+      } else {
+        tableCommentList.put(table, tables.get(table));
       }
-      tableCommentList.put(table, tables.get(table));
     } else {
       tableCommentList.putAll(tables);
     }
@@ -193,7 +194,7 @@ public class ExportSchemaTable extends AbstractExportSchema 
{
                 String.format(Constants.EXPORT_SCHEMA_COLUMNS_SELECT, 
database, tableName));
         exportSchemaBySelect(sessionDataSet, fileName, tableName, comment);
       } catch (IoTDBConnectionException | StatementExecutionException | 
IOException e) {
-        try {
+        try (ITableSession session = sessionPool.getSession()) {
           sessionDataSet =
               session.executeQueryStatement(
                   String.format(Constants.EXPORT_SCHEMA_COLUMNS_DESC, 
database, tableName));
@@ -219,7 +220,7 @@ public class ExportSchemaTable extends AbstractExportSchema 
{
     String dropSql = "DROP TABLE IF EXISTS " + tableName + ";\n";
     StringBuilder sb = new StringBuilder(dropSql);
     sb.append("CREATE TABLE " + tableName + "(\n");
-    try (FileWriter writer = new FileWriter(fileName)) {
+    try (FileWriter writer = new FileWriter(fileName, true)) {
       boolean hasNext = sessionDataSet.hasNext();
       while (hasNext) {
         RowRecord rowRecord = sessionDataSet.next();
@@ -239,12 +240,12 @@ public class ExportSchemaTable extends 
AbstractExportSchema {
         }
         sb.append("\n");
       }
-      sb.append("\n)");
+      sb.append(")");
       if (StringUtils.isNotBlank(tableComment)) {
-        sb.append(" COMMENT '" + tableComment + "'\n");
+        sb.append(" COMMENT '" + tableComment + "'");
       }
       sb.append(";\n");
-      writer.write(sb.toString());
+      writer.append(sb.toString());
       writer.flush();
     }
   }

Reply via email to