-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Aggregate Push Down Followup #6923
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
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,12 +18,12 @@ | |
| */ | ||
| package org.apache.iceberg.spark.source; | ||
|
|
||
| import java.util.Arrays; | ||
| import java.util.stream.Collectors; | ||
| import java.util.List; | ||
| import org.apache.iceberg.Table; | ||
| import org.apache.iceberg.expressions.Expression; | ||
| import org.apache.iceberg.spark.Spark3Util; | ||
| import org.apache.spark.sql.catalyst.InternalRow; | ||
| import org.apache.spark.sql.connector.read.LocalScan; | ||
| import org.apache.spark.sql.types.StructField; | ||
| import org.apache.spark.sql.types.StructType; | ||
|
|
||
| class SparkLocalScan implements LocalScan { | ||
|
|
@@ -32,10 +32,14 @@ class SparkLocalScan implements LocalScan { | |
| private final StructType readSchema; | ||
| private final InternalRow[] rows; | ||
|
|
||
|
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. nit: Shall we group all vars together? There is an empty line before filters now.
Contributor
Author
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. removed |
||
| SparkLocalScan(Table table, StructType readSchema, InternalRow[] rows) { | ||
| private final List<Expression> filterExpressions; | ||
|
|
||
| SparkLocalScan( | ||
| Table table, StructType readSchema, InternalRow[] rows, List<Expression> filterExpressions) { | ||
| this.table = table; | ||
| this.readSchema = readSchema; | ||
| this.rows = rows; | ||
| this.filterExpressions = filterExpressions; | ||
| } | ||
|
|
||
| @Override | ||
|
|
@@ -50,8 +54,11 @@ public StructType readSchema() { | |
|
|
||
| @Override | ||
| public String description() { | ||
| String fields = | ||
| Arrays.stream(readSchema.fields()).map(StructField::name).collect(Collectors.joining(", ")); | ||
| return String.format("%s [%s]", table, fields); | ||
| return String.format("%s [filters=%s]", table, Spark3Util.describe(filterExpressions)); | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return description(); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -47,6 +47,7 @@ | |
| import org.apache.iceberg.relocated.com.google.common.collect.ImmutableList; | ||
| import org.apache.iceberg.relocated.com.google.common.collect.Lists; | ||
| import org.apache.iceberg.spark.Spark3Util; | ||
| import org.apache.iceberg.spark.SparkAggregates; | ||
| import org.apache.iceberg.spark.SparkFilters; | ||
| import org.apache.iceberg.spark.SparkReadConf; | ||
| import org.apache.iceberg.spark.SparkReadOptions; | ||
|
|
@@ -188,13 +189,12 @@ public boolean pushAggregation(Aggregation aggregation) { | |
| if (expr != null) { | ||
| Expression bound = Binder.bind(schema.asStruct(), expr, caseSensitive); | ||
| expressions.add((BoundAggregate<?, ?>) bound); | ||
| } else { | ||
| LOG.info( | ||
| "Skipping aggregate pushdown: AggregateFunc {} can't be converted to iceberg Expression", | ||
|
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. nit:
Contributor
Author
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. Fixed |
||
| aggregateFunc); | ||
| return false; | ||
| } | ||
| } catch (UnsupportedOperationException e) { | ||
| LOG.info( | ||
| "Skipping aggregate pushdown: AggregateFunc {} can't be converted to iceberg Expression", | ||
| aggregateFunc, | ||
| e); | ||
| return false; | ||
| } catch (IllegalArgumentException e) { | ||
| LOG.info("Skipping aggregate pushdown: Bind failed for AggregateFunc {}", aggregateFunc, e); | ||
| return false; | ||
|
|
@@ -207,7 +207,7 @@ public boolean pushAggregation(Aggregation aggregation) { | |
| return false; | ||
| } | ||
|
|
||
| TableScan scan = table.newScan().withColStats(); | ||
| TableScan scan = table.newScan().includeColumnStats(); | ||
| Snapshot snapshot = readSnapshot(); | ||
| if (snapshot == null) { | ||
| LOG.info("Skipping aggregate pushdown: table snapshot is null"); | ||
|
|
@@ -242,7 +242,8 @@ public boolean pushAggregation(Aggregation aggregation) { | |
| StructLike structLike = aggregateEvaluator.result(); | ||
| pushedAggregateRows[0] = | ||
| new StructInternalRow(aggregateEvaluator.resultType()).setStruct(structLike); | ||
| localScan = new SparkLocalScan(table, pushedAggregateSchema, pushedAggregateRows); | ||
| localScan = | ||
| new SparkLocalScan(table, pushedAggregateSchema, pushedAggregateRows, filterExpressions); | ||
|
|
||
| return true; | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.