You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@iceberg.apache.org by "saitharun15 (via GitHub)" <gi...@apache.org> on 2024/11/21 07:24:08 UTC
[PR] Spark : Derive Stats From Manifest on the Fly [iceberg]
saitharun15 opened a new pull request, #11615:
URL: https://github.com/apache/iceberg/pull/11615
This PR helps to derives min,max,numOfNulls Statistics on the fly from manifest files to report back them to Spark.
Currently only Ndv is calculated and reported back to Spark Engine, which leads to [inaccurate plans](https://github.com/apache/iceberg/pull/10659#issuecomment-2252176015) in Spark side since min,max,nullCount are returned as NULL
As there is a discussion still going on whether to store stats partition level or table level, even if we calculate them in either ways there would be an issue as per this [comment](https://github.com/apache/iceberg/issues/10791#issuecomment-2326424328) in discussion #10791
These changes helps to enable the onFly collection of the stats using a table property or a session conf(by default it's false)
cc @guykhazma @jeesou
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Spark : Derive Stats From Manifest on the Fly [iceberg]
Posted by "guykhazma (via GitHub)" <gi...@apache.org>.
guykhazma commented on PR #11615:
URL: https://github.com/apache/iceberg/pull/11615#issuecomment-2574163828
@huaxingao @RussellSpitzer friendly remainder, can you please review this PR.
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Spark : Derive Stats From Manifest on the Fly [iceberg]
Posted by "RussellSpitzer (via GitHub)" <gi...@apache.org>.
RussellSpitzer commented on code in PR #11615:
URL: https://github.com/apache/iceberg/pull/11615#discussion_r1852421521
##########
spark/v3.5/spark/src/main/java/org/apache/iceberg/spark/source/SparkScan.java:
##########
@@ -194,10 +205,40 @@ protected Statistics estimateStatistics(Snapshot snapshot) {
Map<NamedReference, ColumnStatistics> colStatsMap = Collections.emptyMap();
if (readConf.reportColumnStats() && cboEnabled) {
colStatsMap = Maps.newHashMap();
+ Map<Integer, Long> ndvs = Maps.newHashMap();
+ Map<Integer, Long> nullCounts = Maps.newHashMap();
+ Map<Integer, Object> minValues = Maps.newHashMap();
+ Map<Integer, Object> maxValues = Maps.newHashMap();
List<StatisticsFile> files = table.statisticsFiles();
if (!files.isEmpty()) {
List<BlobMetadata> metadataList = (files.get(0)).blobMetadata();
+ if (readConf.deriveStatsFromManifestSessionConf()
+ || readConf.deriveStatsFromManifestTableProperty()) {
+ Map<String, Map<Integer, Long>> distinctDataFilesNullCount = Maps.newHashMap();
Review Comment:
what does "distinct" in this context mean?
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Spark : Derive Stats From Manifest on the Fly [iceberg]
Posted by "guykhazma (via GitHub)" <gi...@apache.org>.
guykhazma commented on code in PR #11615:
URL: https://github.com/apache/iceberg/pull/11615#discussion_r1854912088
##########
spark/v3.5/spark/src/main/java/org/apache/iceberg/spark/source/SparkScan.java:
##########
@@ -248,6 +296,88 @@ protected Statistics estimateStatistics(Snapshot snapshot) {
return new Stats(sizeInBytes, rowsCount, colStatsMap);
}
+ private Map<Integer, Long> calculateNullCount(
+ Map<String, Map<Integer, Long>> distinctDataFilesNullCount) {
+ Map<Integer, Long> nullCount;
+ // get the null counts from the manifest file
+ nullCount =
+ distinctDataFilesNullCount.values().stream() // Stream<Map<Integer, Long>>
+ .flatMap(
+ innerMap ->
+ innerMap.entrySet().stream()) // Flatten to Stream<Map.Entry<Integer, Long>>
+ .collect(
+ Collectors.toMap(
+ Map.Entry::getKey, // Key is the column id
+ Map.Entry::getValue,
+ Long::sum,
+ HashMap::new));
+ return nullCount;
+ }
+
+ private Object toSparkType(Type type, Object value) {
Review Comment:
@RussellSpitzer we saw a similar conversion in the `BaseReader`:
https://github.com/apache/iceberg/blob/f2b1b91d304039027333570451477e7575f7d39d/spark/v3.3/spark/src/main/java/org/apache/iceberg/spark/source/BaseReader.java#L217
However, it is not extracted to some helper function. And in this case we don't need the logic for Strings/Binary as strings are not supported and binary don't support min/max
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Spark : Derive Stats From Manifest on the Fly [iceberg]
Posted by "RussellSpitzer (via GitHub)" <gi...@apache.org>.
RussellSpitzer commented on code in PR #11615:
URL: https://github.com/apache/iceberg/pull/11615#discussion_r1852403873
##########
spark/v3.5/spark/src/main/java/org/apache/iceberg/spark/source/SparkScan.java:
##########
@@ -248,6 +296,88 @@ protected Statistics estimateStatistics(Snapshot snapshot) {
return new Stats(sizeInBytes, rowsCount, colStatsMap);
}
+ private Map<Integer, Long> calculateNullCount(
+ Map<String, Map<Integer, Long>> distinctDataFilesNullCount) {
+ Map<Integer, Long> nullCount;
+ // get the null counts from the manifest file
+ nullCount =
+ distinctDataFilesNullCount.values().stream() // Stream<Map<Integer, Long>>
+ .flatMap(
+ innerMap ->
+ innerMap.entrySet().stream()) // Flatten to Stream<Map.Entry<Integer, Long>>
+ .collect(
+ Collectors.toMap(
+ Map.Entry::getKey, // Key is the column id
+ Map.Entry::getValue,
+ Long::sum,
+ HashMap::new));
+ return nullCount;
+ }
+
+ private Object toSparkType(Type type, Object value) {
+ switch (type.typeId()) {
+ case DECIMAL:
+ return Decimal.apply((BigDecimal) value);
+ default:
+ }
+ return value;
+ }
+
+ // min/max are calculated for numeric, Date, and Timestamp only
+ private boolean isValidMinMaxType(Type type) {
+ switch (type.typeId()) {
+ case DATE:
+ case TIMESTAMP:
+ case INTEGER:
+ case LONG:
+ case FLOAT:
+ case DOUBLE:
+ case DECIMAL:
+ case BOOLEAN:
+ return true;
+ default:
+ return false;
+ }
+ }
+
+ // extract min/max values from the manifests
+ private Map<Integer, Object> calculateMinMax(
+ boolean isMin, Map<String, Map<Integer, ByteBuffer>> distinctDataFilesBounds) {
Review Comment:
I'm not a big fan of parmeterizing "isMin", i'd probably just use two different functions that call a more generic version so that the code in the original calling location is clear and you don't have to know that "true" means "min"
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Spark : Derive Stats From Manifest on the Fly [iceberg]
Posted by "guykhazma (via GitHub)" <gi...@apache.org>.
guykhazma commented on PR #11615:
URL: https://github.com/apache/iceberg/pull/11615#issuecomment-2511446282
@RussellSpitzer @huaxingao Just a friendly reminder to review the changes when you have a chance. Thanks!
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Spark : Derive Stats From Manifest on the Fly [iceberg]
Posted by "saitharun15 (via GitHub)" <gi...@apache.org>.
saitharun15 commented on PR #11615:
URL: https://github.com/apache/iceberg/pull/11615#issuecomment-2532200924
Hi @RussellSpitzer ,@huaxingao can u please review the pr once, Thanks!
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Spark : Derive Stats From Manifest on the Fly [iceberg]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #11615:
URL: https://github.com/apache/iceberg/pull/11615#issuecomment-2702375969
This pull request has been closed due to lack of activity. This is not a judgement on the merit of the PR in any way. It is just a way of keeping the PR queue manageable. If you think that is incorrect, or the pull request requires review, you can revive the PR at any time.
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Spark : Derive Stats From Manifest on the Fly [iceberg]
Posted by "RussellSpitzer (via GitHub)" <gi...@apache.org>.
RussellSpitzer commented on code in PR #11615:
URL: https://github.com/apache/iceberg/pull/11615#discussion_r1852423636
##########
spark/v3.5/spark/src/main/java/org/apache/iceberg/spark/source/SparkScan.java:
##########
@@ -183,6 +193,7 @@ public Statistics estimateStatistics() {
return estimateStatistics(SnapshotUtil.latestSnapshot(table, branch));
}
+ @SuppressWarnings("checkstyle:CyclomaticComplexity")
Review Comment:
Let's try to reduce the complexity rather than suppressing the warning
General this means
Removing nesting
Extracting sub-functions out
Avoiding early exits
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Spark : Derive Stats From Manifest on the Fly [iceberg]
Posted by "saitharun15 (via GitHub)" <gi...@apache.org>.
saitharun15 commented on code in PR #11615:
URL: https://github.com/apache/iceberg/pull/11615#discussion_r1854296151
##########
spark/v3.5/spark/src/main/java/org/apache/iceberg/spark/source/SparkScan.java:
##########
@@ -194,10 +205,40 @@ protected Statistics estimateStatistics(Snapshot snapshot) {
Map<NamedReference, ColumnStatistics> colStatsMap = Collections.emptyMap();
if (readConf.reportColumnStats() && cboEnabled) {
colStatsMap = Maps.newHashMap();
+ Map<Integer, Long> ndvs = Maps.newHashMap();
+ Map<Integer, Long> nullCounts = Maps.newHashMap();
+ Map<Integer, Object> minValues = Maps.newHashMap();
+ Map<Integer, Object> maxValues = Maps.newHashMap();
List<StatisticsFile> files = table.statisticsFiles();
if (!files.isEmpty()) {
List<BlobMetadata> metadataList = (files.get(0)).blobMetadata();
+ if (readConf.deriveStatsFromManifestSessionConf()
+ || readConf.deriveStatsFromManifestTableProperty()) {
+ Map<String, Map<Integer, Long>> distinctDataFilesNullCount = Maps.newHashMap();
Review Comment:
We observed a scenario where different FileScanTask objects in the taskGroup were pointing to the same data file, causing duplicates. I used putIfAbsent to ensure a single entry per file and renamed the maps to distinctDataFiles. However after switching to collect FileScanTask objects as a set, putIfAbsent is no longer needed. @RussellSpitzer , can you please suggest if there is an alternate approach?
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Spark : Derive Stats From Manifest on the Fly [iceberg]
Posted by "saitharun15 (via GitHub)" <gi...@apache.org>.
saitharun15 commented on PR #11615:
URL: https://github.com/apache/iceberg/pull/11615#issuecomment-2490258926
Hi, @huaxingao @karuppayya @aokolnychyi @RussellSpitzer Can you help review this PR
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Spark : Derive Stats From Manifest on the Fly [iceberg]
Posted by "guykhazma (via GitHub)" <gi...@apache.org>.
guykhazma commented on PR #11615:
URL: https://github.com/apache/iceberg/pull/11615#issuecomment-2502221330
@huaxingao yes, it is possible to reuse the logic from the aggregate pushdown by reusing the AggregateEvaluator instead of the current code to aggregate from the manifests. Something along these lines:
```Java
List<Expression> expressions = table.schema().columns().stream()
.map(field -> {
String colName = field.name(); // Extract the column name
// Create expressions for max and min non-null count
return List.of(
Expressions.min(colName),
Expressions.max(colName),
Expressions.count(colName)
);
})
.flatMap(List::stream) // Flatten the lists into a single stream
.collect(Collectors.toList());
AggregateEvaluator aggregateEvaluator = AggregateEvaluator.create(table.schema(),
expressions);
for (FileScanTask task : fileScanTasks) {
aggregateEvaluator.update(task.file());
}
if (!aggregateEvaluator.allAggregatorsValid()) {
return;
}
// get the total row count to compute the number of null rows
long rowsCount = taskGroups().stream().mapToLong(ScanTaskGroup::estimatedRowsCount).sum();
// populate the map with the results
StructLike res = aggregateEvaluator.result();
IntStream.range(0, table.schema().columns().size())
.forEach(i -> {
minValues.put(table.schema().columns().get(i).fieldId(), res.get(i*3, Object.class));
maxValues.put(table.schema().columns().get(i).fieldId(), res.get(i*3 + 1, Object.class));
nullCounts.put(table.schema().columns().get(i).fieldId(),
rowsCount - res.get(i*3 + 2, Long.class));
});
```
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Spark : Derive Stats From Manifest on the Fly [iceberg]
Posted by "RussellSpitzer (via GitHub)" <gi...@apache.org>.
RussellSpitzer commented on code in PR #11615:
URL: https://github.com/apache/iceberg/pull/11615#discussion_r1852425556
##########
spark/v3.5/spark/src/main/java/org/apache/iceberg/spark/SparkReadConf.java:
##########
@@ -355,4 +355,21 @@ public boolean reportColumnStats() {
.defaultValue(SparkSQLProperties.REPORT_COLUMN_STATS_DEFAULT)
.parse();
}
+
+ public boolean deriveStatsFromManifestSessionConf() {
+ return confParser
+ .booleanConf()
+ .sessionConf(SparkSQLProperties.DERIVE_STATS_FROM_MANIFEST_ENABLED)
+ .defaultValue(SparkSQLProperties.DERIVE_STATS_FROM_MANIFEST_ENABLED_DEFAULT)
+ .parse();
+ }
+
+ public boolean deriveStatsFromManifestTableProperty() {
Review Comment:
Why do we need two functions here? You should be able to add all the options into the same conf parser while still maintaining this hierarchy
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Spark : Derive Stats From Manifest on the Fly [iceberg]
Posted by "saitharun15 (via GitHub)" <gi...@apache.org>.
saitharun15 commented on code in PR #11615:
URL: https://github.com/apache/iceberg/pull/11615#discussion_r1854296151
##########
spark/v3.5/spark/src/main/java/org/apache/iceberg/spark/source/SparkScan.java:
##########
@@ -194,10 +205,40 @@ protected Statistics estimateStatistics(Snapshot snapshot) {
Map<NamedReference, ColumnStatistics> colStatsMap = Collections.emptyMap();
if (readConf.reportColumnStats() && cboEnabled) {
colStatsMap = Maps.newHashMap();
+ Map<Integer, Long> ndvs = Maps.newHashMap();
+ Map<Integer, Long> nullCounts = Maps.newHashMap();
+ Map<Integer, Object> minValues = Maps.newHashMap();
+ Map<Integer, Object> maxValues = Maps.newHashMap();
List<StatisticsFile> files = table.statisticsFiles();
if (!files.isEmpty()) {
List<BlobMetadata> metadataList = (files.get(0)).blobMetadata();
+ if (readConf.deriveStatsFromManifestSessionConf()
+ || readConf.deriveStatsFromManifestTableProperty()) {
+ Map<String, Map<Integer, Long>> distinctDataFilesNullCount = Maps.newHashMap();
Review Comment:
We observed a scenario wheredifferent FileScanTask objects in the taskGroup were pointing to the same data file, causing duplicates. I used putIfAbsent to ensure a single entry per file and renamed the maps to distinctDataFiles. However after switching to collect FileScanTask objects as a set, putIfAbsent is no longer needed. @RussellSpitzer , can you suggest if there is an alternate approach?
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Spark : Derive Stats From Manifest on the Fly [iceberg]
Posted by "saitharun15 (via GitHub)" <gi...@apache.org>.
saitharun15 commented on code in PR #11615:
URL: https://github.com/apache/iceberg/pull/11615#discussion_r1854320423
##########
spark/v3.5/spark/src/main/java/org/apache/iceberg/spark/source/SparkScan.java:
##########
@@ -194,10 +205,40 @@ protected Statistics estimateStatistics(Snapshot snapshot) {
Map<NamedReference, ColumnStatistics> colStatsMap = Collections.emptyMap();
if (readConf.reportColumnStats() && cboEnabled) {
colStatsMap = Maps.newHashMap();
+ Map<Integer, Long> ndvs = Maps.newHashMap();
+ Map<Integer, Long> nullCounts = Maps.newHashMap();
+ Map<Integer, Object> minValues = Maps.newHashMap();
+ Map<Integer, Object> maxValues = Maps.newHashMap();
List<StatisticsFile> files = table.statisticsFiles();
if (!files.isEmpty()) {
List<BlobMetadata> metadataList = (files.get(0)).blobMetadata();
+ if (readConf.deriveStatsFromManifestSessionConf()
+ || readConf.deriveStatsFromManifestTableProperty()) {
+ Map<String, Map<Integer, Long>> distinctDataFilesNullCount = Maps.newHashMap();
+ Map<String, Map<Integer, ByteBuffer>> distinctDataFilesMin = Maps.newHashMap();
+ Map<String, Map<Integer, ByteBuffer>> distinctDataFilesMax = Maps.newHashMap();
+
+ // extract the distinct files which are part of the task planning
+ for (ScanTaskGroup<?> taskGrp : taskGroups()) {
+ for (ScanTask task : taskGrp.tasks()) {
+ if (task.isFileScanTask()) {
+ FileScanTask fileScanTask = task.asFileScanTask();
Review Comment:
Updated to collect fileScanTasks into a set, Thanks!
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Spark : Derive Stats From Manifest on the Fly [iceberg]
Posted by "RussellSpitzer (via GitHub)" <gi...@apache.org>.
RussellSpitzer commented on code in PR #11615:
URL: https://github.com/apache/iceberg/pull/11615#discussion_r1852437532
##########
spark/v3.5/spark/src/main/java/org/apache/iceberg/spark/source/SparkScan.java:
##########
@@ -194,10 +205,40 @@ protected Statistics estimateStatistics(Snapshot snapshot) {
Map<NamedReference, ColumnStatistics> colStatsMap = Collections.emptyMap();
if (readConf.reportColumnStats() && cboEnabled) {
colStatsMap = Maps.newHashMap();
+ Map<Integer, Long> ndvs = Maps.newHashMap();
+ Map<Integer, Long> nullCounts = Maps.newHashMap();
+ Map<Integer, Object> minValues = Maps.newHashMap();
+ Map<Integer, Object> maxValues = Maps.newHashMap();
List<StatisticsFile> files = table.statisticsFiles();
if (!files.isEmpty()) {
List<BlobMetadata> metadataList = (files.get(0)).blobMetadata();
+ if (readConf.deriveStatsFromManifestSessionConf()
+ || readConf.deriveStatsFromManifestTableProperty()) {
+ Map<String, Map<Integer, Long>> distinctDataFilesNullCount = Maps.newHashMap();
+ Map<String, Map<Integer, ByteBuffer>> distinctDataFilesMin = Maps.newHashMap();
+ Map<String, Map<Integer, ByteBuffer>> distinctDataFilesMax = Maps.newHashMap();
+
+ // extract the distinct files which are part of the task planning
+ for (ScanTaskGroup<?> taskGrp : taskGroups()) {
+ for (ScanTask task : taskGrp.tasks()) {
+ if (task.isFileScanTask()) {
+ FileScanTask fileScanTask = task.asFileScanTask();
Review Comment:
Could we just make a set of files being used?
Stream.of(tasks).filter(fl.isFileScanTask).map(file).collectAsSet
Then we could just work on the set for all of our min and max functions
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Spark : Derive Stats From Manifest on the Fly [iceberg]
Posted by "huaxingao (via GitHub)" <gi...@apache.org>.
huaxingao commented on PR #11615:
URL: https://github.com/apache/iceberg/pull/11615#issuecomment-2615031769
Sorry, I've been really busy recently. I'll try to take a look soon.
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Spark : Derive Stats From Manifest on the Fly [iceberg]
Posted by "guykhazma (via GitHub)" <gi...@apache.org>.
guykhazma commented on code in PR #11615:
URL: https://github.com/apache/iceberg/pull/11615#discussion_r1854912088
##########
spark/v3.5/spark/src/main/java/org/apache/iceberg/spark/source/SparkScan.java:
##########
@@ -248,6 +296,88 @@ protected Statistics estimateStatistics(Snapshot snapshot) {
return new Stats(sizeInBytes, rowsCount, colStatsMap);
}
+ private Map<Integer, Long> calculateNullCount(
+ Map<String, Map<Integer, Long>> distinctDataFilesNullCount) {
+ Map<Integer, Long> nullCount;
+ // get the null counts from the manifest file
+ nullCount =
+ distinctDataFilesNullCount.values().stream() // Stream<Map<Integer, Long>>
+ .flatMap(
+ innerMap ->
+ innerMap.entrySet().stream()) // Flatten to Stream<Map.Entry<Integer, Long>>
+ .collect(
+ Collectors.toMap(
+ Map.Entry::getKey, // Key is the column id
+ Map.Entry::getValue,
+ Long::sum,
+ HashMap::new));
+ return nullCount;
+ }
+
+ private Object toSparkType(Type type, Object value) {
Review Comment:
@RussellSpitzer we saw a similar conversion in the `BaseReader`:
https://github.com/apache/iceberg/blob/f2b1b91d304039027333570451477e7575f7d39d/spark/v3.5/spark/src/main/java/org/apache/iceberg/spark/source/BaseReader.java#L209
However, it is not extracted to some helper function. And in this case we don't need the logic for Strings/Binary as strings are not supported and binary don't support min/max
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Spark : Derive Stats From Manifest on the Fly [iceberg]
Posted by "saitharun15 (via GitHub)" <gi...@apache.org>.
saitharun15 commented on code in PR #11615:
URL: https://github.com/apache/iceberg/pull/11615#discussion_r1855092790
##########
spark/v3.5/spark/src/main/java/org/apache/iceberg/spark/source/SparkScan.java:
##########
@@ -194,10 +205,40 @@ protected Statistics estimateStatistics(Snapshot snapshot) {
Map<NamedReference, ColumnStatistics> colStatsMap = Collections.emptyMap();
if (readConf.reportColumnStats() && cboEnabled) {
colStatsMap = Maps.newHashMap();
+ Map<Integer, Long> ndvs = Maps.newHashMap();
+ Map<Integer, Long> nullCounts = Maps.newHashMap();
+ Map<Integer, Object> minValues = Maps.newHashMap();
+ Map<Integer, Object> maxValues = Maps.newHashMap();
List<StatisticsFile> files = table.statisticsFiles();
if (!files.isEmpty()) {
List<BlobMetadata> metadataList = (files.get(0)).blobMetadata();
+ if (readConf.deriveStatsFromManifestSessionConf()
+ || readConf.deriveStatsFromManifestTableProperty()) {
+ Map<String, Map<Integer, Long>> distinctDataFilesNullCount = Maps.newHashMap();
Review Comment:
Updated to collect data files into a set and renamed the variables, Thanks!
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Spark : Derive Stats From Manifest on the Fly [iceberg]
Posted by "saitharun15 (via GitHub)" <gi...@apache.org>.
saitharun15 commented on code in PR #11615:
URL: https://github.com/apache/iceberg/pull/11615#discussion_r1854296151
##########
spark/v3.5/spark/src/main/java/org/apache/iceberg/spark/source/SparkScan.java:
##########
@@ -194,10 +205,40 @@ protected Statistics estimateStatistics(Snapshot snapshot) {
Map<NamedReference, ColumnStatistics> colStatsMap = Collections.emptyMap();
if (readConf.reportColumnStats() && cboEnabled) {
colStatsMap = Maps.newHashMap();
+ Map<Integer, Long> ndvs = Maps.newHashMap();
+ Map<Integer, Long> nullCounts = Maps.newHashMap();
+ Map<Integer, Object> minValues = Maps.newHashMap();
+ Map<Integer, Object> maxValues = Maps.newHashMap();
List<StatisticsFile> files = table.statisticsFiles();
if (!files.isEmpty()) {
List<BlobMetadata> metadataList = (files.get(0)).blobMetadata();
+ if (readConf.deriveStatsFromManifestSessionConf()
+ || readConf.deriveStatsFromManifestTableProperty()) {
+ Map<String, Map<Integer, Long>> distinctDataFilesNullCount = Maps.newHashMap();
Review Comment:
We observed a scenario where different FileScanTask objects in the taskGroup were pointing to the same data file, causing duplicates. I used putIfAbsent to ensure a single entry per file and renamed the maps to distinctDataFiles. However after switching to collect FileScanTask objects as a set, putIfAbsent is no longer needed. @RussellSpitzer , can you suggest if there is an alternate approach?
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Spark : Derive Stats From Manifest on the Fly [iceberg]
Posted by "saitharun15 (via GitHub)" <gi...@apache.org>.
saitharun15 commented on code in PR #11615:
URL: https://github.com/apache/iceberg/pull/11615#discussion_r1852219386
##########
spark/v3.5/spark/src/main/java/org/apache/iceberg/spark/SparkReadConf.java:
##########
@@ -355,4 +355,21 @@ public boolean reportColumnStats() {
.defaultValue(SparkSQLProperties.REPORT_COLUMN_STATS_DEFAULT)
.parse();
}
+
+ public boolean deriveStatsFromManifestSessionConf() {
+ return confParser
+ .booleanConf()
+ .sessionConf(SparkSQLProperties.DERIVE_STATS_FROM_MANIFEST_ENABLED)
+ .defaultValue(SparkSQLProperties.DERIVE_STATS_FROM_MANIFEST_ENABLED_DEFAULT)
+ .parse();
+ }
+
+ public boolean deriveStatsFromManifestTableProperty() {
+ return confParser
+ .booleanConf()
+ .option(SparkReadOptions.DERIVE_STATS_FROM_MANIFEST_ENABLED)
+ .tableProperty(TableProperties.DERIVE_STATS_FROM_MANIFEST_ENABLED)
+ .defaultValue(TableProperties.DERIVE_STATS_FROM_MANIFEST_ENABLED_DEFAULT)
+ .parse();
+ }
Review Comment:
This table-level property takes precedence over the session configuration when it is turned off, enabling users to derive statistics only for a specific table.
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Spark : Derive Stats From Manifest on the Fly [iceberg]
Posted by "saitharun15 (via GitHub)" <gi...@apache.org>.
saitharun15 commented on code in PR #11615:
URL: https://github.com/apache/iceberg/pull/11615#discussion_r1854296151
##########
spark/v3.5/spark/src/main/java/org/apache/iceberg/spark/source/SparkScan.java:
##########
@@ -194,10 +205,40 @@ protected Statistics estimateStatistics(Snapshot snapshot) {
Map<NamedReference, ColumnStatistics> colStatsMap = Collections.emptyMap();
if (readConf.reportColumnStats() && cboEnabled) {
colStatsMap = Maps.newHashMap();
+ Map<Integer, Long> ndvs = Maps.newHashMap();
+ Map<Integer, Long> nullCounts = Maps.newHashMap();
+ Map<Integer, Object> minValues = Maps.newHashMap();
+ Map<Integer, Object> maxValues = Maps.newHashMap();
List<StatisticsFile> files = table.statisticsFiles();
if (!files.isEmpty()) {
List<BlobMetadata> metadataList = (files.get(0)).blobMetadata();
+ if (readConf.deriveStatsFromManifestSessionConf()
+ || readConf.deriveStatsFromManifestTableProperty()) {
+ Map<String, Map<Integer, Long>> distinctDataFilesNullCount = Maps.newHashMap();
Review Comment:
We found that different FileScanTask objects in the taskGroup were pointing to the same data file, causing duplicates. I used putIfAbsent to ensure a single entry per file and renamed the maps to distinctDataFiles. However after switching to collect FileScanTask objects as a set, putIfAbsent is no longer needed. @RussellSpitzer , can you suggest if there is an alternate approach?
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Spark : Derive Stats From Manifest on the Fly [iceberg]
Posted by "saitharun15 (via GitHub)" <gi...@apache.org>.
saitharun15 commented on code in PR #11615:
URL: https://github.com/apache/iceberg/pull/11615#discussion_r1854320423
##########
spark/v3.5/spark/src/main/java/org/apache/iceberg/spark/source/SparkScan.java:
##########
@@ -194,10 +205,40 @@ protected Statistics estimateStatistics(Snapshot snapshot) {
Map<NamedReference, ColumnStatistics> colStatsMap = Collections.emptyMap();
if (readConf.reportColumnStats() && cboEnabled) {
colStatsMap = Maps.newHashMap();
+ Map<Integer, Long> ndvs = Maps.newHashMap();
+ Map<Integer, Long> nullCounts = Maps.newHashMap();
+ Map<Integer, Object> minValues = Maps.newHashMap();
+ Map<Integer, Object> maxValues = Maps.newHashMap();
List<StatisticsFile> files = table.statisticsFiles();
if (!files.isEmpty()) {
List<BlobMetadata> metadataList = (files.get(0)).blobMetadata();
+ if (readConf.deriveStatsFromManifestSessionConf()
+ || readConf.deriveStatsFromManifestTableProperty()) {
+ Map<String, Map<Integer, Long>> distinctDataFilesNullCount = Maps.newHashMap();
+ Map<String, Map<Integer, ByteBuffer>> distinctDataFilesMin = Maps.newHashMap();
+ Map<String, Map<Integer, ByteBuffer>> distinctDataFilesMax = Maps.newHashMap();
+
+ // extract the distinct files which are part of the task planning
+ for (ScanTaskGroup<?> taskGrp : taskGroups()) {
+ for (ScanTask task : taskGrp.tasks()) {
+ if (task.isFileScanTask()) {
+ FileScanTask fileScanTask = task.asFileScanTask();
Review Comment:
Updated to collect dataFiles into a set, Thanks!
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Spark : Derive Stats From Manifest on the Fly [iceberg]
Posted by "RussellSpitzer (via GitHub)" <gi...@apache.org>.
RussellSpitzer commented on code in PR #11615:
URL: https://github.com/apache/iceberg/pull/11615#discussion_r1852418237
##########
spark/v3.5/spark/src/main/java/org/apache/iceberg/spark/source/SparkScan.java:
##########
@@ -248,6 +296,88 @@ protected Statistics estimateStatistics(Snapshot snapshot) {
return new Stats(sizeInBytes, rowsCount, colStatsMap);
}
+ private Map<Integer, Long> calculateNullCount(
+ Map<String, Map<Integer, Long>> distinctDataFilesNullCount) {
+ Map<Integer, Long> nullCount;
+ // get the null counts from the manifest file
+ nullCount =
+ distinctDataFilesNullCount.values().stream() // Stream<Map<Integer, Long>>
+ .flatMap(
+ innerMap ->
+ innerMap.entrySet().stream()) // Flatten to Stream<Map.Entry<Integer, Long>>
+ .collect(
+ Collectors.toMap(
+ Map.Entry::getKey, // Key is the column id
+ Map.Entry::getValue,
+ Long::sum,
+ HashMap::new));
+ return nullCount;
+ }
+
+ private Object toSparkType(Type type, Object value) {
+ switch (type.typeId()) {
+ case DECIMAL:
+ return Decimal.apply((BigDecimal) value);
+ default:
+ }
+ return value;
+ }
+
+ // min/max are calculated for numeric, Date, and Timestamp only
+ private boolean isValidMinMaxType(Type type) {
+ switch (type.typeId()) {
+ case DATE:
+ case TIMESTAMP:
+ case INTEGER:
+ case LONG:
+ case FLOAT:
+ case DOUBLE:
+ case DECIMAL:
+ case BOOLEAN:
+ return true;
+ default:
+ return false;
+ }
+ }
+
+ // extract min/max values from the manifests
+ private Map<Integer, Object> calculateMinMax(
Review Comment:
I think we may also have issues if column stats for a particular column are not present
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Spark : Derive Stats From Manifest on the Fly [iceberg]
Posted by "saitharun15 (via GitHub)" <gi...@apache.org>.
saitharun15 commented on PR #11615:
URL: https://github.com/apache/iceberg/pull/11615#issuecomment-2503833787
Hi @RussellSpitzer @huaxingao , We’ve updated the implementation to use AggregateEvaluator from the aggregate pushdown code. In summary, we prepare a list of expressions for min, max, and count for all columns, then update the evaluator with a set of data files. This returns the respective min, max, and count values. For nullCount, we calculate it by subtracting the count returned by the evaluator from the total number of records.
Please review the changes. Thanks!
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Spark : Derive Stats From Manifest on the Fly [iceberg]
Posted by "huaxingao (via GitHub)" <gi...@apache.org>.
huaxingao commented on PR #11615:
URL: https://github.com/apache/iceberg/pull/11615#issuecomment-2499259216
> do you have any thoughts on this? I know you have dealt with similar issues before on the Aggregate pushdowns.
@RussellSpitzer Sorry I just saw this. I disable aggregate pushdowns if row level deletes are detected.
@saitharun15 Is it possible to reuse some the aggregate pushdown code to get min/max?
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Spark : Derive Stats From Manifest on the Fly [iceberg]
Posted by "jeesou (via GitHub)" <gi...@apache.org>.
jeesou commented on PR #11615:
URL: https://github.com/apache/iceberg/pull/11615#issuecomment-2614906052
HI @huaxingao , @RussellSpitzer, kindly have a look at the PR and suggest any update if there.
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Spark : Derive Stats From Manifest on the Fly [iceberg]
Posted by "RussellSpitzer (via GitHub)" <gi...@apache.org>.
RussellSpitzer commented on code in PR #11615:
URL: https://github.com/apache/iceberg/pull/11615#discussion_r1852396291
##########
spark/v3.5/spark/src/main/java/org/apache/iceberg/spark/source/SparkScan.java:
##########
@@ -248,6 +296,88 @@ protected Statistics estimateStatistics(Snapshot snapshot) {
return new Stats(sizeInBytes, rowsCount, colStatsMap);
}
+ private Map<Integer, Long> calculateNullCount(
+ Map<String, Map<Integer, Long>> distinctDataFilesNullCount) {
+ Map<Integer, Long> nullCount;
+ // get the null counts from the manifest file
+ nullCount =
+ distinctDataFilesNullCount.values().stream() // Stream<Map<Integer, Long>>
+ .flatMap(
+ innerMap ->
+ innerMap.entrySet().stream()) // Flatten to Stream<Map.Entry<Integer, Long>>
+ .collect(
+ Collectors.toMap(
+ Map.Entry::getKey, // Key is the column id
+ Map.Entry::getValue,
+ Long::sum,
+ HashMap::new));
+ return nullCount;
+ }
+
+ private Object toSparkType(Type type, Object value) {
+ switch (type.typeId()) {
+ case DECIMAL:
+ return Decimal.apply((BigDecimal) value);
+ default:
+ }
+ return value;
+ }
+
+ // min/max are calculated for numeric, Date, and Timestamp only
+ private boolean isValidMinMaxType(Type type) {
+ switch (type.typeId()) {
+ case DATE:
+ case TIMESTAMP:
+ case INTEGER:
+ case LONG:
+ case FLOAT:
+ case DOUBLE:
+ case DECIMAL:
+ case BOOLEAN:
+ return true;
+ default:
+ return false;
+ }
+ }
+
+ // extract min/max values from the manifests
+ private Map<Integer, Object> calculateMinMax(
Review Comment:
This may have errors if any delete files are present or if there are any non file covering predicates in the query
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Spark : Derive Stats From Manifest on the Fly [iceberg]
Posted by "RussellSpitzer (via GitHub)" <gi...@apache.org>.
RussellSpitzer commented on code in PR #11615:
URL: https://github.com/apache/iceberg/pull/11615#discussion_r1852416780
##########
spark/v3.5/spark/src/main/java/org/apache/iceberg/spark/source/SparkScan.java:
##########
@@ -248,6 +296,88 @@ protected Statistics estimateStatistics(Snapshot snapshot) {
return new Stats(sizeInBytes, rowsCount, colStatsMap);
}
+ private Map<Integer, Long> calculateNullCount(
+ Map<String, Map<Integer, Long>> distinctDataFilesNullCount) {
+ Map<Integer, Long> nullCount;
+ // get the null counts from the manifest file
+ nullCount =
+ distinctDataFilesNullCount.values().stream() // Stream<Map<Integer, Long>>
+ .flatMap(
+ innerMap ->
+ innerMap.entrySet().stream()) // Flatten to Stream<Map.Entry<Integer, Long>>
+ .collect(
+ Collectors.toMap(
+ Map.Entry::getKey, // Key is the column id
+ Map.Entry::getValue,
+ Long::sum,
+ HashMap::new));
+ return nullCount;
+ }
+
+ private Object toSparkType(Type type, Object value) {
Review Comment:
I feel like we must have this in a helper function somewhere, I know we have to do similar tricks with UTF8
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Spark : Derive Stats From Manifest on the Fly [iceberg]
Posted by "saitharun15 (via GitHub)" <gi...@apache.org>.
saitharun15 commented on code in PR #11615:
URL: https://github.com/apache/iceberg/pull/11615#discussion_r1854296151
##########
spark/v3.5/spark/src/main/java/org/apache/iceberg/spark/source/SparkScan.java:
##########
@@ -194,10 +205,40 @@ protected Statistics estimateStatistics(Snapshot snapshot) {
Map<NamedReference, ColumnStatistics> colStatsMap = Collections.emptyMap();
if (readConf.reportColumnStats() && cboEnabled) {
colStatsMap = Maps.newHashMap();
+ Map<Integer, Long> ndvs = Maps.newHashMap();
+ Map<Integer, Long> nullCounts = Maps.newHashMap();
+ Map<Integer, Object> minValues = Maps.newHashMap();
+ Map<Integer, Object> maxValues = Maps.newHashMap();
List<StatisticsFile> files = table.statisticsFiles();
if (!files.isEmpty()) {
List<BlobMetadata> metadataList = (files.get(0)).blobMetadata();
+ if (readConf.deriveStatsFromManifestSessionConf()
+ || readConf.deriveStatsFromManifestTableProperty()) {
+ Map<String, Map<Integer, Long>> distinctDataFilesNullCount = Maps.newHashMap();
Review Comment:
We found that different FileScanTask objects in the taskGroup were pointing to the same data file, causing duplicates. I used putIfAbsent to ensure a single entry per file and renamed the maps to distinctDataFiles. However after switching to collect FileScanTask objects as a set, putIfAbsent is no longer needed. @RussellSpitzer , can you suggest if there is any other alternate approach?
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Spark : Derive Stats From Manifest on the Fly [iceberg]
Posted by "RussellSpitzer (via GitHub)" <gi...@apache.org>.
RussellSpitzer commented on code in PR #11615:
URL: https://github.com/apache/iceberg/pull/11615#discussion_r1852391179
##########
spark/v3.5/spark/src/main/java/org/apache/iceberg/spark/source/SparkScan.java:
##########
@@ -194,10 +205,40 @@ protected Statistics estimateStatistics(Snapshot snapshot) {
Map<NamedReference, ColumnStatistics> colStatsMap = Collections.emptyMap();
if (readConf.reportColumnStats() && cboEnabled) {
colStatsMap = Maps.newHashMap();
+ Map<Integer, Long> ndvs = Maps.newHashMap();
+ Map<Integer, Long> nullCounts = Maps.newHashMap();
+ Map<Integer, Object> minValues = Maps.newHashMap();
+ Map<Integer, Object> maxValues = Maps.newHashMap();
List<StatisticsFile> files = table.statisticsFiles();
if (!files.isEmpty()) {
List<BlobMetadata> metadataList = (files.get(0)).blobMetadata();
+ if (readConf.deriveStatsFromManifestSessionConf()
+ || readConf.deriveStatsFromManifestTableProperty()) {
+ Map<String, Map<Integer, Long>> distinctDataFilesNullCount = Maps.newHashMap();
+ Map<String, Map<Integer, ByteBuffer>> distinctDataFilesMin = Maps.newHashMap();
+ Map<String, Map<Integer, ByteBuffer>> distinctDataFilesMax = Maps.newHashMap();
+
+ // extract the distinct files which are part of the task planning
+ for (ScanTaskGroup<?> taskGrp : taskGroups()) {
Review Comment:
nit: taskGroup
I don't think we need to save the two characters here ;)
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Spark : Derive Stats From Manifest on the Fly [iceberg]
Posted by "RussellSpitzer (via GitHub)" <gi...@apache.org>.
RussellSpitzer commented on code in PR #11615:
URL: https://github.com/apache/iceberg/pull/11615#discussion_r1852388937
##########
core/src/main/java/org/apache/iceberg/TableProperties.java:
##########
@@ -388,4 +388,8 @@ private TableProperties() {}
public static final int ENCRYPTION_DEK_LENGTH_DEFAULT = 16;
public static final int ENCRYPTION_AAD_LENGTH_DEFAULT = 16;
+
+ public static final String DERIVE_STATS_FROM_MANIFEST_ENABLED =
Review Comment:
These properties don't effect any engines except for Spark so they probably need a prefix
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Spark : Derive Stats From Manifest on the Fly [iceberg]
Posted by "saitharun15 (via GitHub)" <gi...@apache.org>.
saitharun15 commented on PR #11615:
URL: https://github.com/apache/iceberg/pull/11615#issuecomment-2492078503
@RussellSpitzer, thanks for the review comments,I will address them soon. As per @huaxingao implementation [here](https://github.com/apache/iceberg/blob/90be5d7360bc7ff274e7d00cb7259afbf78f223b/spark/v3.5/spark/src/main/java/org/apache/iceberg/spark/source/SparkScanBuilder.java#L242) , aggregate pushdown is skipped when row level deletes are detected, I have applied a similar change here as well.
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Spark : Derive Stats From Manifest on the Fly [iceberg]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #11615:
URL: https://github.com/apache/iceberg/pull/11615#issuecomment-2686493099
This pull request has been marked as stale due to 30 days of inactivity. It will be closed in 1 week if no further activity occurs. If you think that’s incorrect or this pull request requires a review, please simply write any comment. If closed, you can revive the PR at any time and @mention a reviewer or discuss it on the dev@iceberg.apache.org list. Thank you for your contributions.
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Spark : Derive Stats From Manifest on the Fly [iceberg]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] closed pull request #11615: Spark : Derive Stats From Manifest on the Fly
URL: https://github.com/apache/iceberg/pull/11615
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Spark : Derive Stats From Manifest on the Fly [iceberg]
Posted by "RussellSpitzer (via GitHub)" <gi...@apache.org>.
RussellSpitzer commented on code in PR #11615:
URL: https://github.com/apache/iceberg/pull/11615#discussion_r1854422282
##########
spark/v3.5/spark/src/main/java/org/apache/iceberg/spark/source/SparkScan.java:
##########
@@ -194,10 +205,40 @@ protected Statistics estimateStatistics(Snapshot snapshot) {
Map<NamedReference, ColumnStatistics> colStatsMap = Collections.emptyMap();
if (readConf.reportColumnStats() && cboEnabled) {
colStatsMap = Maps.newHashMap();
+ Map<Integer, Long> ndvs = Maps.newHashMap();
+ Map<Integer, Long> nullCounts = Maps.newHashMap();
+ Map<Integer, Object> minValues = Maps.newHashMap();
+ Map<Integer, Object> maxValues = Maps.newHashMap();
List<StatisticsFile> files = table.statisticsFiles();
if (!files.isEmpty()) {
List<BlobMetadata> metadataList = (files.get(0)).blobMetadata();
+ if (readConf.deriveStatsFromManifestSessionConf()
+ || readConf.deriveStatsFromManifestTableProperty()) {
+ Map<String, Map<Integer, Long>> distinctDataFilesNullCount = Maps.newHashMap();
Review Comment:
Yes, filescan tasks are not guaranteed to have non-overlapping groups of files. That's why i suggested below just collecting them all up in a set before collecting stats. Since all data files are "distinct" by definition we don't really need it in a variable name.
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Spark : Derive Stats From Manifest on the Fly [iceberg]
Posted by "saitharun15 (via GitHub)" <gi...@apache.org>.
saitharun15 commented on code in PR #11615:
URL: https://github.com/apache/iceberg/pull/11615#discussion_r1854296151
##########
spark/v3.5/spark/src/main/java/org/apache/iceberg/spark/source/SparkScan.java:
##########
@@ -194,10 +205,40 @@ protected Statistics estimateStatistics(Snapshot snapshot) {
Map<NamedReference, ColumnStatistics> colStatsMap = Collections.emptyMap();
if (readConf.reportColumnStats() && cboEnabled) {
colStatsMap = Maps.newHashMap();
+ Map<Integer, Long> ndvs = Maps.newHashMap();
+ Map<Integer, Long> nullCounts = Maps.newHashMap();
+ Map<Integer, Object> minValues = Maps.newHashMap();
+ Map<Integer, Object> maxValues = Maps.newHashMap();
List<StatisticsFile> files = table.statisticsFiles();
if (!files.isEmpty()) {
List<BlobMetadata> metadataList = (files.get(0)).blobMetadata();
+ if (readConf.deriveStatsFromManifestSessionConf()
+ || readConf.deriveStatsFromManifestTableProperty()) {
+ Map<String, Map<Integer, Long>> distinctDataFilesNullCount = Maps.newHashMap();
Review Comment:
We found that different FileScanTask objects in the taskGroup were pointing to the same data file, causing duplicates. I used putIfAbsent to ensure a single entry per file and renamed the maps to distinctDataFiles. However after switching to collect FileScanTask objects as a set, putIfAbsent is no longer needed. @RussellSpitzer , can you suggest any alternate approach to fix this?
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Spark : Derive Stats From Manifest on the Fly [iceberg]
Posted by "jeesou (via GitHub)" <gi...@apache.org>.
jeesou commented on PR #11615:
URL: https://github.com/apache/iceberg/pull/11615#issuecomment-2840872077
Hi @RussellSpitzer could we please check this PR once?
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org