Skip to content

Conversation

@pjain1
Copy link
Member

@pjain1 pjain1 commented Jan 8, 2026

CH does not support automatically converting zulu formatted time 2025-12-25T00:00:00Z to DateTime. A config cast_string_to_date_time_mode enables this but still needs a cast to be added to the string typed time value.

This fix adds support for CAST operator in metrics_sql but only for DateTime and Timestamp type. This will enables api users to pass in datetime as string with the condition that they cast the param in api like day >= CAST('{{ .args.startDate }}' AS DateTime). This also supports Rill time functions so this is also supported day > CAST(time_range_start('P30D') AS DateTime).

Checklist:

  • Covered by tests
  • Ran it and it works as intended
  • Reviewed the diff before requesting a review
  • Checked for unhandled edge cases
  • Linked the issues it closes
  • Checked if the docs need to be updated. If so, create a separate Linear DOCS issue
  • Intend to cherry-pick into the release branch
  • I'm proud of this work!

@pjain1
Copy link
Member Author

pjain1 commented Jan 8, 2026

Tests failing because test CH is old version not supporting this config added in 25.6.

return err
}
b.writeString(" AS ")
b.writeString(cond.Expressions[1].Value.(string))
Copy link
Contributor

Choose a reason for hiding this comment

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

  1. Unsafe type cast – can we make it safe? (Just to protect against panics)
  2. Since SQL types differ between different OLAPs, can we use a generic type here that is not DB-specific? Maybe accept a runtimev1.Type_Code and use drivers.Dialect to map it to a SQL type for common types (can just handle timestamps for now)?

Copy link
Member Author

Choose a reason for hiding this comment

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

Using runtimev1.Type and also added a test.

Also not setting cast_string_to_date_time_mode in the code by default because we have check for min supported version of 22.7 and this config is available in 25.6. We can set it through connector.clickhouse.query_settings="cast_string_to_date_time_mode='best_effort'" for projects needing this.

@pjain1 pjain1 requested a review from begelundmuller January 9, 2026 07:48
@pjain1 pjain1 merged commit e1b5f0f into main Jan 9, 2026
14 checks passed
@pjain1 pjain1 deleted the add_cast_op_exp_ch_date_cast branch January 9, 2026 10:47
pjain1 added a commit that referenced this pull request Jan 9, 2026
…t_string_to_date_time_mode" for clickhouse (#8612)

* add cast operator support in metrics sql, also enable cast_string_to_date_time_mode for clickhouse

* upgrade ch image

* test, review comments

* lint

* better handling

* comment

* fix web code quality CI
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.

3 participants