deniskuzZ commented on code in PR #5136:
URL: https://github.com/apache/hive/pull/5136#discussion_r1539447431
##########
iceberg/iceberg-handler/src/main/java/org/apache/iceberg/mr/hive/HiveIcebergStorageHandler.java:
##########
@@ -1611,7 +1612,68 @@ public SnapshotContext
getCurrentSnapshotContext(org.apache.hadoop.hive.ql.metad
if (current == null) {
return null;
}
- return new SnapshotContext(current.snapshotId());
+ return toSnapshotContext(current);
+ }
+
+ private SnapshotContext toSnapshotContext(Snapshot snapshot) {
+ Map<String, String> summaryMap = snapshot.summary();
+ long addedRecords = getLongSummary(summaryMap,
SnapshotSummary.ADDED_RECORDS_PROP);
+ long deletedRecords = getLongSummary(summaryMap,
SnapshotSummary.DELETED_RECORDS_PROP);
+ return new SnapshotContext(
+ snapshot.snapshotId(), toWriteOperationType(snapshot.operation()),
addedRecords, deletedRecords);
+ }
+
+ private SnapshotContext.WriteOperationType toWriteOperationType(String
operation) {
+ if (DataOperations.APPEND.equals(operation)) {
+ return SnapshotContext.WriteOperationType.APPEND;
+ } else if (DataOperations.DELETE.equals(operation)) {
+ return SnapshotContext.WriteOperationType.DELETE;
+ } else if (DataOperations.OVERWRITE.equals(operation)) {
+ return SnapshotContext.WriteOperationType.OVERWRITE;
+ } else if (DataOperations.REPLACE.equals(operation)) {
+ return SnapshotContext.WriteOperationType.REPLACE;
+ } else {
+ return SnapshotContext.WriteOperationType.UNKNOWN;
+ }
+ }
+
+ private long getLongSummary(Map<String, String> summaryMap, String key) {
+ String textValue = summaryMap.get(key);
+ if (StringUtils.isBlank(textValue)) {
+ return 0;
+ }
+ return Long.parseLong(textValue);
+ }
+
+ @Override
+ public Iterable<SnapshotContext> getSnapshots(
+ org.apache.hadoop.hive.ql.metadata.Table hmsTable, SnapshotContext
since) {
+
+ TableDesc tableDesc = Utilities.getTableDesc(hmsTable);
+ Table table = IcebergTableUtil.getTable(conf, tableDesc.getProperties());
+ return getSnapshots(table.snapshots(), since);
+ }
+
+ @VisibleForTesting
+ Iterable<SnapshotContext> getSnapshots(Iterable<Snapshot> snapshots,
SnapshotContext since) {
+ List<SnapshotContext> result = Lists.newArrayList();
+
+ boolean foundSince = since == null;
+ for (Snapshot snapshot : snapshots) {
+ if (!foundSince) {
+ if (snapshot.snapshotId() == since.getSnapshotId()) {
Review Comment:
isn't snapshotId incremental? can't we use >= filter and then collect?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]