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 38831292ed [IOTDB-4503] fix load error when autoregister is 
false(#7426)
38831292ed is described below

commit 38831292ed9003e9f60782afe092bdef96b8b074
Author: yschengzi <[email protected]>
AuthorDate: Mon Sep 26 14:22:52 2022 +0800

    [IOTDB-4503] fix load error when autoregister is false(#7426)
---
 .../java/org/apache/iotdb/db/it/IOTDBLoadTsFileIT.java    |  3 ++-
 .../apache/iotdb/db/engine/storagegroup/DataRegion.java   |  6 +++---
 .../apache/iotdb/db/mpp/plan/analyze/AnalyzeVisitor.java  |  2 +-
 .../org/apache/iotdb/db/mpp/plan/parser/ASTVisitor.java   | 15 ++++++++++-----
 .../mpp/plan/scheduler/load/LoadTsFileDispatcherImpl.java |  2 +-
 .../db/mpp/plan/statement/crud/LoadTsFileStatement.java   |  7 ++++++-
 6 files changed, 23 insertions(+), 12 deletions(-)

diff --git 
a/integration-test/src/test/java/org/apache/iotdb/db/it/IOTDBLoadTsFileIT.java 
b/integration-test/src/test/java/org/apache/iotdb/db/it/IOTDBLoadTsFileIT.java
index d72e58eed7..8b07702e4a 100644
--- 
a/integration-test/src/test/java/org/apache/iotdb/db/it/IOTDBLoadTsFileIT.java
+++ 
b/integration-test/src/test/java/org/apache/iotdb/db/it/IOTDBLoadTsFileIT.java
@@ -200,7 +200,8 @@ public class IOTDBLoadTsFileIT {
     try (Connection connection = EnvFactory.getEnv().getConnection();
         Statement statement = connection.createStatement()) {
 
-      statement.execute(String.format("load \"%s\" sglevel=2", 
tmpDir.getAbsolutePath()));
+      statement.execute(
+          String.format("load \"%s\" sglevel=2, autoregister=false", 
tmpDir.getAbsolutePath()));
 
       try (ResultSet resultSet =
           statement.executeQuery("select count(*) from root.** group by 
level=1,2")) {
diff --git 
a/server/src/main/java/org/apache/iotdb/db/engine/storagegroup/DataRegion.java 
b/server/src/main/java/org/apache/iotdb/db/engine/storagegroup/DataRegion.java
index bf8286c9a9..59df2d878f 100755
--- 
a/server/src/main/java/org/apache/iotdb/db/engine/storagegroup/DataRegion.java
+++ 
b/server/src/main/java/org/apache/iotdb/db/engine/storagegroup/DataRegion.java
@@ -3073,7 +3073,7 @@ public class DataRegion {
       if (deleteOriginFile) {
         FileUtils.moveFile(tsFileToLoad, targetFile);
       } else {
-        Files.createLink(targetFile.toPath(), tsFileToLoad.toPath());
+        Files.copy(tsFileToLoad.toPath(), targetFile.toPath());
       }
     } catch (IOException e) {
       logger.error(
@@ -3095,7 +3095,7 @@ public class DataRegion {
       if (deleteOriginFile) {
         FileUtils.moveFile(resourceFileToLoad, targetResourceFile);
       } else {
-        Files.createLink(targetResourceFile.toPath(), 
resourceFileToLoad.toPath());
+        Files.copy(resourceFileToLoad.toPath(), targetResourceFile.toPath());
       }
     } catch (IOException e) {
       logger.error(
@@ -3127,7 +3127,7 @@ public class DataRegion {
         if (deleteOriginFile) {
           FileUtils.moveFile(modFileToLoad, targetModFile);
         } else {
-          Files.createLink(targetModFile.toPath(), modFileToLoad.toPath());
+          Files.copy(modFileToLoad.toPath(), targetModFile.toPath());
         }
       } catch (IOException e) {
         logger.error(
diff --git 
a/server/src/main/java/org/apache/iotdb/db/mpp/plan/analyze/AnalyzeVisitor.java 
b/server/src/main/java/org/apache/iotdb/db/mpp/plan/analyze/AnalyzeVisitor.java
index bdccefb5b1..7ae1cc083d 100644
--- 
a/server/src/main/java/org/apache/iotdb/db/mpp/plan/analyze/AnalyzeVisitor.java
+++ 
b/server/src/main/java/org/apache/iotdb/db/mpp/plan/analyze/AnalyzeVisitor.java
@@ -1477,7 +1477,7 @@ public class AnalyzeVisitor extends 
StatementVisitor<Analysis, MPPQueryContext>
     }
 
     // auto create and verify schema
-    if (loadTsFileStatement.isVerifySchema() || 
loadTsFileStatement.isAutoCreateSchema()) {
+    if (loadTsFileStatement.isAutoCreateSchema()) {
       try {
         if (loadTsFileStatement.isVerifySchema()) {
           verifyLoadingMeasurements(device2Schemas);
diff --git 
a/server/src/main/java/org/apache/iotdb/db/mpp/plan/parser/ASTVisitor.java 
b/server/src/main/java/org/apache/iotdb/db/mpp/plan/parser/ASTVisitor.java
index 7428a40500..fd3464f863 100644
--- a/server/src/main/java/org/apache/iotdb/db/mpp/plan/parser/ASTVisitor.java
+++ b/server/src/main/java/org/apache/iotdb/db/mpp/plan/parser/ASTVisitor.java
@@ -164,6 +164,7 @@ import 
org.apache.iotdb.tsfile.file.metadata.enums.TSEncoding;
 import org.apache.iotdb.tsfile.read.common.TimeRange;
 import org.apache.iotdb.tsfile.utils.Pair;
 
+import java.io.FileNotFoundException;
 import java.net.URI;
 import java.net.URISyntaxException;
 import java.time.ZoneId;
@@ -1443,12 +1444,16 @@ public class ASTVisitor extends 
IoTDBSqlParserBaseVisitor<Statement> {
 
   @Override
   public Statement visitLoadFile(IoTDBSqlParser.LoadFileContext ctx) {
-    LoadTsFileStatement loadTsFileStatement =
-        new LoadTsFileStatement(parseStringLiteral(ctx.fileName.getText()));
-    if (ctx.loadFilesClause() != null) {
-      parseLoadFiles(loadTsFileStatement, ctx.loadFilesClause());
+    try {
+      LoadTsFileStatement loadTsFileStatement =
+          new LoadTsFileStatement(parseStringLiteral(ctx.fileName.getText()));
+      if (ctx.loadFilesClause() != null) {
+        parseLoadFiles(loadTsFileStatement, ctx.loadFilesClause());
+      }
+      return loadTsFileStatement;
+    } catch (FileNotFoundException e) {
+      throw new SQLParserException(e.getMessage());
     }
-    return loadTsFileStatement;
   }
 
   /**
diff --git 
a/server/src/main/java/org/apache/iotdb/db/mpp/plan/scheduler/load/LoadTsFileDispatcherImpl.java
 
b/server/src/main/java/org/apache/iotdb/db/mpp/plan/scheduler/load/LoadTsFileDispatcherImpl.java
index 69733b2443..1b616f2a9b 100644
--- 
a/server/src/main/java/org/apache/iotdb/db/mpp/plan/scheduler/load/LoadTsFileDispatcherImpl.java
+++ 
b/server/src/main/java/org/apache/iotdb/db/mpp/plan/scheduler/load/LoadTsFileDispatcherImpl.java
@@ -162,7 +162,7 @@ public class LoadTsFileDispatcherImpl implements 
IFragInstanceDispatcher {
       try {
         StorageEngineV2.getInstance()
             .getDataRegion((DataRegionId) groupId)
-            .loadNewTsFile(((LoadSingleTsFileNode) 
planNode).getTsFileResource(), true);
+            .loadNewTsFile(((LoadSingleTsFileNode) 
planNode).getTsFileResource(), false);
       } catch (LoadFileException e) {
         logger.error(String.format("Load TsFile Node %s error.", planNode), e);
         TSStatus resultStatus = new TSStatus();
diff --git 
a/server/src/main/java/org/apache/iotdb/db/mpp/plan/statement/crud/LoadTsFileStatement.java
 
b/server/src/main/java/org/apache/iotdb/db/mpp/plan/statement/crud/LoadTsFileStatement.java
index f5cd7e90cf..2d788c16a6 100644
--- 
a/server/src/main/java/org/apache/iotdb/db/mpp/plan/statement/crud/LoadTsFileStatement.java
+++ 
b/server/src/main/java/org/apache/iotdb/db/mpp/plan/statement/crud/LoadTsFileStatement.java
@@ -28,6 +28,7 @@ import org.apache.iotdb.tsfile.common.constant.TsFileConstant;
 import org.apache.iotdb.tsfile.utils.FilePathUtils;
 
 import java.io.File;
+import java.io.FileNotFoundException;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.HashMap;
@@ -43,7 +44,7 @@ public class LoadTsFileStatement extends Statement {
   private List<File> tsFiles;
   private List<TsFileResource> resources;
 
-  public LoadTsFileStatement(String filePath) {
+  public LoadTsFileStatement(String filePath) throws FileNotFoundException {
     this.file = new File(filePath);
     this.autoCreateSchema = true;
     this.sgLevel = 
IoTDBDescriptor.getInstance().getConfig().getDefaultStorageGroupLevel();
@@ -54,6 +55,10 @@ public class LoadTsFileStatement extends Statement {
     if (file.isFile()) {
       tsFiles.add(file);
     } else {
+      if (file.listFiles() == null) {
+        throw new FileNotFoundException(
+            "Can not find %s on this machine, note that load can only handle 
files on this machine.");
+      }
       findAllTsFile(file);
     }
     sortTsFiles(tsFiles);

Reply via email to