feat(datafusion): support REST format table partition commands - #591
feat(datafusion): support REST format table partition commands#591sundapeng wants to merge 1 commit into
Conversation
|
Add Spark-style partition administration to DataFusion for catalog-managed
internal Format Tables loaded from REST Catalog. REST partition registrations
become the authoritative partition set used by both SQL commands and scans.
- SHOW PARTITIONS table [PARTITION (...)]
- ALTER TABLE table ADD [IF NOT EXISTS] PARTITION (...)
- ALTER TABLE table DROP [IF EXISTS] PARTITION (...)
- MSCK REPAIR TABLE table [{ADD|DROP|SYNC} PARTITIONS]
DROP PARTITION follows Java Format Table semantics: a statement may carry
several specifications, and one that fixes only some of the partition keys
expands to every registered partition it matches, whether or not those keys
are a leading prefix. One catalog listing serves the whole statement.
A catalog-managed scan pushes the leading equality prefix of its filter down
as a partitionNamePattern with a 1000-row page size, instead of downloading
every registration and pruning locally. The pattern is a hint, so the local
match stays as the backstop.
Partition boolean values accept every spelling Java accepts (t/true/y/yes/1
and their negatives, case-insensitive), so a partition another engine
registered as TRUE is readable here.
78f19a5 to
2d40c53
Compare
|
@JingsongLi Thanks for the review. All three are fixed, and the branch is rebased onto current main (it was conflicting with #600 and #627). Details below, including one place where I could not go all the way and would like your call. 1. DROP PARTITION semantics
Error semantics follow Java as well: a complete specification names one partition, so a missing one raises unless One thing I could not do. Hive and Spark write several specs as ALTER TABLE t DROP PARTITION (dt = '20260722'), DROP PARTITION (dt = '20260723');The alternatives are a change in sqlparser, or a hand-rolled pre-parse of the statement like the one I also did not add 2. Partition pruning through the REST endpoint A catalog-managed scan now extracts the leading equality prefix from its filter, builds the partition-name prefix pattern with the same contract as One Rust-specific detail worth flagging. A straight port of the Java extractor would have pushed nothing in the case that matters most. Predicate pushdown to 3. Boolean partition values
While confirming this I found the same class of problem is wider than booleans: Also in this push
|
Purpose
A Format Table loaded from REST Catalog can have its partitions managed by the catalog instead of discovered from the directory layout. DataFusion had no way to administer that partition set, and no way to read it:
SHOW PARTITIONS,ALTER TABLE ... ADD/DROP PARTITIONandMSCK REPAIR TABLEwere unavailable, and a scan discovered partitions from storage even when the catalog was the authority.This change adds those commands and makes the catalog registration the partition set a scan reads.
Brief change log
SHOW PARTITIONS table [PARTITION (...)]ALTER TABLE table ADD [IF NOT EXISTS] PARTITION (...)ALTER TABLE table DROP [IF EXISTS] PARTITION (...)MSCK REPAIR TABLE table [{ADD|DROP|SYNC} PARTITIONS]DROP PARTITIONfollows Java Format Table semantics: one statement may carry several specifications, and a specification that fixes only some of the partition keys expands to every registered partition it matches. The fixed keys need not be a leading prefix, sohh = '10'alone works on a(dt, hh)table. One catalog listing serves the whole statement.partitionNamePatternwithmaxResults=1000, instead of downloading every registration and pruning locally. The pattern is a hint the catalog may ignore, so the local match stays as the backstop.t/true/y/yes/1and their negatives, case-insensitive), so a partition another engine registered asTRUEis readable here.DROP/SYNCreconciliation.Tests
crates/paimon/tests/format_partition_test.rs,rest_api_test.rs,rest_catalog_test.rscrates/integrations/datafusion/tests/rest_format_partition_sql.rs, including:IF EXISTS, a partial one that matches nothing being a no-op, and a failing specification leaving the whole statement unappliedpartitionNamePatterna scan pushes for each predicate shape, asserted on the request the server receivedcrates/paimon/src/table/format_partition.rsCommands run:
API and Format
Additive except for one signature:
RESTApi::list_partitions_pagedtakes a fourthpartition_name_pattern: Option<&str>, matching JavaRESTApi.listPartitionsPaged. Both in-crate callers passNone.RESTApi::list_partitions_by_name_patternis new. TheCatalogtrait is unchanged; the scan reaches the REST client directly, so adding the pattern there can wait for a caller that needs it.The storage format is unchanged.
Documentation
docs/src/sql.mdgains a Format Table Partitions section covering all four statements, themetastore.partitioned-tableprerequisite, the ordering guarantees ofADD/DROP, and what repair does and does not touch.Scope and limitations
metastore.partitioned-table=trueand a non-engineimplementation.DROP PARTITIONspecifications are written as repeated clauses,DROP PARTITION (...), DROP PARTITION (...). Hive and Spark writeDROP PARTITION (...), (...), which sqlparser 0.62 cannot parse:parse_alter_tablecomma-separates ALTER operations, and a bare secondPARTITIONis read asRENAME PARTITION. Accepting the Hive spelling needs either a change in sqlparser or a hand-rolled pre-parse like the oneSHOW PARTITIONSalready uses. Happy to add the pre-parse if that is preferred.listPartitionsByFilteris not included. [spec] Support parsing REST catalog Predicate and Transform JSON #500 added REST predicate JSON parsing but not serialization, so there is no encoder to send yet. The prefix pattern covers the leading-equality case.TypeUtils.castFromString, which is better done on its own.