-
Notifications
You must be signed in to change notification settings - Fork 3.7k
[feat][iceberg] Support Iceberg Meta Procedure implementations #56257
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
morningman
merged 15 commits into
apache:master
from
vinlee19:support_iceberg_meta_procedure
Oct 9, 2025
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
8a11fb3
support Iceberg Meta Procedure
2b99b17
optimized code
bf87c67
fix checkstyle
1690088
fix fast forward
805b078
optimiz action regression test
eedc73f
optimiz action regression test
297006b
modify case sql
8fda9c9
modify case sql
afdeaf8
delete unused case
381b836
case
a16adaf
Update IcebergCherrypickSnapshotAction.java
vinlee19 b51edb4
Update IcebergFastForwardAction.java
vinlee19 2d0e004
Update IcebergRollbackToTimestampAction.java
vinlee19 87b4d63
Update IcebergRollbackToSnapshotAction.java
vinlee19 be10a6e
Update IcebergCherrypickSnapshotAction.java
vinlee19 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -17,13 +17,22 @@ | |
|
|
||
| package org.apache.doris.datasource.iceberg.action; | ||
|
|
||
| import org.apache.doris.catalog.Column; | ||
| import org.apache.doris.catalog.Env; | ||
| import org.apache.doris.catalog.TableIf; | ||
| import org.apache.doris.common.DdlException; | ||
| import org.apache.doris.catalog.Type; | ||
| import org.apache.doris.common.UserException; | ||
| import org.apache.doris.common.util.TimeUtils; | ||
| import org.apache.doris.datasource.ExternalTable; | ||
| import org.apache.doris.datasource.iceberg.IcebergExternalTable; | ||
| import org.apache.doris.nereids.trees.expressions.Expression; | ||
| import org.apache.doris.nereids.trees.plans.commands.info.PartitionNamesInfo; | ||
|
|
||
| import com.google.common.collect.Lists; | ||
| import org.apache.iceberg.Snapshot; | ||
| import org.apache.iceberg.Table; | ||
|
|
||
| import java.time.format.DateTimeFormatter; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
| import java.util.Optional; | ||
|
|
@@ -34,6 +43,7 @@ | |
| * at a specific timestamp. | ||
| */ | ||
| public class IcebergRollbackToTimestampAction extends BaseIcebergAction { | ||
| private static final DateTimeFormatter DATETIME_MS_FORMAT = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS"); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. must with millionsecond? |
||
| public static final String TIMESTAMP = "timestamp"; | ||
|
|
||
| public IcebergRollbackToTimestampAction(Map<String, String> properties, | ||
|
|
@@ -48,7 +58,7 @@ protected void registerIcebergArguments() { | |
| // Create a custom timestamp parser that supports both ISO datetime and | ||
| // millisecond formats | ||
| namedArguments.registerRequiredArgument(TIMESTAMP, | ||
| "A timestamp to rollback to (ISO datetime 'yyyy-MM-ddTHH:mm:ss' or milliseconds since epoch)", | ||
| "A timestamp to rollback to (formats: 'yyyy-MM-dd HH:mm:ss.SSS' or milliseconds since epoch)", | ||
| value -> { | ||
| if (value == null || value.trim().isEmpty()) { | ||
| throw new IllegalArgumentException("timestamp cannot be empty"); | ||
|
|
@@ -64,14 +74,13 @@ protected void registerIcebergArguments() { | |
| } | ||
| return trimmed; | ||
| } catch (NumberFormatException e) { | ||
| // If not a number, try as ISO datetime format | ||
| // Second attempt: Parse as ISO datetime format (yyyy-MM-dd HH:mm:ss.SSS) | ||
| try { | ||
| java.time.LocalDateTime.parse(trimmed, | ||
| java.time.format.DateTimeFormatter.ISO_LOCAL_DATE_TIME); | ||
| java.time.LocalDateTime.parse(trimmed, DATETIME_MS_FORMAT); | ||
| return trimmed; | ||
| } catch (java.time.format.DateTimeParseException dte) { | ||
| throw new IllegalArgumentException("Invalid timestamp format. Expected ISO datetime " | ||
| + "(yyyy-MM-ddTHH:mm:ss) or timestamp in milliseconds: " + trimmed); | ||
| + "(yyyy-MM-dd HH:mm:ss.SSS) or timestamp in milliseconds: " + trimmed); | ||
| } | ||
| } | ||
| }); | ||
|
|
@@ -87,7 +96,38 @@ protected void validateIcebergAction() throws UserException { | |
|
|
||
| @Override | ||
| protected List<String> executeAction(TableIf table) throws UserException { | ||
| throw new DdlException("Iceberg rollback_to_timestamp procedure is not implemented yet"); | ||
| Table icebergTable = ((IcebergExternalTable) table).getIcebergTable(); | ||
|
|
||
| String timestampStr = namedArguments.getString(TIMESTAMP); | ||
|
|
||
| Snapshot previousSnapshot = icebergTable.currentSnapshot(); | ||
| Long previousSnapshotId = previousSnapshot != null ? previousSnapshot.snapshotId() : null; | ||
|
|
||
| try { | ||
| long targetTimestamp = TimeUtils.msTimeStringToLong(timestampStr, TimeUtils.getTimeZone()); | ||
| icebergTable.manageSnapshots().rollbackToTime(targetTimestamp).commit(); | ||
|
|
||
| Snapshot currentSnapshot = icebergTable.currentSnapshot(); | ||
| Long currentSnapshotId = currentSnapshot != null ? currentSnapshot.snapshotId() : null; | ||
| // invalid iceberg catalog table cache. | ||
| Env.getCurrentEnv().getExtMetaCacheMgr().invalidateTableCache((ExternalTable) table); | ||
| return Lists.newArrayList( | ||
| String.valueOf(previousSnapshotId), | ||
| String.valueOf(currentSnapshotId) | ||
| ); | ||
|
|
||
| } catch (Exception e) { | ||
| throw new UserException("Failed to rollback to timestamp " + timestampStr + ": " + e.getMessage(), e); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| protected List<Column> getResultSchema() { | ||
| return Lists.newArrayList( | ||
| new Column("previous_snapshot_id", Type.BIGINT, false, | ||
| "ID of the snapshot that was current before the rollback operation"), | ||
| new Column("current_snapshot_id", Type.BIGINT, false, | ||
| "ID of the snapshot that was current at the specified timestamp and is now set as current")); | ||
| } | ||
|
|
||
| @Override | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.