Skip to content
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

[SPARK-49507][SQL] Fix Expected only partition pruning predicates exception #47998

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

TongWei1105
Copy link
Contributor

@TongWei1105 TongWei1105 commented Sep 5, 2024

What changes were proposed in this pull request?

bug fix

Why are the changes needed?

How to reproduce:

CREATE TABLE t (ID BIGINT, DT STRING) USING parquet PARTITIONED BY (DT);
set spark.sql.hive.metastorePartitionPruningFastFallback=true;
select * from t where dt=20240820;

Error msg:

org.apache.spark.sql.AnalysisException: Expected only partition pruning predicates: List(isnotnull(DT#21), (cast(DT#21 as bigint) = 20240820)).
  at org.apache.spark.sql.errors.QueryCompilationErrors$.nonPartitionPruningPredicatesNotExpectedError(QueryCompilationErrors.scala:2414)
  at org.apache.spark.sql.catalyst.catalog.ExternalCatalogUtils$.generatePartitionPredicateByFilter(ExternalCatalo

Does this PR introduce any user-facing change?

No

How was this patch tested?

add ut

Was this patch authored or co-authored using generative AI tooling?

No

@github-actions github-actions bot added the SQL label Sep 5, 2024
@TongWei1105 TongWei1105 changed the title [WIP][SPARK-49507] Fix Expected only partition pruning predicates exception [WIP][SPARK-49507][SQL] Fix Expected only partition pruning predicates exception Sep 5, 2024
@TongWei1105 TongWei1105 changed the title [WIP][SPARK-49507][SQL] Fix Expected only partition pruning predicates exception [SPARK-49507][SQL] Fix Expected only partition pruning predicates exception Sep 5, 2024
@TongWei1105
Copy link
Contributor Author

cc @wangyum

@wangyum
Copy link
Member

wangyum commented Sep 13, 2024

cc @cxzl25 @cloud-fan

val boundPredicate = ExternalCatalogUtils.generatePartitionPredicateByFilter(
catalogTable, partitionSchema, predicates)
catalogTable, partitionSchema, transformedPredicates)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because the catalogTable here is loaded directly from HMS, the partition fields are in lowercase instead of being restored to uppercase partition fields, which leads to this problem.

Because the catalog of conf.metastorePartitionPruning=false has partition field names in uppercase, there is no such problem.

def listPartitionsByFilter(
conf: SQLConf,
catalog: SessionCatalog,
table: CatalogTable,
partitionFilters: Seq[Expression]): Seq[CatalogTablePartition] = {
if (conf.metastorePartitionPruning) {
catalog.listPartitionsByFilter(table.identifier, partitionFilters)
} else {
ExternalCatalogUtils.prunePartitionsByFilter(table, catalog.listPartitions(table.identifier),
partitionFilters, conf.sessionLocalTimeZone)
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants