-
Notifications
You must be signed in to change notification settings - Fork 1k
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
[core] Refactor MetastoreClient methods to simplify catalog #4726
Merged
JingsongLi
merged 4 commits into
apache:master
from
JingsongLi:refactor_MetastoreClient
Dec 17, 2024
Merged
Changes from 3 commits
Commits
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 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
64 changes: 64 additions & 0 deletions
64
paimon-core/src/main/java/org/apache/paimon/metastore/PartitionStats.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,64 @@ | ||
/* | ||
* 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.metastore; | ||
|
||
/** Statistic for partition. */ | ||
public interface PartitionStats { | ||
|
||
long numFiles(); | ||
|
||
long totalSize(); | ||
|
||
long numRows(); | ||
|
||
long lastUpdateTimeMillis(); | ||
|
||
static PartitionStats create( | ||
long numFiles, long totalSize, long numRows, long lastUpdateTimeMillis) { | ||
return new PartitionStats() { | ||
|
||
@Override | ||
public long numFiles() { | ||
return numFiles; | ||
} | ||
|
||
@Override | ||
public long totalSize() { | ||
return totalSize; | ||
} | ||
|
||
@Override | ||
public long numRows() { | ||
return numRows; | ||
} | ||
|
||
@Override | ||
public long lastUpdateTimeMillis() { | ||
return lastUpdateTimeMillis; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return String.format( | ||
"numFiles: %s, totalSize: %s, numRows: %s, lastUpdateTimeMillis: %s", | ||
numFiles, totalSize, numRows, lastUpdateTimeMillis); | ||
} | ||
}; | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,7 @@ | |
import org.apache.paimon.fs.Path; | ||
import org.apache.paimon.io.DataFileMeta; | ||
import org.apache.paimon.metastore.MetastoreClient; | ||
import org.apache.paimon.metastore.PartitionStats; | ||
import org.apache.paimon.table.FileStoreTable; | ||
import org.apache.paimon.table.source.DataSplit; | ||
import org.apache.paimon.table.source.ScanMode; | ||
|
@@ -35,24 +36,16 @@ | |
import java.io.Closeable; | ||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.LinkedHashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import static org.apache.paimon.catalog.Catalog.LAST_UPDATE_TIME_PROP; | ||
import static org.apache.paimon.catalog.Catalog.NUM_FILES_PROP; | ||
import static org.apache.paimon.catalog.Catalog.NUM_ROWS_PROP; | ||
import static org.apache.paimon.catalog.Catalog.TOTAL_SIZE_PROP; | ||
import static org.apache.paimon.utils.PartitionPathUtils.extractPartitionSpecFromPath; | ||
|
||
/** Action to report the table statistic from the latest snapshot to HMS. */ | ||
public class PartitionStatisticsReporter implements Closeable { | ||
|
||
private static final Logger LOG = LoggerFactory.getLogger(PartitionStatisticsReporter.class); | ||
|
||
private static final String HIVE_LAST_UPDATE_TIME_PROP = "transient_lastDdlTime"; | ||
|
||
private final MetastoreClient metastoreClient; | ||
private final SnapshotReader snapshotReader; | ||
private final SnapshotManager snapshotManager; | ||
|
@@ -64,7 +57,7 @@ public PartitionStatisticsReporter(FileStoreTable table, MetastoreClient client) | |
this.snapshotManager = table.snapshotManager(); | ||
} | ||
|
||
public void report(String partition, long modifyTime) throws Exception { | ||
public void report(String partition, long modifyTimeMillis) throws Exception { | ||
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. modifyTimeInMillis 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. See |
||
Snapshot snapshot = snapshotManager.latestSnapshot(); | ||
if (snapshot != null) { | ||
LinkedHashMap<String, String> partitionSpec = | ||
|
@@ -88,19 +81,11 @@ public void report(String partition, long modifyTime) throws Exception { | |
totalSize += fileMeta.fileSize(); | ||
} | ||
} | ||
Map<String, String> statistic = new HashMap<>(); | ||
statistic.put(NUM_FILES_PROP, String.valueOf(fileCount)); | ||
statistic.put(TOTAL_SIZE_PROP, String.valueOf(totalSize)); | ||
statistic.put(NUM_ROWS_PROP, String.valueOf(rowCount)); | ||
|
||
String modifyTimeSeconds = String.valueOf(modifyTime / 1000); | ||
statistic.put(LAST_UPDATE_TIME_PROP, modifyTimeSeconds); | ||
|
||
// just for being compatible with hive metastore | ||
statistic.put(HIVE_LAST_UPDATE_TIME_PROP, modifyTimeSeconds); | ||
|
||
LOG.info("alter partition {} with statistic {}.", partitionSpec, statistic); | ||
metastoreClient.alterPartition(partitionSpec, statistic, modifyTime, true); | ||
PartitionStats partitionStats = | ||
PartitionStats.create(fileCount, totalSize, rowCount, modifyTimeMillis); | ||
LOG.info("alter partition {} with statistic {}.", partitionSpec, partitionStats); | ||
metastoreClient.alterPartition(partitionSpec, partitionStats); | ||
} | ||
} | ||
|
||
|
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.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
addPartitions?not dropPartitions?