Skip to content

[GLUTEN-4730][CH] feat: Support date_from_unix_date function: Add ClickHouse backend implementation#12410

Open
navaneethsujith09 wants to merge 6 commits into
apache:mainfrom
navaneethsujith09:date-from-unix-date
Open

[GLUTEN-4730][CH] feat: Support date_from_unix_date function: Add ClickHouse backend implementation#12410
navaneethsujith09 wants to merge 6 commits into
apache:mainfrom
navaneethsujith09:date-from-unix-date

Conversation

@navaneethsujith09

@navaneethsujith09 navaneethsujith09 commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

Implement SparkFunctionDateFromUnixDate in C++
Register function in CommonScalarFunctionParser
Add unit test in GlutenDateFunctionsSuite (Spark 3.5) for correctness
This enables Spark SQL queries using date_from_unix_date to work with the ClickHouse backend.
Implemented the feedback recieved from @taiyang-li

What changes are proposed in this pull request?

This pull request adds support for the date_from_unix_date function in the ClickHouse backend of Apache Gluten.
Specifically, it includes:
Implementation of the SparkFunctionDateFromUnixDate C++ function, which converts a unix date (number of days since epoch) to a Spark-compatible date.
Registration of the function in the ClickHouse function factory and the scalar function parser, enabling Substrait-to-ClickHouse translation.
Addition of unit tests in GlutenDateFunctionsSuite (Spark 3.5) to verify correctness and expected behavior.

How was this patch tested?

Added unit tests in gluten-ut/spark35/src/test/scala/org/apache/spark/sql/GlutenDateFunctionsSuite.scala to cover:
Typical values (e.g., date_from_unix_date(0) returns 1970-01-01)
Larger values (e.g., date_from_unix_date(1000) returns 1972-09-27)
Null handling (date_from_unix_date(null) returns null)
Ran the full test suite to ensure no regressions.

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

Generated-by Claude Opus 4.8

Related issue: #4730

Copilot AI review requested due to automatic review settings June 30, 2026 22:23

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@github-actions github-actions Bot added CORE works for Gluten Core CLICKHOUSE labels Jun 30, 2026
@github-actions

Copy link
Copy Markdown

Run Gluten Clickhouse CI on x86

@prestodb-ci

Copy link
Copy Markdown

Failed to query issues imported from #12410:

dial tcp 10.167.38.130:3306: connect: connection timed out

@github-actions

Copy link
Copy Markdown

Run Gluten Clickhouse CI on x86

Copilot AI review requested due to automatic review settings June 30, 2026 22:33

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@github-actions

Copy link
Copy Markdown

Run Gluten Clickhouse CI on x86

@lgbo-ustc

Copy link
Copy Markdown
Contributor

@navaneethsujith09

engine/Functions/CMakeFiles/gluten_spark_functions_obj.dir/SparkFunctionDateFromUnixDate.cpp.o -MF utils/extern-local-engine/Functions/CMakeFiles/gluten_spark_functions_obj.dir/SparkFunctionDateFromUnixDate.cpp.o.d -o utils/extern-local-engine/Functions/CMakeFiles/gluten_spark_functions_obj.dir/SparkFunctionDateFromUnixDate.cpp.o -c /home/jenkins/agent/workspace/gluten/gluten-ci/gluten/cpp-ch/ClickHouse/utils/extern-local-engine/Functions/SparkFunctionDateFromUnixDate.cpp

[2026-06-30T22:42:20.727Z] /home/jenkins/agent/workspace/gluten/gluten-ci/gluten/cpp-ch/local-engine/Functions/SparkFunctionDateFromUnixDate.cpp:26:2: error: expected '}'

[2026-06-30T22:42:20.727Z]    26 | }

[2026-06-30T22:42:20.727Z]       |  ^

[2026-06-30T22:42:20.727Z] /home/jenkins/agent/workspace/gluten/gluten-ci/gluten/cpp-ch/local-engine/Functions/SparkFunctionDateFromUnixDate.cpp:21:1: note: to match this '{'

[2026-06-30T22:42:20.727Z]    21 | {

[2026-06-30T22:42:20.727Z]       | ^

[2026-06-30T22:42:20.727Z] 1 error generated.

[2026-06-30T22:42:24.869Z] [10726/13871] Linking CXX executable contrib/llvm-project/llvm/bin/llvm-tblgen

[2026-06-30T22:42:24.869Z] ninja: build stopped: subcommand failed.

@github-actions

github-actions Bot commented Jul 1, 2026

Copy link
Copy Markdown

Run Gluten Clickhouse CI on x86

@navaneethsujith09

Copy link
Copy Markdown
Contributor Author

@lgbo-ustc Ok, I think I have fixed the issue. Please let me know if anything else needs to be fixed.

@taiyang-li

Copy link
Copy Markdown
Contributor

@navaneethsujith09 I'm curious about why we need to create a new function instead of reusing existed function like toDate

:) select toDate(1)

SELECT toDate(1)

Query id: b986ea69-9b6b-4184-b189-aae2b3ec2014

   ┌──toDate(1)─┐
1. │ 1970-01-02 │
   └────────────┘

1 row in set. Elapsed: 0.002 sec. 

:) select toDate32(1)

SELECT toDate32(1)

Query id: 3833fbb7-36b3-4ae5-8fb7-f3359fc22ab0

   ┌─toDate32(1)─┐
1. │  1970-01-02 │
   └─────────────┘

1 row in set. Elapsed: 0.002 sec. 

@lgbo-ustc

Copy link
Copy Markdown
Contributor

the ci still fails。 you can login the jenkins to view the log.
user:gluten
passwd: hN2xX3uQ4m

Copilot AI review requested due to automatic review settings July 6, 2026 19:08
@github-actions

github-actions Bot commented Jul 6, 2026

Copy link
Copy Markdown

Run Gluten Clickhouse CI on x86

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Comment on lines +50 to +63
DB::DataTypePtr getReturnTypeImpl(const DB::ColumnsWithTypeAndName &) const override { return std::make_shared<DB::DataTypeDate32>(); }

DB::ColumnPtr executeImpl(const DB::ColumnsWithTypeAndName & arguments, const DB::DataTypePtr & result_type, size_t input_rows) const override
{
if (arguments.size() != 1)
throw DB::Exception(DB::ErrorCodes::NUMBER_OF_ARGUMENTS_DOESNT_MATCH, "Function {} requires exactly 1 argument", name);

const DB::ColumnWithTypeAndName & first_arg = arguments[0];
DB::WhichDataType which(first_arg.type);
if (which.isInt32())
return executeInternal<Int32>(first_arg.column, input_rows);
else
throw DB::Exception(DB::ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT, "Function {} requires Int32 argument", name);
}
Comment on lines +284 to +288
testGluten("date_from_unix_date") {
// -100000 and 200000 are outside ClickHouse's native Date32 range
// [1900-01-01, 2299-12-31]. They guard against implementations that clamp to that
// range (e.g. mapping to CH toDate32), which would silently diverge from Spark.
val df = Seq(Some(0), Some(1000), Some(-100000), Some(200000), None).toDF("unix_date")
@navaneethsujith09

navaneethsujith09 commented Jul 6, 2026

Copy link
Copy Markdown
Contributor Author

@lgbo-ustc Ok, I have fixed the issue. The ci now passes. Thanks for giving me access to the jenkins. That helped a lot.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLICKHOUSE CORE works for Gluten Core

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants