Skip to content

Support AtTimeZone node in SqlToRel #9580

Closed

Description

@rebasedming

Is your feature request related to a problem or challenge?

I would like SqlToRel to be able to construct a LogicalPlan from the a query string containing the AT TIME ZONE clause. Right now it's unsupported:

create table t (a timestamptz);
insert into t values('2000-12-01 04:04:12');
select a AT TIME ZONE 'UTC' from t;
This feature is not implemented: Unsupported ast node in sqltorel: AtTimeZone { timestamp: Identifier(Ident { value: "a", quote_style: None }), time_zone: "UTC" }

Describe the solution you'd like

AT TIME ZONE clauses can be parsed and converted into logical plans.

Describe alternatives you've considered

No response

Additional context

No response

Activity

  1. tinfoil-knight commented on Mar 13, 2024

    @tinfoil-knight
    Contributor

    take

  2. tinfoil-knight commented on Mar 13, 2024

    @tinfoil-knight
    Contributor

    I'm picking up this issue.

    This error (Unsupported ast node in sqltorel) comes from this line:
    https://github.com/apache/arrow-datafusion/blob/0302d6530a5a7fffe7da40e0f3b13794a9c693ff/datafusion/sql/src/expr/mod.rs#L579

    AtTimeZone SQL Expr is already provided by sqlparser.


    Intended Change:

    Add a condition to handle SQLExpr::AtTimeZone in the match case in sql_expr_to_logical_expr_internal here:

    https://github.com/apache/arrow-datafusion/blob/0302d6530a5a7fffe7da40e0f3b13794a9c693ff/datafusion/sql/src/expr/mod.rs#L162-L172

    And, add a scalar function to convert a date to a specific time zone as per the HowTo here so that it can be used by sql_named_function_to_expr to get the Result.

  3. alamb commented on Mar 14, 2024

    @alamb
    Contributor

    And, add a scalar function to convert a date to a specific time zone as per the HowTo here so that it can be used by sql_named_function_to_expr to get the Result.

    Since the Timezone is encoded in the DataType I think you could call Expr::Cast with a DataType that had the appropriate timezone -- e.g. set the timezone correctly https://docs.rs/arrow/latest/arrow/datatypes/enum.DataType.html#variant.Timestamp and then cast the expression to that type

    Thus you may not need to make a new scalar function

  4. tinfoil-knight commented on Mar 16, 2024

    @tinfoil-knight
    Contributor

    Since the Timezone is encoded in the DataType I think you could call Expr::Cast with a DataType that had the appropriate timezone -- e.g. set the timezone correctly docs.rs/arrow/latest/arrow/datatypes/enum.DataType.html#variant.Timestamp and then cast the expression to that type

    Thus you may not need to make a new scalar function

    Yeah. This worked. Thank you for the suggestion.

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

Metadata

Metadata

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions