Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PPL-Lang] Support CAST command #948

Closed
qianheng-aws opened this issue Nov 26, 2024 · 0 comments · Fixed by #952
Closed

[PPL-Lang] Support CAST command #948

qianheng-aws opened this issue Nov 26, 2024 · 0 comments · Fixed by #952
Assignees
Labels
enhancement New feature or request Lang:PPL Pipe Processing Language support

Comments

@qianheng-aws
Copy link
Contributor

Is your feature request related to a problem?
Support CAST command.

`cast(expr as dateType)` cast the expr to dataType. return the value of dataType. The following conversion rules are used:

+------------+--------+--------+---------+-------------+--------+--------+
| Src/Target | STRING | NUMBER | BOOLEAN | TIMESTAMP   | DATE   | TIME   |
+------------+--------+--------+---------+-------------+--------+--------+
| STRING     |        | Note1  | Note1   | TIMESTAMP() | DATE() | TIME() |
+------------+--------+--------+---------+-------------+--------+--------+
| NUMBER     | Note1  |        | v!=0    | N/A         | N/A    | N/A    |
+------------+--------+--------+---------+-------------+--------+--------+
| BOOLEAN    | Note1  | v?1:0  |         | N/A         | N/A    | N/A    |
+------------+--------+--------+---------+-------------+--------+--------+
| TIMESTAMP  | Note1  | N/A    | N/A     |             | DATE() | TIME() |
+------------+--------+--------+---------+-------------+--------+--------+
| DATE       | Note1  | N/A    | N/A     | N/A         |        | N/A    |
+------------+--------+--------+---------+-------------+--------+--------+
| TIME       | Note1  | N/A    | N/A     | N/A         | N/A    |        |
+------------+--------+--------+---------+-------------+--------+--------+

Cast to **string** example:

    os> source=people | eval `cbool` = CAST(true as string), `cint` = CAST(1 as string), `cdate` = CAST(CAST('2012-08-07' as date) as string) | fields `cbool`, `cint`, `cdate`
    fetched rows / total rows = 1/1
    +---------+--------+------------+
    | cbool   | cint   | cdate      |
    |---------+--------+------------|
    | true    | 1      | 2012-08-07 |
    +---------+--------+------------+

See details in this doc: https://github.com/opensearch-project/opensearch-spark/blob/v0.6.0/docs/ppl-lang/functions/ppl-conversion.md#ppl-type-conversion-functions

What solution would you like?
We already have ANTLR definition here:

Need to implement its parser and convert it to Spark function Cast

@qianheng-aws qianheng-aws added enhancement New feature or request untriaged labels Nov 26, 2024
@qianheng-aws qianheng-aws mentioned this issue Nov 27, 2024
5 tasks
@LantaoJin LantaoJin added Lang:PPL Pipe Processing Language support and removed untriaged labels Nov 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request Lang:PPL Pipe Processing Language support
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants