Skip to content

feat(datafusion): extend aggregate, JSON and SQL dialect compatibility - #1304

Merged
JingsongLi merged 5 commits into
apache:mainfrom
JingsongLi:codex/fusion-remaining-compat
Nov 2, 2026
Merged

JingsongLi merged 5 commits into
apache:mainfrom
JingsongLi:codex/fusion-remaining-compat

Conversation

@JingsongLi

@JingsongLi JingsongLi commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

Purpose

Closes #1303.

Common aggregate spellings, JSON output expressions, custom LIKE escapes and several SQL dialect entry points currently fail during SQLContext planning or execution. This change executes those patterns through existing DataFusion/Paimon primitives while preserving NULL, ordering, name-resolution and schema-evolution contracts.

Brief change log

  • Add count_if, any, any_value, first, approx_count_distinct, max_by, min_by, arg_max, collect_list and LISTAGG ordered-set compatibility. Preserve filters, output names and registered-session-function precedence, and keep original REST definitions portable.
  • Add typed to_json/json_object output and exact-Variant string CAST/TRY_CAST rewriting, including dictionary value NULLs, nested values, decimals and corrupted Variant handling.
  • Add one-character LIKE/ILIKE escapes, assert_true, 64-bit conv, date_diff overloads and explicit-zone convert_tz.
  • Route scalar MODIFY COLUMN through existing SchemaChange validation, protecting field IDs, unmentioned attributes and temporary-table shadowing. Add extended Paimon descriptions with native/temporary/external-object fallbacks and redacted credential-like properties.
  • Keep extended descriptions in extended_describe and expression lowering in expression_compat. Selection aggregates adapt native first_value state and grouped accumulation while evaluating each value/key once.

Tests

  • Added thirteen integration regression groups and one REST function/view unit regression. Reproduced the five main failure categories before implementation.
  • Cover empty/all-NULL groups, OR filters, constant sort keys, duplicates/order, window counts, local UDF overrides, persistent definition round trips, dictionary value NULLs, malformed Variant CAST/TRY_CAST, decimal/binary JSON, Unicode LIKE, numeric/timezone/DST boundaries, actual type widening and schema-update failure atomicity.
  • Passed final-head full validation: TZ=UTC RUST_MIN_STACK=16777216 CARGO_BUILD_JOBS=3 cargo test --locked -p paimon-datafusion --all-targets -- --test-threads=4 with Rust 1.95.0.
  • Passed Rust 1.98 Clippy for the crate and all targets with --no-deps -- -D warnings, formatting and diff checks.
  • Completed additional independent review after the module rename. Added failing regressions for invalid fixed-offset minutes, repeated evaluation of volatile aggregate arguments, nullable partial key state, dictionary value NULLs and nullable FILTER masks, then repaired them. Also cover native selection-state merging across batches/partitions and negative CONV source bases returning NULL.

API and Format

Adds SQL names and syntax. New bare compatibility names follow built-in precedence; explicitly registered session functions and qualified catalog calls retain their precedence. Extended Paimon DESCRIBE returns comment/metadata rows, while native and temporary objects retain their existing description behavior. No storage-format, dependency or Rust public API changes.

The documented initial scope uses native fixed-precision HLL, two-argument selection aggregates and scalar MODIFY types. Unsupported precision requests, selection window/DISTINCT modifiers, LISTAGG overflow clauses and nested MODIFY targets fail explicitly. Existing nullability-change policy remains in force.

Design scope

Paimon metadata, Variant conversion and schema changes stay in the integration layer. General expressions reuse native aggregators, Arrow values/timezones and existing Variant decoding, retaining native aggregate state layouts and existing storage contracts.

These are documented SQLContext compatibility subsets. Two-argument date_diff uses end/start date subtraction; the unit/start/end form has explicit UTC/calendar rules. JSON output retains nested NULLs and Arrow temporal formatting and does not implement Spark JSON options. CONV accepts source bases 2 through 36, with negative destination bases for signed output. Native HLL precision and explicit DST-ambiguity behavior are retained.

DataFusion 54's separate Spark package already covers some overlapping names, including collect_list and two-argument date_diff. This PR keeps small native adapters without adding that dependency or registering its full set of overriding functions; future expansion should evaluate selective upstream reuse first. Full Spark/MySQL/Trino emulation is outside this change.

Documentation

Updated docs/src/sql.md with syntax, supported inputs, NULL/error behavior, timezone/encoding rules, precedence and compatibility limits.

@leaves12138 leaves12138 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

LGTM

@JingsongLi
JingsongLi merged commit 4a2437d into apache:main Nov 2, 2026
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[datafusion] Extend aggregate, JSON and SQL dialect compatibility

2 participants