leaves12138 commented on code in PR #1624: URL: https://github.com/apache/incubator-paimon/pull/1624#discussion_r1277331622
########## paimon-flink/paimon-flink-common/src/main/java/org/apache/paimon/flink/action/OrderRewriteActionFactory.java: ########## @@ -0,0 +1,86 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.paimon.flink.action; + +import org.apache.flink.api.java.tuple.Tuple3; +import org.apache.flink.api.java.utils.MultipleParameterTool; + +import java.util.Map; +import java.util.Optional; + +/** Action Factory to create {@link OrderRewriteAction}. */ +public class OrderRewriteActionFactory implements ActionFactory { + + public static final String IDENTIFIER = "order-rewrite"; + + @Override + public String identifier() { + return IDENTIFIER; + } + + @Override + public Optional<Action> create(MultipleParameterTool params) { + if (params.has("help")) { + printHelp(); + return Optional.empty(); + } + + Tuple3<String, String, String> tablePath = getTablePath(params); + + String sqlSelect = getSqlSelect(params); + + Map<String, String> catalogConfig = optionalConfigMap(params, "catalog-conf"); + + String sqlOrderBy = getSqlOrderBy(params); + + return Optional.of( + new OrderRewriteAction( + tablePath.f0, + tablePath.f1, + tablePath.f2, + sqlSelect, + sqlOrderBy, + catalogConfig)); + } + + @Override + public void printHelp() { + System.out.println( + "Action \"order-rewrite\" is similar to sql \"INSERT OVERWRITE target_table SELECT * FROM SOURCE ZORDER BY col1,col2,... \"."); + System.out.println(); + + System.out.println("Syntax:"); + System.out.println( + " order-rewrite --warehouse <warehouse-path>\n" + + " --database <database-name>\n" + + " --warehouse <warehouse-path>\n" + + " --table <target-table-name>\n" + + " --sql-select \"sql\"\n" Review Comment: Learned from iceberg: https://iceberg.apache.org/docs/latest/spark-procedures/#rewrite_data_files Iceberg rewrite action has sort_order: For Zorder use a comma separated list of columns within zorder(). (Supported in Spark 3.2 and Above) Example: zorder(c1,c2,c3). Else, Comma separated sort orders in the format (ColumnName SortDirection NullOrder). Where SortDirection can be ASC or DESC. NullOrder can be NULLS FIRST or NULLS LAST. Defaults to the table’s sort order where:predicate as a string used for filtering the files. Note that all files that may contain data matching the filter will be selected for rewriting eg: CALL catalog_name.system.rewrite_data_files(table => 'db.sample', where => 'id = 3 and name = "foo", strategy => 'sort', sort_order => 'zorder(c1,c2)') But I thing use write sql-select is more flexible, which mean they could rewrite source table to target table by zorder without changing origin table. So i change "where" to "sql-select" ########## paimon-flink/paimon-flink-common/src/main/java/org/apache/paimon/flink/action/OrderRewriteActionFactory.java: ########## @@ -0,0 +1,86 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.paimon.flink.action; + +import org.apache.flink.api.java.tuple.Tuple3; +import org.apache.flink.api.java.utils.MultipleParameterTool; + +import java.util.Map; +import java.util.Optional; + +/** Action Factory to create {@link OrderRewriteAction}. */ +public class OrderRewriteActionFactory implements ActionFactory { + + public static final String IDENTIFIER = "order-rewrite"; + + @Override + public String identifier() { + return IDENTIFIER; + } + + @Override + public Optional<Action> create(MultipleParameterTool params) { + if (params.has("help")) { + printHelp(); + return Optional.empty(); + } + + Tuple3<String, String, String> tablePath = getTablePath(params); + + String sqlSelect = getSqlSelect(params); + + Map<String, String> catalogConfig = optionalConfigMap(params, "catalog-conf"); + + String sqlOrderBy = getSqlOrderBy(params); + + return Optional.of( + new OrderRewriteAction( + tablePath.f0, + tablePath.f1, + tablePath.f2, + sqlSelect, + sqlOrderBy, + catalogConfig)); + } + + @Override + public void printHelp() { + System.out.println( + "Action \"order-rewrite\" is similar to sql \"INSERT OVERWRITE target_table SELECT * FROM SOURCE ZORDER BY col1,col2,... \"."); + System.out.println(); + + System.out.println("Syntax:"); + System.out.println( + " order-rewrite --warehouse <warehouse-path>\n" + + " --database <database-name>\n" + + " --warehouse <warehouse-path>\n" + + " --table <target-table-name>\n" + + " --sql-select \"sql\"\n" Review Comment: Learned from iceberg: https://iceberg.apache.org/docs/latest/spark-procedures/#rewrite_data_files Iceberg rewrite action has sort_order: For Zorder use a comma separated list of columns within zorder(). (Supported in Spark 3.2 and Above) Example: zorder(c1,c2,c3). Else, Comma separated sort orders in the format (ColumnName SortDirection NullOrder). Where SortDirection can be ASC or DESC. NullOrder can be NULLS FIRST or NULLS LAST. Defaults to the table’s sort order where:predicate as a string used for filtering the files. Note that all files that may contain data matching the filter will be selected for rewriting eg: CALL catalog_name.system.rewrite_data_files(table => 'db.sample', where => 'id = 3 and name = "foo", strategy => 'sort', sort_order => 'zorder(c1,c2)') But I thing use write sql-select is more flexible, which mean they could rewrite source table to target table by zorder without changing origin table. So i change "where" to "sql-select" -- 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]
