-
Notifications
You must be signed in to change notification settings - Fork 936
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[core] Introduce expire_tags action and procedure with olderThan user…
… custom time (#4138)
- Loading branch information
Showing
15 changed files
with
832 additions
and
6 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
63 changes: 63 additions & 0 deletions
63
...aimon-flink-1.18/src/main/java/org/apache/paimon/flink/procedure/ExpireTagsProcedure.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,63 @@ | ||
/* | ||
* 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.catalog.Catalog; | ||
import org.apache.paimon.table.FileStoreTable; | ||
import org.apache.paimon.tag.TagTimeExpire; | ||
import org.apache.paimon.utils.DateTimeUtils; | ||
|
||
import org.apache.flink.table.procedure.ProcedureContext; | ||
|
||
import java.time.LocalDateTime; | ||
import java.util.List; | ||
import java.util.TimeZone; | ||
|
||
/** A procedure to expire tags by time. */ | ||
public class ExpireTagsProcedure extends ProcedureBase { | ||
|
||
private static final String IDENTIFIER = "expire_tags"; | ||
|
||
public String[] call(ProcedureContext procedureContext, String tableId) | ||
throws Catalog.TableNotExistException { | ||
return call(procedureContext, tableId, null); | ||
} | ||
|
||
public String[] call(ProcedureContext procedureContext, String tableId, String olderThanStr) | ||
throws Catalog.TableNotExistException { | ||
FileStoreTable fileStoreTable = (FileStoreTable) table(tableId); | ||
TagTimeExpire tagTimeExpire = | ||
fileStoreTable.store().newTagCreationManager().getTagTimeExpire(); | ||
if (olderThanStr != null) { | ||
LocalDateTime olderThanTime = | ||
DateTimeUtils.parseTimestampData(olderThanStr, 3, TimeZone.getDefault()) | ||
.toLocalDateTime(); | ||
tagTimeExpire.withOlderThanTime(olderThanTime); | ||
} | ||
List<String> expired = tagTimeExpire.expire(); | ||
return expired.isEmpty() | ||
? new String[] {"No expired tags."} | ||
: expired.toArray(new String[0]); | ||
} | ||
|
||
@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
46 changes: 46 additions & 0 deletions
46
...nk/paimon-flink-common/src/main/java/org/apache/paimon/flink/action/ExpireTagsAction.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,46 @@ | ||
/* | ||
* 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.flink.procedure.ExpireTagsProcedure; | ||
|
||
import org.apache.flink.table.procedure.DefaultProcedureContext; | ||
|
||
import java.util.Map; | ||
|
||
/** Expire tags action for Flink. */ | ||
public class ExpireTagsAction extends ActionBase { | ||
|
||
private final String table; | ||
private final String olderThan; | ||
|
||
public ExpireTagsAction( | ||
String warehouse, String table, String olderThan, Map<String, String> catalogConfig) { | ||
super(warehouse, catalogConfig); | ||
this.table = table; | ||
this.olderThan = olderThan; | ||
} | ||
|
||
@Override | ||
public void run() throws Exception { | ||
ExpireTagsProcedure expireTagsProcedure = new ExpireTagsProcedure(); | ||
expireTagsProcedure.withCatalog(catalog); | ||
expireTagsProcedure.call(new DefaultProcedureContext(env), table, olderThan); | ||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
...on-flink-common/src/main/java/org/apache/paimon/flink/action/ExpireTagsActionFactory.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,59 @@ | ||
/* | ||
* 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.Map; | ||
import java.util.Optional; | ||
|
||
/** Factory to create {@link ExpireTagsAction}. */ | ||
public class ExpireTagsActionFactory implements ActionFactory { | ||
|
||
private static final String IDENTIFIER = "expire_tags"; | ||
|
||
private static final String OLDER_THAN = "older_than"; | ||
|
||
@Override | ||
public String identifier() { | ||
return IDENTIFIER; | ||
} | ||
|
||
@Override | ||
public Optional<Action> create(MultipleParameterToolAdapter params) { | ||
String warehouse = params.get(WAREHOUSE); | ||
String table = params.get(TABLE); | ||
String olderThan = params.get(OLDER_THAN); | ||
Map<String, String> catalogConfig = optionalConfigMap(params, CATALOG_CONF); | ||
|
||
ExpireTagsAction expireTagsAction = | ||
new ExpireTagsAction(warehouse, table, olderThan, catalogConfig); | ||
return Optional.of(expireTagsAction); | ||
} | ||
|
||
@Override | ||
public void printHelp() { | ||
System.out.println("Action \"expire_tags\" expire tags by time."); | ||
System.out.println(); | ||
|
||
System.out.println("Syntax:"); | ||
System.out.println( | ||
" expire_tags --warehouse <warehouse_path> " | ||
+ "--table <database.table_name> " | ||
+ "[--older_than <older_than>]"); | ||
} | ||
} |
Oops, something went wrong.