IGNITE-7709: SQL COPY command: make sure file name is always quoted. This closes...
authorshq <kirill.shirokov@gmail.com>
Thu, 15 Feb 2018 10:36:00 +0000 (13:36 +0300)
committerdevozerov <vozerov@gridgain.com>
Thu, 15 Feb 2018 10:36:00 +0000 (13:36 +0300)
modules/core/src/main/java/org/apache/ignite/internal/sql/command/SqlBulkLoadCommand.java
modules/core/src/test/java/org/apache/ignite/internal/sql/SqlParserBulkLoadSelfTest.java

index e5246d5..4f065f2 100644 (file)
@@ -29,6 +29,7 @@ import java.util.ArrayList;
 import java.util.List;
 
 import static org.apache.ignite.internal.sql.SqlParserUtils.error;
+import static org.apache.ignite.internal.sql.SqlParserUtils.errorUnexpectedToken;
 import static org.apache.ignite.internal.sql.SqlParserUtils.parseIdentifier;
 import static org.apache.ignite.internal.sql.SqlParserUtils.parseInt;
 import static org.apache.ignite.internal.sql.SqlParserUtils.parseQualifiedIdentifier;
@@ -83,7 +84,12 @@ public class SqlBulkLoadCommand implements SqlCommand {
      * @param lex The lexer.
      */
     private void parseFileName(SqlLexer lex) {
-        locFileName = parseIdentifier(lex);
+        if (lex.lookAhead().tokenType() != SqlLexerTokenType.QUOTED)
+            throw errorUnexpectedToken(lex.lookAhead(), "[quoted file name]");
+
+        lex.shift();
+
+        locFileName = lex.token();
     }
 
     /**
index b5cd55b..ff09c73 100644 (file)
@@ -33,11 +33,31 @@ public class SqlParserBulkLoadSelfTest extends SqlParserAbstractSelfTest {
 
         assertParseError(null,
             "copy from into Person (_key, age, firstName, lastName) format csv",
-            "Unexpected token: \"INTO\" (expected: \"[identifier]\"");
+            "Unexpected token: \"INTO\" (expected: \"[quoted file name]\"");
 
         assertParseError(null,
-            "copy from any.file into Person (_key, age, firstName, lastName) format csv",
-            "Unexpected token: \".\" (expected: \"INTO\"");
+            "copy from unquoted into Person (_key, age, firstName, lastName) format csv",
+            "Unexpected token: \"UNQUOTED\" (expected: \"[quoted file name]\"");
+
+        assertParseError(null,
+            "copy from unquoted.file into Person (_key, age, firstName, lastName) format csv",
+            "Unexpected token: \"UNQUOTED\" (expected: \"[quoted file name]\"");
+
+        new SqlParser(null,
+            "copy from \"\" into Person (_key, age, firstName, lastName) format csv")
+            .nextCommand();
+
+        new SqlParser(null,
+            "copy from \"d:/copy/from/into/format.csv\" into Person (_key, age, firstName, lastName) format csv")
+            .nextCommand();
+
+        new SqlParser(null,
+            "copy from \"/into\" into Person (_key, age, firstName, lastName) format csv")
+            .nextCommand();
+
+        new SqlParser(null,
+            "copy from \"into\" into Person (_key, age, firstName, lastName) format csv")
+            .nextCommand();
 
         assertParseError(null,
             "copy from \"any.file\" to Person (_key, age, firstName, lastName) format csv",