-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[flink] Introduce PartitionMarkDone action and procedure (#3584)
- Loading branch information
1 parent
83444c2
commit c1551a4
Showing
8 changed files
with
460 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
...on-flink-common/src/main/java/org/apache/paimon/flink/action/PartitionMarkDoneAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
/* | ||
* 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.paimon.CoreOptions; | ||
import org.apache.paimon.options.Options; | ||
import org.apache.paimon.table.FileStoreTable; | ||
import org.apache.paimon.utils.PartitionPathUtils; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.stream.Collectors; | ||
|
||
import static org.apache.paimon.flink.sink.partition.PartitionMarkDone.closeActions; | ||
import static org.apache.paimon.flink.sink.partition.PartitionMarkDone.getPartitionMarkDoneActions; | ||
import static org.apache.paimon.flink.sink.partition.PartitionMarkDone.markDone; | ||
|
||
/** Table partition mark done action for Flink. */ | ||
public class PartitionMarkDoneAction extends TableActionBase { | ||
|
||
private final FileStoreTable fileStoreTable; | ||
private final List<Map<String, String>> partitions; | ||
private final CoreOptions coreOptions; | ||
private final Options options; | ||
|
||
public PartitionMarkDoneAction( | ||
String warehouse, | ||
String databaseName, | ||
String tableName, | ||
List<Map<String, String>> partitions, | ||
Map<String, String> catalogConfig) { | ||
super(warehouse, databaseName, tableName, catalogConfig); | ||
if (!(table instanceof FileStoreTable)) { | ||
throw new UnsupportedOperationException( | ||
String.format( | ||
"Only FileStoreTable supports mark_partition_done action. The table type is '%s'.", | ||
table.getClass().getName())); | ||
} | ||
|
||
this.fileStoreTable = (FileStoreTable) table; | ||
this.partitions = partitions; | ||
this.coreOptions = fileStoreTable.coreOptions(); | ||
this.options = coreOptions.toConfiguration(); | ||
} | ||
|
||
@Override | ||
public void run() throws Exception { | ||
List<org.apache.paimon.flink.sink.partition.PartitionMarkDoneAction> actions = | ||
getPartitionMarkDoneActions(fileStoreTable, coreOptions, options); | ||
|
||
List<String> partitionPaths = getPartitionPaths(fileStoreTable, partitions); | ||
|
||
markDone(partitionPaths, actions); | ||
|
||
closeActions(actions); | ||
} | ||
|
||
public static List<String> getPartitionPaths( | ||
FileStoreTable fileStoreTable, List<Map<String, String>> partitions) { | ||
return partitions.stream() | ||
.map( | ||
partition -> | ||
PartitionPathUtils.generatePartitionPath( | ||
partition, fileStoreTable.store().partitionType())) | ||
.collect(Collectors.toList()); | ||
} | ||
} |
75 changes: 75 additions & 0 deletions
75
...k-common/src/main/java/org/apache/paimon/flink/action/PartitionMarkDoneActionFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/* | ||
* 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 java.util.List; | ||
import java.util.Map; | ||
import java.util.Optional; | ||
|
||
/** Factory to create {@link PartitionMarkDoneAction}. */ | ||
public class PartitionMarkDoneActionFactory implements ActionFactory { | ||
|
||
public static final String IDENTIFIER = "mark_partition_done"; | ||
|
||
@Override | ||
public String identifier() { | ||
return IDENTIFIER; | ||
} | ||
|
||
@Override | ||
public Optional<Action> create(MultipleParameterToolAdapter params) { | ||
Tuple3<String, String, String> tablePath = getTablePath(params); | ||
|
||
checkRequiredArgument(params, PARTITION); | ||
List<Map<String, String>> partitions = getPartitions(params); | ||
|
||
Map<String, String> catalogConfig = optionalConfigMap(params, CATALOG_CONF); | ||
|
||
return Optional.of( | ||
new PartitionMarkDoneAction( | ||
tablePath.f0, tablePath.f1, tablePath.f2, partitions, catalogConfig)); | ||
} | ||
|
||
@Override | ||
public void printHelp() { | ||
System.out.println( | ||
"Action \"mark_partition_done\" mark done of specified partitions for a table."); | ||
System.out.println(); | ||
|
||
System.out.println("Syntax:"); | ||
System.out.println( | ||
" mark_partition_done --warehouse <warehouse_path> --database <database_name> " | ||
+ "--table <table_name> --partition <partition_name> [--partition <partition_name> ...]"); | ||
System.out.println( | ||
" mark_partition_done --path <table_path> --partition <partition_name> [--partition <partition_name> ...]"); | ||
System.out.println(); | ||
|
||
System.out.println("Partition name syntax:"); | ||
System.out.println(" key1=value1,key2=value2,..."); | ||
System.out.println(); | ||
|
||
System.out.println("Examples:"); | ||
System.out.println( | ||
" mark_partition_done --warehouse hdfs:///path/to/warehouse --database test_db --table test_table --partition dt=20221126,hh=08"); | ||
System.out.println( | ||
" mark_partition_done --path hdfs:///path/to/warehouse/test_db.db/test_table --partition dt=20221126,hh=08 --partition dt=20221127,hh=09"); | ||
} | ||
} |
86 changes: 86 additions & 0 deletions
86
...nk-common/src/main/java/org/apache/paimon/flink/procedure/PartitionMarkDoneProcedure.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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.procedure; | ||
|
||
import org.apache.paimon.CoreOptions; | ||
import org.apache.paimon.catalog.Catalog; | ||
import org.apache.paimon.catalog.Identifier; | ||
import org.apache.paimon.options.Options; | ||
import org.apache.paimon.table.FileStoreTable; | ||
import org.apache.paimon.table.Table; | ||
|
||
import org.apache.flink.table.procedure.ProcedureContext; | ||
|
||
import java.io.IOException; | ||
import java.util.List; | ||
|
||
import static org.apache.paimon.flink.action.PartitionMarkDoneAction.getPartitionPaths; | ||
import static org.apache.paimon.flink.sink.partition.PartitionMarkDone.closeActions; | ||
import static org.apache.paimon.flink.sink.partition.PartitionMarkDone.getPartitionMarkDoneActions; | ||
import static org.apache.paimon.flink.sink.partition.PartitionMarkDone.markDone; | ||
import static org.apache.paimon.utils.ParameterUtils.getPartitions; | ||
import static org.apache.paimon.utils.Preconditions.checkArgument; | ||
|
||
/** | ||
* Partition mark done procedure. Usage: | ||
* | ||
* <pre><code> | ||
* CALL sys.mark_partition_done('tableId', 'partition1', 'partition2', ...) | ||
* </code></pre> | ||
*/ | ||
public class PartitionMarkDoneProcedure extends ProcedureBase { | ||
|
||
public static final String IDENTIFIER = "mark_partition_done"; | ||
|
||
public String[] call( | ||
ProcedureContext procedureContext, String tableId, String... partitionStrings) | ||
throws Catalog.TableNotExistException, IOException { | ||
checkArgument( | ||
partitionStrings.length > 0, | ||
"mark_partition_done procedure must specify partitions."); | ||
|
||
Identifier identifier = Identifier.fromString(tableId); | ||
Table table = catalog.getTable(identifier); | ||
checkArgument( | ||
table instanceof FileStoreTable, | ||
"Only FileStoreTable supports mark_partition_done procedure. The table type is '%s'.", | ||
table.getClass().getName()); | ||
|
||
FileStoreTable fileStoreTable = (FileStoreTable) table; | ||
CoreOptions coreOptions = fileStoreTable.coreOptions(); | ||
Options options = coreOptions.toConfiguration(); | ||
|
||
List<org.apache.paimon.flink.sink.partition.PartitionMarkDoneAction> actions = | ||
getPartitionMarkDoneActions(fileStoreTable, coreOptions, options); | ||
|
||
List<String> partitionPaths = | ||
getPartitionPaths(fileStoreTable, getPartitions(partitionStrings)); | ||
|
||
markDone(partitionPaths, actions); | ||
|
||
closeActions(actions); | ||
|
||
return new String[] {"Success"}; | ||
} | ||
|
||
@Override | ||
public String identifier() { | ||
return IDENTIFIER; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.