Wali05 opened a new pull request, #421: URL: https://github.com/apache/datafusion-spark/pull/421
## Which issue does this PR close? - Closes #385. ## Rationale for this change `SparkInputTypes` takes exactly one type per argument, so a function with optional trailing arguments (`round(expr[, scale])`) or a variadic tail (`concat_ws`, `elt`) can't use it yet. #353 lists `elt` and `concat_ws` as waiting on this. ## What changes are included in this PR? - **Optional trailing arguments.** `SparkInputTypes::optional(required, optional, volatility)`, so `round` can be declared as `[Numeric]` plus an optional `[Integer]`. `coerce` returns types only for the arguments that were given, and the function supplies the default for an omitted one itself. - **Variadic tail.** `SparkInputTypes::variadic(fixed, repeated, min_args, volatility)`: the fixed types, then `repeated` for every remaining argument, with a minimum total count. The fixed arguments are always required. An invalid argument in the tail is reported by its own position, like any other argument. - **Spark's `WRONG_NUM_ARGS` text for each case**, formatted the way `QueryCompilationErrors.wrongNumArgsError` does it: `2` for one accepted count (unchanged), `[1, 2]` when several counts are accepted, and `> 1` / `> 0` for a variadic minimum, as `elt` and `concat_ws` raise it. - A short note in `CONTRIBUTING.md` and the module docs pointing to the two new constructors. No function is moved onto them here, so there are no user-visible changes yet. `concat_ws` can use these constructors as they stand. `elt` can use the count check, but it still needs its own type checks (the index must already be INT, and every remaining argument must be STRING or BINARY), and check-only mode cannot yet be combined with a variadic tail. Moving the functions is left to #353. ## Are these changes tested? Yes, with unit tests in `implicit_cast.rs`: - optional arguments omitted and given, a wrong type in a given optional argument, and the `[1, 2]` / `[0, 1, 2, 3]` messages - a `concat_ws`-shaped variadic declaration (casts across the tail, separator only, an invalid tail argument reported by position, and the `> 0` message), plus the `> 1` message for `elt` - fixed arguments staying required when `min_args` is smaller, a variadic tail with no minimum, and ANSI mode applying to the tail I checked the expected messages against Spark 4.2.0: [`wrongNumArgsError`](https://github.com/apache/spark/blob/v4.2.0/sql/catalyst/src/main/scala/org/apache/spark/sql/errors/QueryCompilationErrors.scala#L995-L1020), the `> 0` check in [`ConcatWs`](https://github.com/apache/spark/blob/v4.2.0/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/stringExpressions.scala#L101-L104), the `> 1` check in [`Elt`](https://github.com/apache/spark/blob/v4.2.0/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/stringExpressions.scala#L304-L307), and `to_json`'s `[1, 2]` in the [`json-functions.sql.out`](https://github.com/apache/spark/blob/v4.2.0/sql/core/src/test/resources/sql-tests/results/json-functions.sql.out#L119) golden file. I didn't use the PySpark runner, since nothing reaches SQL yet. `cargo fmt`, `cargo clippy --all-targets --all-features -- -D warnings`, `cargo test -p datafusion-spark`, `cargo test -p datafusion-spark-sqllogictest` and `cargo doc` all pass locally. ## Are there any user-facing changes? No. The new constructors are crate-internal, and no function's behavior changes. -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
