You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by GitBox <gi...@apache.org> on 2022/04/20 02:47:04 UTC

[GitHub] [flink] luoyuxia opened a new pull request, #19520: [FLINK-26366][hive] support insert overwrite directory

luoyuxia opened a new pull request, #19520:
URL: https://github.com/apache/flink/pull/19520

   <!--
   *Thank you very much for contributing to Apache Flink - we are happy that you want to help us improve Flink. To help the community review your contribution in the best possible way, please go through the checklist below, which will get the contribution into a shape in which it can be best reviewed.*
   
   *Please understand that we do not do this to make contributions to Flink a hassle. In order to uphold a high standard of quality for code contributions, while at the same time managing a large number of contributions, we need contributors to prepare the contributions well, and give reviewers enough contextual information for the review. Please also understand that contributions that do not follow this guide will take longer to review and thus typically be picked up with lower priority by the community.*
   
   ## Contribution Checklist
   
     - Make sure that the pull request corresponds to a [JIRA issue](https://issues.apache.org/jira/projects/FLINK/issues). Exceptions are made for typos in JavaDoc or documentation files, which need no JIRA issue.
     
     - Name the pull request in the form "[FLINK-XXXX] [component] Title of the pull request", where *FLINK-XXXX* should be replaced by the actual issue number. Skip *component* if you are unsure about which is the best component.
     Typo fixes that have no associated JIRA issue should be named following this pattern: `[hotfix] [docs] Fix typo in event time introduction` or `[hotfix] [javadocs] Expand JavaDoc for PuncuatedWatermarkGenerator`.
   
     - Fill out the template below to describe the changes contributed by the pull request. That will give reviewers the context they need to do the review.
     
     - Make sure that the change passes the automated tests, i.e., `mvn clean verify` passes. You can set up Azure Pipelines CI to do that following [this guide](https://cwiki.apache.org/confluence/display/FLINK/Azure+Pipelines#AzurePipelines-Tutorial:SettingupAzurePipelinesforaforkoftheFlinkrepository).
   
     - Each pull request should address only one issue, not mix up code from multiple issues.
     
     - Each commit in the pull request has a meaningful commit message (including the JIRA id)
   
     - Once all items of the checklist are addressed, remove the above text and this checklist, leaving only the filled out template below.
   
   
   **(The sections below can be removed for hotfixes of typos)**
   -->
   
   ## What is the purpose of the change
   
   *(For example: This pull request makes task deployment go through the blob server, rather than through RPC. That way we avoid re-transferring them on each deployment (during recovery).)*
   
   
   ## Brief change log
   
   *(for example:)*
     - *The TaskInfo is stored in the blob store on job creation time as a persistent artifact*
     - *Deployments RPC transmits only the blob storage reference*
     - *TaskManagers retrieve the TaskInfo from the blob cache*
   
   
   ## Verifying this change
   
   Please make sure both new and modified tests in this PR follows the conventions defined in our code quality guide: https://flink.apache.org/contributing/code-style-and-quality-common.html#testing
   
   *(Please pick either of the following options)*
   
   This change is a trivial rework / code cleanup without any test coverage.
   
   *(or)*
   
   This change is already covered by existing tests, such as *(please describe tests)*.
   
   *(or)*
   
   This change added tests and can be verified as follows:
   
   *(example:)*
     - *Added integration tests for end-to-end deployment with large payloads (100MB)*
     - *Extended integration test for recovery after master (JobManager) failure*
     - *Added test that validates that TaskInfo is transferred only once across recoveries*
     - *Manually verified the change by running a 4 node cluster with 2 JobManagers and 4 TaskManagers, a stateful streaming program, and killing one JobManager and two TaskManagers during the execution, verifying that recovery happens correctly.*
   
   ## Does this pull request potentially affect one of the following parts:
   
     - Dependencies (does it add or upgrade a dependency): (yes / no)
     - The public API, i.e., is any changed class annotated with `@Public(Evolving)`: (yes / no)
     - The serializers: (yes / no / don't know)
     - The runtime per-record code paths (performance sensitive): (yes / no / don't know)
     - Anything that affects deployment or recovery: JobManager (and its components), Checkpointing, Kubernetes/Yarn, ZooKeeper: (yes / no / don't know)
     - The S3 file system connector: (yes / no / don't know)
   
   ## Documentation
   
     - Does this pull request introduce a new feature? (yes / no)
     - If yes, how is the feature documented? (not applicable / docs / JavaDocs / not documented)
   


-- 
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: issues-unsubscribe@flink.apache.org

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


[GitHub] [flink] luoyuxia commented on a diff in pull request #19520: [FLINK-26366][hive] support insert overwrite directory

Posted by GitBox <gi...@apache.org>.
luoyuxia commented on code in PR #19520:
URL: https://github.com/apache/flink/pull/19520#discussion_r892187726


##########
flink-connectors/flink-connector-hive/src/main/java/org/apache/flink/table/planner/delegation/hive/HiveParserDMLHelper.java:
##########
@@ -285,6 +305,81 @@ public Operation createInsertOperation(HiveParserCalcitePlanner analyzer, RelNod
                 Collections.emptyMap());
     }
 
+    private SinkModifyOperation createInsertIntoDirectoryOperation(
+            HiveParserQB topQB, QBMetaData qbMetaData, RelNode queryRelNode, HiveConf hiveConf) {
+        String dest = topQB.getParseInfo().getClauseNamesForDest().iterator().next();
+        // get the location for insert into directory
+        String location = qbMetaData.getDestFileForAlias(dest);
+        // get whether it's for insert local directory
+        boolean isToLocal = qbMetaData.getDestTypeForAlias(dest) == QBMetaData.DEST_LOCAL_FILE;
+        HiveParserDirectoryDesc directoryDesc = topQB.getDirectoryDesc();
+
+        // set row format / stored as / location
+        Map<String, String> props = new HashMap<>();
+        HiveParserDDLSemanticAnalyzer.encodeRowFormat(directoryDesc.getRowFormatParams(), props);
+        HiveParserDDLSemanticAnalyzer.encodeStorageFormat(directoryDesc.getStorageFormat(), props);
+        props.put(TABLE_LOCATION_URI, location);
+
+        props.put(FactoryUtil.CONNECTOR.key(), HiveCatalogFactoryOptions.IDENTIFIER);
+        // mark it's for insert into directory
+        props.put(CatalogPropertiesUtil.FLINK_PROPERTY_PREFIX + IS_INSERT_DIRECTORY, "true");
+        // mark it's for insert into local directory or not
+        props.put(
+                CatalogPropertiesUtil.FLINK_PROPERTY_PREFIX + IS_TO_LOCAL_DIRECTORY,
+                String.valueOf(isToLocal));
+
+        List<RelDataTypeField> fieldList = queryRelNode.getRowType().getFieldList();
+        String[] colNameArr = new String[fieldList.size()];
+        String[] colTypeArr = new String[fieldList.size()];
+        for (int i = 0; i < fieldList.size(); i++) {
+            colNameArr[i] = fieldList.get(i).getName();
+            TypeInfo typeInfo = HiveParserTypeConverter.convert(fieldList.get(i).getType());
+            if (typeInfo.equals(TypeInfoFactory.voidTypeInfo)) {
+                colTypeArr[i] = TypeInfoFactory.stringTypeInfo.getTypeName();
+            } else {
+                colTypeArr[i] = typeInfo.getTypeName();
+            }
+        }
+
+        String colNames = String.join(",", colNameArr);
+        String colTypes = String.join(":", colTypeArr);
+        props.put("columns", colNames);
+        props.put("columns.types", colTypes);
+
+        PlannerQueryOperation plannerQueryOperation = new PlannerQueryOperation(queryRelNode);
+        return new SinkModifyOperation(
+                createDummyTableForInsertDirectory(
+                        plannerQueryOperation.getResolvedSchema(), props),
+                new PlannerQueryOperation(queryRelNode),
+                Collections.emptyMap(),
+                true, // insert into directory is always for overwrite
+                Collections.emptyMap());
+    }
+
+    private ContextResolvedTable createDummyTableForInsertDirectory(
+            ResolvedSchema resolvedSchema, Map<String, String> props) {
+        Schema.Builder schemaBuilder = Schema.newBuilder();
+        for (Column column : resolvedSchema.getColumns()) {
+            schemaBuilder.column(column.getName(), column.getDataType());
+        }
+        CatalogTable catalogTable =
+                CatalogTable.of(
+                        schemaBuilder.build(),
+                        "a dummy table for the case of insert into directory ",
+                        Collections.emptyList(),
+                        props);
+        ResolvedCatalogTable resolvedCatalogTable =
+                new ResolvedCatalogTable(catalogTable, resolvedSchema);
+        String currentCatalog = catalogManager.getCurrentCatalog();
+        // the object name means nothing, it's just for placeholder and won't be used actually
+        String objectName = "insert_directory_tbl";

Review Comment:
   There's no conflict here for we will never create the table. It's just a placeholder



-- 
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: issues-unsubscribe@flink.apache.org

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


[GitHub] [flink] wuchong closed pull request #19520: [FLINK-26366][hive] support insert overwrite directory

Posted by GitBox <gi...@apache.org>.
wuchong closed pull request #19520: [FLINK-26366][hive] support insert overwrite directory
URL: https://github.com/apache/flink/pull/19520


-- 
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: issues-unsubscribe@flink.apache.org

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


[GitHub] [flink] luoyuxia commented on pull request #19520: [FLINK-26366][hive] support insert overwrite directory

Posted by GitBox <gi...@apache.org>.
luoyuxia commented on PR #19520:
URL: https://github.com/apache/flink/pull/19520#issuecomment-1149812872

   @lsyldliu Thanks for review. Addressed the comments now.


-- 
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: issues-unsubscribe@flink.apache.org

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


[GitHub] [flink] luoyuxia commented on a diff in pull request #19520: [FLINK-26366][hive] support insert overwrite directory

Posted by GitBox <gi...@apache.org>.
luoyuxia commented on code in PR #19520:
URL: https://github.com/apache/flink/pull/19520#discussion_r892237434


##########
flink-connectors/flink-connector-hive/src/test/java/org/apache/flink/connectors/hive/HiveDialectQueryITCase.java:
##########
@@ -330,6 +333,59 @@ public void testJoinInvolvingComplexType() throws Exception {
         }
     }
 
+    @Test
+    public void testInsertDirectory() throws Exception {
+        String warehouse = hiveCatalog.getHiveConf().getVar(HiveConf.ConfVars.METASTOREWAREHOUSE);
+
+        // test insert overwrite directory with row format parameters
+        tableEnv.executeSql("create table map_table (foo STRING , bar MAP<STRING, INT>)");
+        tableEnv.executeSql(
+                "insert into map_table select 'A', map('math',100,'english',90,'history',85)");
+
+        String dataDir = warehouse + "/map_table_dir";

Review Comment:
   The `warehouse` directory will always be a random directory in each run, so I think it's no need to add an UUID suffix again.



-- 
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: issues-unsubscribe@flink.apache.org

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


[GitHub] [flink] lsyldliu commented on a diff in pull request #19520: [FLINK-26366][hive] support insert overwrite directory

Posted by GitBox <gi...@apache.org>.
lsyldliu commented on code in PR #19520:
URL: https://github.com/apache/flink/pull/19520#discussion_r890798373


##########
flink-connectors/flink-connector-hive/src/test/java/org/apache/flink/connectors/hive/HiveDialectQueryITCase.java:
##########
@@ -330,6 +333,59 @@ public void testJoinInvolvingComplexType() throws Exception {
         }
     }
 
+    @Test
+    public void testInsertDirectory() throws Exception {

Review Comment:
   We should also test insert overwrite local directory?



##########
flink-connectors/flink-connector-hive/src/test/java/org/apache/flink/connectors/hive/HiveDialectQueryITCase.java:
##########
@@ -330,6 +333,59 @@ public void testJoinInvolvingComplexType() throws Exception {
         }
     }
 
+    @Test
+    public void testInsertDirectory() throws Exception {
+        String warehouse = hiveCatalog.getHiveConf().getVar(HiveConf.ConfVars.METASTOREWAREHOUSE);
+
+        // test insert overwrite directory with row format parameters
+        tableEnv.executeSql("create table map_table (foo STRING , bar MAP<STRING, INT>)");
+        tableEnv.executeSql(
+                "insert into map_table select 'A', map('math',100,'english',90,'history',85)");
+
+        String dataDir = warehouse + "/map_table_dir";
+        tableEnv.executeSql(
+                        String.format(
+                                "INSERT OVERWRITE DIRECTORY '%s'"
+                                        + "ROW FORMAT DELIMITED \n"
+                                        + "FIELDS TERMINATED BY ':'\n"
+                                        + "COLLECTION ITEMS TERMINATED BY '#' \n"
+                                        + "MAP KEYS TERMINATED BY '=' select * from map_table",
+                                dataDir))
+                .await();
+        java.nio.file.Path[] files =
+                FileUtils.listFilesInDirectory(
+                                Paths.get(dataDir), (path) -> !path.toFile().isHidden())
+                        .toArray(new Path[0]);
+        assertEquals(1, files.length);
+        String actualString = FileUtils.readFileUtf8(files[0].toFile());

Review Comment:
   Why here doesn't through a external table and read it?



##########
flink-connectors/flink-connector-hive/src/main/java/org/apache/flink/table/planner/delegation/hive/copy/HiveParserSemanticAnalyzer.java:
##########
@@ -1792,61 +1791,42 @@ private void getMetaData(HiveParserQB qb, ReadEntity parentInput) throws HiveExc
                             }
                         }
 
-                        boolean isDfsFile = true;
-                        if (ast.getChildCount() >= 2
-                                && ast.getChild(1).getText().toLowerCase().equals("local")) {
-                            isDfsFile = false;
-                        }
+                        boolean isDfsFile =
+                                ast.getChildCount() < 2

Review Comment:
   I can't understand this judge logic, can you help explain it?



##########
flink-connectors/flink-connector-hive/src/main/java/org/apache/flink/table/planner/delegation/hive/copy/HiveParserSemanticAnalyzer.java:
##########
@@ -1792,61 +1791,42 @@ private void getMetaData(HiveParserQB qb, ReadEntity parentInput) throws HiveExc
                             }
                         }
 
-                        boolean isDfsFile = true;
-                        if (ast.getChildCount() >= 2
-                                && ast.getChild(1).getText().toLowerCase().equals("local")) {
-                            isDfsFile = false;
-                        }
+                        boolean isDfsFile =
+                                ast.getChildCount() < 2
+                                        || !ast.getChild(1).getText().equalsIgnoreCase("local");
                         // Set the destination for the SELECT query inside the CTAS
                         qb.getMetaData().setDestForAlias(name, fname, isDfsFile);
 
-                        CreateTableDesc directoryDesc = new CreateTableDesc();
-                        boolean directoryDescIsSet = false;
+                        HiveParserDirectoryDesc directoryDesc =

Review Comment:
   Add some annotation about why use HiveParserDirectoryDesc instead of CreateTableDesc



##########
flink-connectors/flink-connector-hive/src/main/java/org/apache/flink/table/planner/delegation/hive/HiveParserDMLHelper.java:
##########
@@ -285,6 +305,81 @@ public Operation createInsertOperation(HiveParserCalcitePlanner analyzer, RelNod
                 Collections.emptyMap());
     }
 
+    private SinkModifyOperation createInsertIntoDirectoryOperation(
+            HiveParserQB topQB, QBMetaData qbMetaData, RelNode queryRelNode, HiveConf hiveConf) {
+        String dest = topQB.getParseInfo().getClauseNamesForDest().iterator().next();
+        // get the location for insert into directory
+        String location = qbMetaData.getDestFileForAlias(dest);
+        // get whether it's for insert local directory
+        boolean isToLocal = qbMetaData.getDestTypeForAlias(dest) == QBMetaData.DEST_LOCAL_FILE;
+        HiveParserDirectoryDesc directoryDesc = topQB.getDirectoryDesc();
+
+        // set row format / stored as / location
+        Map<String, String> props = new HashMap<>();
+        HiveParserDDLSemanticAnalyzer.encodeRowFormat(directoryDesc.getRowFormatParams(), props);
+        HiveParserDDLSemanticAnalyzer.encodeStorageFormat(directoryDesc.getStorageFormat(), props);
+        props.put(TABLE_LOCATION_URI, location);
+
+        props.put(FactoryUtil.CONNECTOR.key(), HiveCatalogFactoryOptions.IDENTIFIER);
+        // mark it's for insert into directory
+        props.put(CatalogPropertiesUtil.FLINK_PROPERTY_PREFIX + IS_INSERT_DIRECTORY, "true");
+        // mark it's for insert into local directory or not
+        props.put(
+                CatalogPropertiesUtil.FLINK_PROPERTY_PREFIX + IS_TO_LOCAL_DIRECTORY,
+                String.valueOf(isToLocal));
+
+        List<RelDataTypeField> fieldList = queryRelNode.getRowType().getFieldList();
+        String[] colNameArr = new String[fieldList.size()];
+        String[] colTypeArr = new String[fieldList.size()];
+        for (int i = 0; i < fieldList.size(); i++) {
+            colNameArr[i] = fieldList.get(i).getName();
+            TypeInfo typeInfo = HiveParserTypeConverter.convert(fieldList.get(i).getType());
+            if (typeInfo.equals(TypeInfoFactory.voidTypeInfo)) {
+                colTypeArr[i] = TypeInfoFactory.stringTypeInfo.getTypeName();
+            } else {
+                colTypeArr[i] = typeInfo.getTypeName();
+            }
+        }
+
+        String colNames = String.join(",", colNameArr);
+        String colTypes = String.join(":", colTypeArr);
+        props.put("columns", colNames);
+        props.put("columns.types", colTypes);
+
+        PlannerQueryOperation plannerQueryOperation = new PlannerQueryOperation(queryRelNode);
+        return new SinkModifyOperation(
+                createDummyTableForInsertDirectory(
+                        plannerQueryOperation.getResolvedSchema(), props),
+                new PlannerQueryOperation(queryRelNode),
+                Collections.emptyMap(),
+                true, // insert into directory is always for overwrite
+                Collections.emptyMap());
+    }
+
+    private ContextResolvedTable createDummyTableForInsertDirectory(
+            ResolvedSchema resolvedSchema, Map<String, String> props) {
+        Schema.Builder schemaBuilder = Schema.newBuilder();
+        for (Column column : resolvedSchema.getColumns()) {
+            schemaBuilder.column(column.getName(), column.getDataType());
+        }
+        CatalogTable catalogTable =
+                CatalogTable.of(
+                        schemaBuilder.build(),
+                        "a dummy table for the case of insert into directory ",
+                        Collections.emptyList(),
+                        props);
+        ResolvedCatalogTable resolvedCatalogTable =
+                new ResolvedCatalogTable(catalogTable, resolvedSchema);
+        String currentCatalog = catalogManager.getCurrentCatalog();
+        // the object name means nothing, it's just for placeholder and won't be used actually
+        String objectName = "insert_directory_tbl";

Review Comment:
   Add an UUID suffix to avoid conflict?



##########
flink-connectors/flink-connector-files/pom.xml:
##########
@@ -65,6 +65,12 @@ under the License.
 			<scope>provided</scope>
 		</dependency>
 
+		<dependency>

Review Comment:
   We should not dependent it.



##########
flink-connectors/flink-connector-hive/src/main/java/org/apache/flink/table/planner/delegation/hive/HiveParserDMLHelper.java:
##########
@@ -285,6 +305,81 @@ public Operation createInsertOperation(HiveParserCalcitePlanner analyzer, RelNod
                 Collections.emptyMap());
     }
 
+    private SinkModifyOperation createInsertIntoDirectoryOperation(
+            HiveParserQB topQB, QBMetaData qbMetaData, RelNode queryRelNode, HiveConf hiveConf) {

Review Comment:
   `HiveConf hiveConf` is not used here, remove it?



##########
flink-connectors/flink-connector-hive/src/test/java/org/apache/flink/connectors/hive/HiveDialectQueryITCase.java:
##########
@@ -330,6 +333,59 @@ public void testJoinInvolvingComplexType() throws Exception {
         }
     }
 
+    @Test
+    public void testInsertDirectory() throws Exception {
+        String warehouse = hiveCatalog.getHiveConf().getVar(HiveConf.ConfVars.METASTOREWAREHOUSE);
+
+        // test insert overwrite directory with row format parameters
+        tableEnv.executeSql("create table map_table (foo STRING , bar MAP<STRING, INT>)");
+        tableEnv.executeSql(
+                "insert into map_table select 'A', map('math',100,'english',90,'history',85)");
+
+        String dataDir = warehouse + "/map_table_dir";

Review Comment:
   It will be better use a random dir such as add an UUID suffix.  `FileUtils#getRandomFilename` maybe useful.



##########
flink-table/flink-sql-parser-hive/src/main/java/org/apache/flink/sql/parser/hive/ddl/SqlCreateHiveTable.java:
##########
@@ -50,7 +50,8 @@ public class SqlCreateHiveTable extends SqlCreateTable {
     public static final String PK_CONSTRAINT_TRAIT = "hive.pk.constraint.trait";
     public static final String NOT_NULL_CONSTRAINT_TRAITS = "hive.not.null.constraint.traits";
     public static final String NOT_NULL_COLS = "hive.not.null.cols";
-
+    public static final String IS_INSERT_DIRECTORY = "is-insert-directory";

Review Comment:
   In the long run, this module will be dropped, so I think we should add new code in here?



##########
flink-connectors/flink-connector-hive/src/main/java/org/apache/flink/table/planner/delegation/hive/copy/HiveParserQB.java:
##########
@@ -69,6 +69,10 @@ public class HiveParserQB {
      */
     private int numSubQueryPredicates;
 
+    private CreateTableDesc createTableDesc;

Review Comment:
   It seems that `createTableDesc` doesn't must require here, remove it?



##########
flink-table/flink-sql-parser-hive/src/main/java/org/apache/flink/sql/parser/hive/ddl/SqlCreateHiveTable.java:
##########
@@ -50,7 +50,8 @@ public class SqlCreateHiveTable extends SqlCreateTable {
     public static final String PK_CONSTRAINT_TRAIT = "hive.pk.constraint.trait";
     public static final String NOT_NULL_CONSTRAINT_TRAITS = "hive.not.null.constraint.traits";
     public static final String NOT_NULL_COLS = "hive.not.null.cols";
-
+    public static final String IS_INSERT_DIRECTORY = "is-insert-directory";
+    public static final String IS_TO_LOCAL_DIRECTORY = "is-to-local-directory";

Review Comment:
   IS_LOCAL_DIRECTORY = "is-local-directory"?



##########
flink-connectors/flink-connector-hive/src/main/java/org/apache/flink/table/planner/delegation/hive/HiveParserDMLHelper.java:
##########
@@ -285,6 +305,81 @@ public Operation createInsertOperation(HiveParserCalcitePlanner analyzer, RelNod
                 Collections.emptyMap());
     }
 
+    private SinkModifyOperation createInsertIntoDirectoryOperation(
+            HiveParserQB topQB, QBMetaData qbMetaData, RelNode queryRelNode, HiveConf hiveConf) {
+        String dest = topQB.getParseInfo().getClauseNamesForDest().iterator().next();
+        // get the location for insert into directory
+        String location = qbMetaData.getDestFileForAlias(dest);
+        // get whether it's for insert local directory
+        boolean isToLocal = qbMetaData.getDestTypeForAlias(dest) == QBMetaData.DEST_LOCAL_FILE;
+        HiveParserDirectoryDesc directoryDesc = topQB.getDirectoryDesc();
+
+        // set row format / stored as / location
+        Map<String, String> props = new HashMap<>();
+        HiveParserDDLSemanticAnalyzer.encodeRowFormat(directoryDesc.getRowFormatParams(), props);
+        HiveParserDDLSemanticAnalyzer.encodeStorageFormat(directoryDesc.getStorageFormat(), props);
+        props.put(TABLE_LOCATION_URI, location);
+
+        props.put(FactoryUtil.CONNECTOR.key(), HiveCatalogFactoryOptions.IDENTIFIER);
+        // mark it's for insert into directory
+        props.put(CatalogPropertiesUtil.FLINK_PROPERTY_PREFIX + IS_INSERT_DIRECTORY, "true");
+        // mark it's for insert into local directory or not
+        props.put(
+                CatalogPropertiesUtil.FLINK_PROPERTY_PREFIX + IS_TO_LOCAL_DIRECTORY,
+                String.valueOf(isToLocal));
+
+        List<RelDataTypeField> fieldList = queryRelNode.getRowType().getFieldList();
+        String[] colNameArr = new String[fieldList.size()];
+        String[] colTypeArr = new String[fieldList.size()];
+        for (int i = 0; i < fieldList.size(); i++) {
+            colNameArr[i] = fieldList.get(i).getName();
+            TypeInfo typeInfo = HiveParserTypeConverter.convert(fieldList.get(i).getType());
+            if (typeInfo.equals(TypeInfoFactory.voidTypeInfo)) {
+                colTypeArr[i] = TypeInfoFactory.stringTypeInfo.getTypeName();
+            } else {
+                colTypeArr[i] = typeInfo.getTypeName();
+            }
+        }
+
+        String colNames = String.join(",", colNameArr);
+        String colTypes = String.join(":", colTypeArr);
+        props.put("columns", colNames);
+        props.put("columns.types", colTypes);
+
+        PlannerQueryOperation plannerQueryOperation = new PlannerQueryOperation(queryRelNode);
+        return new SinkModifyOperation(
+                createDummyTableForInsertDirectory(
+                        plannerQueryOperation.getResolvedSchema(), props),
+                new PlannerQueryOperation(queryRelNode),
+                Collections.emptyMap(),
+                true, // insert into directory is always for overwrite
+                Collections.emptyMap());
+    }
+
+    private ContextResolvedTable createDummyTableForInsertDirectory(
+            ResolvedSchema resolvedSchema, Map<String, String> props) {
+        Schema.Builder schemaBuilder = Schema.newBuilder();
+        for (Column column : resolvedSchema.getColumns()) {
+            schemaBuilder.column(column.getName(), column.getDataType());
+        }
+        CatalogTable catalogTable =
+                CatalogTable.of(
+                        schemaBuilder.build(),

Review Comment:
   `Schema.newBuilder().fromResolvedSchema(resolvedSchema).build()`



##########
flink-connectors/flink-connector-hive/src/main/java/org/apache/flink/table/planner/delegation/hive/HiveParserDMLHelper.java:
##########
@@ -285,6 +305,81 @@ public Operation createInsertOperation(HiveParserCalcitePlanner analyzer, RelNod
                 Collections.emptyMap());
     }
 
+    private SinkModifyOperation createInsertIntoDirectoryOperation(
+            HiveParserQB topQB, QBMetaData qbMetaData, RelNode queryRelNode, HiveConf hiveConf) {
+        String dest = topQB.getParseInfo().getClauseNamesForDest().iterator().next();
+        // get the location for insert into directory
+        String location = qbMetaData.getDestFileForAlias(dest);
+        // get whether it's for insert local directory
+        boolean isToLocal = qbMetaData.getDestTypeForAlias(dest) == QBMetaData.DEST_LOCAL_FILE;
+        HiveParserDirectoryDesc directoryDesc = topQB.getDirectoryDesc();
+
+        // set row format / stored as / location
+        Map<String, String> props = new HashMap<>();
+        HiveParserDDLSemanticAnalyzer.encodeRowFormat(directoryDesc.getRowFormatParams(), props);
+        HiveParserDDLSemanticAnalyzer.encodeStorageFormat(directoryDesc.getStorageFormat(), props);
+        props.put(TABLE_LOCATION_URI, location);
+
+        props.put(FactoryUtil.CONNECTOR.key(), HiveCatalogFactoryOptions.IDENTIFIER);
+        // mark it's for insert into directory
+        props.put(CatalogPropertiesUtil.FLINK_PROPERTY_PREFIX + IS_INSERT_DIRECTORY, "true");
+        // mark it's for insert into local directory or not
+        props.put(
+                CatalogPropertiesUtil.FLINK_PROPERTY_PREFIX + IS_TO_LOCAL_DIRECTORY,
+                String.valueOf(isToLocal));
+
+        List<RelDataTypeField> fieldList = queryRelNode.getRowType().getFieldList();
+        String[] colNameArr = new String[fieldList.size()];
+        String[] colTypeArr = new String[fieldList.size()];
+        for (int i = 0; i < fieldList.size(); i++) {
+            colNameArr[i] = fieldList.get(i).getName();
+            TypeInfo typeInfo = HiveParserTypeConverter.convert(fieldList.get(i).getType());
+            if (typeInfo.equals(TypeInfoFactory.voidTypeInfo)) {
+                colTypeArr[i] = TypeInfoFactory.stringTypeInfo.getTypeName();
+            } else {
+                colTypeArr[i] = typeInfo.getTypeName();
+            }
+        }
+
+        String colNames = String.join(",", colNameArr);
+        String colTypes = String.join(":", colTypeArr);
+        props.put("columns", colNames);
+        props.put("columns.types", colTypes);
+
+        PlannerQueryOperation plannerQueryOperation = new PlannerQueryOperation(queryRelNode);
+        return new SinkModifyOperation(
+                createDummyTableForInsertDirectory(
+                        plannerQueryOperation.getResolvedSchema(), props),
+                new PlannerQueryOperation(queryRelNode),
+                Collections.emptyMap(),
+                true, // insert into directory is always for overwrite
+                Collections.emptyMap());
+    }
+
+    private ContextResolvedTable createDummyTableForInsertDirectory(
+            ResolvedSchema resolvedSchema, Map<String, String> props) {
+        Schema.Builder schemaBuilder = Schema.newBuilder();
+        for (Column column : resolvedSchema.getColumns()) {
+            schemaBuilder.column(column.getName(), column.getDataType());
+        }
+        CatalogTable catalogTable =
+                CatalogTable.of(
+                        schemaBuilder.build(),
+                        "a dummy table for the case of insert into directory ",

Review Comment:
   insert overwrite directory



##########
flink-connectors/flink-connector-hive/src/main/java/org/apache/flink/table/planner/delegation/hive/HiveParserDMLHelper.java:
##########
@@ -285,6 +305,81 @@ public Operation createInsertOperation(HiveParserCalcitePlanner analyzer, RelNod
                 Collections.emptyMap());
     }
 
+    private SinkModifyOperation createInsertIntoDirectoryOperation(
+            HiveParserQB topQB, QBMetaData qbMetaData, RelNode queryRelNode, HiveConf hiveConf) {
+        String dest = topQB.getParseInfo().getClauseNamesForDest().iterator().next();
+        // get the location for insert into directory
+        String location = qbMetaData.getDestFileForAlias(dest);
+        // get whether it's for insert local directory
+        boolean isToLocal = qbMetaData.getDestTypeForAlias(dest) == QBMetaData.DEST_LOCAL_FILE;
+        HiveParserDirectoryDesc directoryDesc = topQB.getDirectoryDesc();
+
+        // set row format / stored as / location
+        Map<String, String> props = new HashMap<>();
+        HiveParserDDLSemanticAnalyzer.encodeRowFormat(directoryDesc.getRowFormatParams(), props);
+        HiveParserDDLSemanticAnalyzer.encodeStorageFormat(directoryDesc.getStorageFormat(), props);
+        props.put(TABLE_LOCATION_URI, location);
+
+        props.put(FactoryUtil.CONNECTOR.key(), HiveCatalogFactoryOptions.IDENTIFIER);
+        // mark it's for insert into directory
+        props.put(CatalogPropertiesUtil.FLINK_PROPERTY_PREFIX + IS_INSERT_DIRECTORY, "true");
+        // mark it's for insert into local directory or not
+        props.put(
+                CatalogPropertiesUtil.FLINK_PROPERTY_PREFIX + IS_TO_LOCAL_DIRECTORY,
+                String.valueOf(isToLocal));
+
+        List<RelDataTypeField> fieldList = queryRelNode.getRowType().getFieldList();
+        String[] colNameArr = new String[fieldList.size()];
+        String[] colTypeArr = new String[fieldList.size()];
+        for (int i = 0; i < fieldList.size(); i++) {
+            colNameArr[i] = fieldList.get(i).getName();
+            TypeInfo typeInfo = HiveParserTypeConverter.convert(fieldList.get(i).getType());
+            if (typeInfo.equals(TypeInfoFactory.voidTypeInfo)) {
+                colTypeArr[i] = TypeInfoFactory.stringTypeInfo.getTypeName();
+            } else {
+                colTypeArr[i] = typeInfo.getTypeName();
+            }
+        }
+
+        String colNames = String.join(",", colNameArr);
+        String colTypes = String.join(":", colTypeArr);
+        props.put("columns", colNames);
+        props.put("columns.types", colTypes);
+
+        PlannerQueryOperation plannerQueryOperation = new PlannerQueryOperation(queryRelNode);
+        return new SinkModifyOperation(
+                createDummyTableForInsertDirectory(
+                        plannerQueryOperation.getResolvedSchema(), props),
+                new PlannerQueryOperation(queryRelNode),

Review Comment:
   Here can reuse the above `plannerQueryOperation` 



##########
flink-connectors/flink-connector-files/src/main/java/org/apache/flink/connector/file/table/PartitionLoader.java:
##########
@@ -99,15 +104,32 @@ private void overwrite(Path destDir) throws Exception {
     }
 
     /** Moves files from srcDir to destDir. */
-    private void renameFiles(List<Path> srcDirs, Path destDir) throws Exception {
+    private void moveFiles(List<Path> srcDirs, Path destDir) throws Exception {
         for (Path srcDir : srcDirs) {
             if (!srcDir.equals(destDir)) {
                 FileStatus[] srcFiles = listStatusWithoutHidden(fs, srcDir);
                 if (srcFiles != null) {
                     for (FileStatus srcFile : srcFiles) {
                         Path srcPath = srcFile.getPath();
                         Path destPath = new Path(destDir, srcPath.getName());
-                        fs.rename(srcPath, destPath);
+                        // if it's not to move to local file system, just rename it
+                        if (!isToLocal) {
+                            fs.rename(srcPath, destPath);
+                        } else {
+                            // need move to local file system
+                            if (fs instanceof HadoopFileSystem) {
+                                HadoopFileSystem hdfs = ((HadoopFileSystem) fs);

Review Comment:
   We don't need to use HadoopFileSystem, the logic is specialized. Here can use `                            FileUtils.copy(srcPath, destPath, true);` copy file to local simply. Moreover, you should add an insert local directory test.



-- 
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: issues-unsubscribe@flink.apache.org

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


[GitHub] [flink] luoyuxia commented on a diff in pull request #19520: [FLINK-26366][hive] support insert overwrite directory

Posted by GitBox <gi...@apache.org>.
luoyuxia commented on code in PR #19520:
URL: https://github.com/apache/flink/pull/19520#discussion_r892240386


##########
flink-connectors/flink-connector-hive/src/test/java/org/apache/flink/connectors/hive/HiveDialectQueryITCase.java:
##########
@@ -330,6 +333,59 @@ public void testJoinInvolvingComplexType() throws Exception {
         }
     }
 
+    @Test
+    public void testInsertDirectory() throws Exception {
+        String warehouse = hiveCatalog.getHiveConf().getVar(HiveConf.ConfVars.METASTOREWAREHOUSE);
+
+        // test insert overwrite directory with row format parameters
+        tableEnv.executeSql("create table map_table (foo STRING , bar MAP<STRING, INT>)");
+        tableEnv.executeSql(
+                "insert into map_table select 'A', map('math',100,'english',90,'history',85)");
+
+        String dataDir = warehouse + "/map_table_dir";
+        tableEnv.executeSql(
+                        String.format(
+                                "INSERT OVERWRITE DIRECTORY '%s'"
+                                        + "ROW FORMAT DELIMITED \n"
+                                        + "FIELDS TERMINATED BY ':'\n"
+                                        + "COLLECTION ITEMS TERMINATED BY '#' \n"
+                                        + "MAP KEYS TERMINATED BY '=' select * from map_table",
+                                dataDir))
+                .await();
+        java.nio.file.Path[] files =
+                FileUtils.listFilesInDirectory(
+                                Paths.get(dataDir), (path) -> !path.toFile().isHidden())
+                        .toArray(new Path[0]);
+        assertEquals(1, files.length);
+        String actualString = FileUtils.readFileUtf8(files[0].toFile());

Review Comment:
   Here, we want to make sure the file format like `separator` is consistent with specified in SQL.
   If create a external table and then read it, we can't make such guarantee.



-- 
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: issues-unsubscribe@flink.apache.org

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


[GitHub] [flink] flinkbot commented on pull request #19520: [FLINK-26366][hive] support insert overwrite directory

Posted by GitBox <gi...@apache.org>.
flinkbot commented on PR #19520:
URL: https://github.com/apache/flink/pull/19520#issuecomment-1103417126

   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "63ebecb5b68a6371036ddb5c609b7094ea6b00fa",
       "status" : "UNKNOWN",
       "url" : "TBD",
       "triggerID" : "63ebecb5b68a6371036ddb5c609b7094ea6b00fa",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * 63ebecb5b68a6371036ddb5c609b7094ea6b00fa UNKNOWN
   
   <details>
   <summary>Bot commands</summary>
     The @flinkbot bot supports the following commands:
   
    - `@flinkbot run azure` re-run the last Azure build
   </details>


-- 
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: issues-unsubscribe@flink.apache.org

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


[GitHub] [flink] luoyuxia commented on a diff in pull request #19520: [FLINK-26366][hive] support insert overwrite directory

Posted by GitBox <gi...@apache.org>.
luoyuxia commented on code in PR #19520:
URL: https://github.com/apache/flink/pull/19520#discussion_r933712358


##########
flink-connectors/flink-connector-hive/src/main/java/org/apache/flink/table/planner/delegation/hive/HiveParserDMLHelper.java:
##########
@@ -209,7 +227,8 @@ public HiveParserDMLHelper(
                 identifier, new PlannerQueryOperation(queryRelNode), staticPartSpec, overwrite);
     }
 
-    public Operation createInsertOperation(HiveParserCalcitePlanner analyzer, RelNode queryRelNode)
+    public Operation createInsertOperation(
+            HiveParserCalcitePlanner analyzer, RelNode queryRelNode, HiveConf hiveConf)

Review Comment:
   Miss added. Now I removed it.



-- 
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: issues-unsubscribe@flink.apache.org

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


[GitHub] [flink] luoyuxia commented on a diff in pull request #19520: [FLINK-26366][hive] support insert overwrite directory

Posted by GitBox <gi...@apache.org>.
luoyuxia commented on code in PR #19520:
URL: https://github.com/apache/flink/pull/19520#discussion_r892241423


##########
flink-table/flink-sql-parser-hive/src/main/java/org/apache/flink/sql/parser/hive/ddl/SqlCreateHiveTable.java:
##########
@@ -50,7 +50,8 @@ public class SqlCreateHiveTable extends SqlCreateTable {
     public static final String PK_CONSTRAINT_TRAIT = "hive.pk.constraint.trait";
     public static final String NOT_NULL_CONSTRAINT_TRAITS = "hive.not.null.constraint.traits";
     public static final String NOT_NULL_COLS = "hive.not.null.cols";
-
+    public static final String IS_INSERT_DIRECTORY = "is-insert-directory";
+    public static final String IS_TO_LOCAL_DIRECTORY = "is-to-local-directory";

Review Comment:
   I think it's more intuitive with `is-to-local-directory`.



-- 
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: issues-unsubscribe@flink.apache.org

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


[GitHub] [flink] luoyuxia commented on a diff in pull request #19520: [FLINK-26366][hive] support insert overwrite directory

Posted by GitBox <gi...@apache.org>.
luoyuxia commented on code in PR #19520:
URL: https://github.com/apache/flink/pull/19520#discussion_r933716216


##########
flink-connectors/flink-connector-hive/src/main/java/org/apache/flink/table/planner/delegation/hive/HiveParserDMLHelper.java:
##########
@@ -285,6 +304,78 @@ public Operation createInsertOperation(HiveParserCalcitePlanner analyzer, RelNod
                 Collections.emptyMap());
     }
 
+    private SinkModifyOperation createInsertIntoDirectoryOperation(
+            HiveParserQB topQB, QBMetaData qbMetaData, RelNode queryRelNode) {
+        String dest = topQB.getParseInfo().getClauseNamesForDest().iterator().next();
+        // get the location for insert into directory
+        String location = qbMetaData.getDestFileForAlias(dest);
+        // get whether it's for insert local directory
+        boolean isToLocal = qbMetaData.getDestTypeForAlias(dest) == QBMetaData.DEST_LOCAL_FILE;
+        HiveParserDirectoryDesc directoryDesc = topQB.getDirectoryDesc();
+
+        // set row format / stored as / location
+        Map<String, String> props = new HashMap<>();
+        HiveParserDDLSemanticAnalyzer.encodeRowFormat(directoryDesc.getRowFormatParams(), props);
+        HiveParserDDLSemanticAnalyzer.encodeStorageFormat(directoryDesc.getStorageFormat(), props);
+        props.put(TABLE_LOCATION_URI, location);
+
+        props.put(FactoryUtil.CONNECTOR.key(), HiveCatalogFactoryOptions.IDENTIFIER);
+        // mark it's for insert into directory
+        props.put(CatalogPropertiesUtil.FLINK_PROPERTY_PREFIX + IS_INSERT_DIRECTORY, "true");
+        // mark it's for insert into local directory or not
+        props.put(
+                CatalogPropertiesUtil.FLINK_PROPERTY_PREFIX + IS_TO_LOCAL_DIRECTORY,
+                String.valueOf(isToLocal));
+
+        List<RelDataTypeField> fieldList = queryRelNode.getRowType().getFieldList();
+        String[] colNameArr = new String[fieldList.size()];
+        String[] colTypeArr = new String[fieldList.size()];
+        for (int i = 0; i < fieldList.size(); i++) {
+            colNameArr[i] = fieldList.get(i).getName();
+            TypeInfo typeInfo = HiveParserTypeConverter.convert(fieldList.get(i).getType());
+            if (typeInfo.equals(TypeInfoFactory.voidTypeInfo)) {
+                colTypeArr[i] = TypeInfoFactory.stringTypeInfo.getTypeName();
+            } else {
+                colTypeArr[i] = typeInfo.getTypeName();
+            }
+        }
+
+        String colNames = String.join(",", colNameArr);
+        String colTypes = String.join(":", colTypeArr);
+        props.put("columns", colNames);
+        props.put("columns.types", colTypes);
+
+        PlannerQueryOperation plannerQueryOperation = new PlannerQueryOperation(queryRelNode);

Review Comment:
   We don't need the extra logic when it's for `insert overwrite into directory`.
   When it's insert into directory, no need to do type conversion which is actually for converting into dest table's schema and no need to do adjustment for static partitions & dynamic partition which is only needed when the dest is a real table.



-- 
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: issues-unsubscribe@flink.apache.org

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


[GitHub] [flink] wuchong commented on a diff in pull request #19520: [FLINK-26366][hive] support insert overwrite directory

Posted by GitBox <gi...@apache.org>.
wuchong commented on code in PR #19520:
URL: https://github.com/apache/flink/pull/19520#discussion_r932941561


##########
flink-connectors/flink-connector-hive/src/main/java/org/apache/flink/table/planner/delegation/hive/HiveParserDMLHelper.java:
##########
@@ -209,7 +227,8 @@ public HiveParserDMLHelper(
                 identifier, new PlannerQueryOperation(queryRelNode), staticPartSpec, overwrite);
     }
 
-    public Operation createInsertOperation(HiveParserCalcitePlanner analyzer, RelNode queryRelNode)
+    public Operation createInsertOperation(
+            HiveParserCalcitePlanner analyzer, RelNode queryRelNode, HiveConf hiveConf)

Review Comment:
   The `hiveConf` is never used?



##########
flink-connectors/flink-connector-hive/src/main/java/org/apache/flink/table/planner/delegation/hive/HiveParserDMLHelper.java:
##########
@@ -285,6 +304,78 @@ public Operation createInsertOperation(HiveParserCalcitePlanner analyzer, RelNod
                 Collections.emptyMap());
     }
 
+    private SinkModifyOperation createInsertIntoDirectoryOperation(
+            HiveParserQB topQB, QBMetaData qbMetaData, RelNode queryRelNode) {
+        String dest = topQB.getParseInfo().getClauseNamesForDest().iterator().next();
+        // get the location for insert into directory
+        String location = qbMetaData.getDestFileForAlias(dest);
+        // get whether it's for insert local directory
+        boolean isToLocal = qbMetaData.getDestTypeForAlias(dest) == QBMetaData.DEST_LOCAL_FILE;
+        HiveParserDirectoryDesc directoryDesc = topQB.getDirectoryDesc();
+
+        // set row format / stored as / location
+        Map<String, String> props = new HashMap<>();
+        HiveParserDDLSemanticAnalyzer.encodeRowFormat(directoryDesc.getRowFormatParams(), props);
+        HiveParserDDLSemanticAnalyzer.encodeStorageFormat(directoryDesc.getStorageFormat(), props);
+        props.put(TABLE_LOCATION_URI, location);
+
+        props.put(FactoryUtil.CONNECTOR.key(), HiveCatalogFactoryOptions.IDENTIFIER);
+        // mark it's for insert into directory
+        props.put(CatalogPropertiesUtil.FLINK_PROPERTY_PREFIX + IS_INSERT_DIRECTORY, "true");
+        // mark it's for insert into local directory or not
+        props.put(
+                CatalogPropertiesUtil.FLINK_PROPERTY_PREFIX + IS_TO_LOCAL_DIRECTORY,
+                String.valueOf(isToLocal));
+
+        List<RelDataTypeField> fieldList = queryRelNode.getRowType().getFieldList();
+        String[] colNameArr = new String[fieldList.size()];
+        String[] colTypeArr = new String[fieldList.size()];
+        for (int i = 0; i < fieldList.size(); i++) {
+            colNameArr[i] = fieldList.get(i).getName();
+            TypeInfo typeInfo = HiveParserTypeConverter.convert(fieldList.get(i).getType());
+            if (typeInfo.equals(TypeInfoFactory.voidTypeInfo)) {
+                colTypeArr[i] = TypeInfoFactory.stringTypeInfo.getTypeName();
+            } else {
+                colTypeArr[i] = typeInfo.getTypeName();
+            }
+        }
+
+        String colNames = String.join(",", colNameArr);
+        String colTypes = String.join(":", colTypeArr);
+        props.put("columns", colNames);
+        props.put("columns.types", colTypes);
+
+        PlannerQueryOperation plannerQueryOperation = new PlannerQueryOperation(queryRelNode);

Review Comment:
   There are some conversions (e.g. type conversion, static partitions) on the `queryRelNode` in `createInsertOperationInfo()`. Should we reuse the logic here? 



-- 
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: issues-unsubscribe@flink.apache.org

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


[GitHub] [flink] luoyuxia commented on a diff in pull request #19520: [FLINK-26366][hive] support insert overwrite directory

Posted by GitBox <gi...@apache.org>.
luoyuxia commented on code in PR #19520:
URL: https://github.com/apache/flink/pull/19520#discussion_r892231118


##########
flink-connectors/flink-connector-hive/src/main/java/org/apache/flink/table/planner/delegation/hive/copy/HiveParserSemanticAnalyzer.java:
##########
@@ -1792,61 +1791,42 @@ private void getMetaData(HiveParserQB qb, ReadEntity parentInput) throws HiveExc
                             }
                         }
 
-                        boolean isDfsFile = true;
-                        if (ast.getChildCount() >= 2
-                                && ast.getChild(1).getText().toLowerCase().equals("local")) {
-                            isDfsFile = false;
-                        }
+                        boolean isDfsFile =
+                                ast.getChildCount() < 2

Review Comment:
   for insert directory, the ast node will like 
   `TOK_DIR StringLiteral $local? tableRowFormat? tableFileFormat?`
   So, `ChildCount < 2` means there's no `local ` token, or the `ChildCount >= 2` but the second token is not `local`, which means it's not to insert local directory.



-- 
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: issues-unsubscribe@flink.apache.org

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