Copilot commented on code in PR #16252:
URL: https://github.com/apache/iotdb/pull/16252#discussion_r2297586785


##########
iotdb-client/cli/src/main/java/org/apache/iotdb/tool/data/ExportDataTable.java:
##########
@@ -233,44 +248,49 @@ private Boolean exportToTsFile(SessionDataSet 
sessionDataSet, String filePath, S
 
   private void exportToCsvFile(SessionDataSet sessionDataSet, String filePath)
       throws IOException, IoTDBConnectionException, 
StatementExecutionException {
+    processedRows = 0;
+    lastPrintTime = 0;
     List<String> headers = sessionDataSet.getColumnNames();
     int fileIndex = 0;
-    boolean hasNext = sessionDataSet.hasNext();
-    while (hasNext) {
+    SessionDataSet.DataIterator iterator = sessionDataSet.iterator();
+    List<String> columnTypeList = iterator.getColumnTypeList();
+    int totalColumns = columnTypeList.size();
+    boolean fromOuterloop = false;
+    while (iterator.next()) {
       final String finalFilePath = filePath + "_" + fileIndex + ".csv";
       final CSVPrinterWrapper csvPrinterWrapper = new 
CSVPrinterWrapper(finalFilePath);
       csvPrinterWrapper.printRecord(headers);
-      int i = 0;
-      while (i++ < linesPerFile) {
-        RowRecord rowRecord = sessionDataSet.next();
-        rowRecord
-            .getFields()
-            .forEach(
-                field -> {
-                  String fieldStringValue = field.getStringValue();
-                  if (!"null".equals(field.getStringValue())) {
-                    if ((field.getDataType() == TSDataType.TEXT
-                        || field.getDataType() == TSDataType.STRING)) {
-                      fieldStringValue = "\"" + fieldStringValue + "\"";
-                    } else if (field.getDataType() == TSDataType.TIMESTAMP) {
-                      fieldStringValue = timeTrans(field.getLongV());
-                    }
-                    csvPrinterWrapper.print(fieldStringValue);
-                  } else {
-                    csvPrinterWrapper.print("");
-                  }
-                });
+      fromOuterloop = true;
+      int countLine = 0;
+      while (countLine++ < linesPerFile && (fromOuterloop || iterator.next())) 
{
+        fromOuterloop = false;
+        for (int curColumnIndex = 0; curColumnIndex < totalColumns; 
curColumnIndex++) {
+          String columnValue = iterator.getString(curColumnIndex + 1);
+          if (columnValue.equals("null")) {
+            csvPrinterWrapper.print("");
+          } else {
+            String curType = columnTypeList.get(curColumnIndex);
+            if (curType.equalsIgnoreCase("TEXT") || 
curType.equalsIgnoreCase("STRING")) {
+              csvPrinterWrapper.print("\"" + columnValue + "\"");
+            } else if (curType.equalsIgnoreCase("TIMESTAMP")) {
+              
csvPrinterWrapper.print(timeTrans(iterator.getLong(curColumnIndex + 1)));

Review Comment:
   The method calls iterator.getLong() but the column type check uses 
iterator.getString(). This inconsistency could cause type conversion errors 
when the column value is not actually a long.
   ```suggestion
             String curType = columnTypeList.get(curColumnIndex);
             if (curType.equalsIgnoreCase("TIMESTAMP")) {
               long timestampValue = iterator.getLong(curColumnIndex + 1);
               csvPrinterWrapper.print(timeTrans(timestampValue));
             } else {
               String columnValue = iterator.getString(curColumnIndex + 1);
               if (columnValue.equals("null")) {
                 csvPrinterWrapper.print("");
               } else if (curType.equalsIgnoreCase("TEXT") || 
curType.equalsIgnoreCase("STRING")) {
                 csvPrinterWrapper.print("\"" + columnValue + "\"");
   ```



-- 
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