-
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.
Change-Id: I66d3d6a774bcaa20a7c473b053490bfe614a7c95
- Loading branch information
1 parent
7ab4ea5
commit 727ba2c
Showing
10 changed files
with
334 additions
and
106 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
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
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
72 changes: 72 additions & 0 deletions
72
...paimon-flink-common/src/main/java/org/apache/paimon/flink/action/ClearConsumerAction.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,72 @@ | ||
/* | ||
* 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.consumer.ConsumerManager; | ||
import org.apache.paimon.table.FileStoreTable; | ||
import org.apache.paimon.utils.StringUtils; | ||
|
||
import javax.annotation.Nullable; | ||
|
||
import java.util.Map; | ||
import java.util.regex.Pattern; | ||
|
||
/** Clear consumers action for Flink. */ | ||
public class ClearConsumerAction extends TableActionBase { | ||
|
||
private String includingConsumers; | ||
private String excludingConsumers; | ||
|
||
protected ClearConsumerAction( | ||
String databaseName, String tableName, Map<String, String> catalogConfig) { | ||
super(databaseName, tableName, catalogConfig); | ||
} | ||
|
||
public ClearConsumerAction withIncludingConsumers(@Nullable String includingConsumers) { | ||
this.includingConsumers = includingConsumers; | ||
return this; | ||
} | ||
|
||
public ClearConsumerAction withExcludingConsumers(@Nullable String excludingConsumers) { | ||
this.excludingConsumers = excludingConsumers; | ||
return this; | ||
} | ||
|
||
@Override | ||
public void run() throws Exception { | ||
FileStoreTable dataTable = (FileStoreTable) table; | ||
ConsumerManager consumerManager = | ||
new ConsumerManager( | ||
dataTable.fileIO(), | ||
dataTable.location(), | ||
dataTable.snapshotManager().branch()); | ||
|
||
includingConsumers = | ||
StringUtils.isNullOrWhitespaceOnly(includingConsumers) ? null : includingConsumers; | ||
excludingConsumers = | ||
StringUtils.isNullOrWhitespaceOnly(excludingConsumers) ? null : excludingConsumers; | ||
Pattern includingPattern = | ||
includingConsumers == null | ||
? Pattern.compile(".*") | ||
: Pattern.compile(includingConsumers); | ||
Pattern excludingPattern = | ||
excludingConsumers == null ? null : Pattern.compile(excludingConsumers); | ||
consumerManager.clearConsumers(includingPattern, excludingPattern); | ||
} | ||
} |
72 changes: 72 additions & 0 deletions
72
...flink-common/src/main/java/org/apache/paimon/flink/action/ClearConsumerActionFactory.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,72 @@ | ||
/* | ||
* 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 java.util.Optional; | ||
|
||
/** Factory to create {@link ClearConsumerAction}. */ | ||
public class ClearConsumerActionFactory implements ActionFactory { | ||
|
||
public static final String IDENTIFIER = "clear_consumers"; | ||
|
||
private static final String INCLUDING_CONSUMERS = "including_consumers"; | ||
private static final String EXCLUDING_CONSUMERS = "excluding_consumers"; | ||
|
||
@Override | ||
public String identifier() { | ||
return IDENTIFIER; | ||
} | ||
|
||
@Override | ||
public Optional<Action> create(MultipleParameterToolAdapter params) { | ||
ClearConsumerAction action = | ||
new ClearConsumerAction( | ||
params.getRequired(DATABASE), | ||
params.getRequired(TABLE), | ||
catalogConfigMap(params)); | ||
|
||
if (params.has(INCLUDING_CONSUMERS)) { | ||
action.withIncludingConsumers(params.get(INCLUDING_CONSUMERS)); | ||
} | ||
|
||
if (params.has(EXCLUDING_CONSUMERS)) { | ||
action.withExcludingConsumers(params.get(EXCLUDING_CONSUMERS)); | ||
} | ||
|
||
return Optional.of(action); | ||
} | ||
|
||
@Override | ||
public void printHelp() { | ||
System.out.println( | ||
"Action \"clear_consumers\" clear consumers with including consumers and excluding consumers."); | ||
System.out.println(); | ||
|
||
System.out.println("Syntax:"); | ||
System.out.println( | ||
" clear_consumers --warehouse <warehouse_path> --database <database_name> " | ||
+ "--table <table_name> [--including_consumers <including_pattern> --excluding_consumers <excluding_pattern>]"); | ||
|
||
System.out.println(); | ||
System.out.println("Note:"); | ||
System.out.println( | ||
" use '' as placeholder for including_consumers if you want to clear all consumers except excludingConsumers in the table."); | ||
System.out.println(); | ||
} | ||
} |
Oops, something went wrong.