From 0e7522b7390441c853b8f3d0b5393ceaefa3fd19 Mon Sep 17 00:00:00 2001 From: yuxiqian <34335406+yuxiqian@users.noreply.github.com> Date: Thu, 5 Sep 2024 12:09:32 +0800 Subject: [PATCH 1/2] [FLINK-36221] Add `CAST ... AS ...` documentations --- docs/content.zh/docs/core-concept/transform.md | 17 +++++++++++++++++ docs/content/docs/core-concept/transform.md | 17 +++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/docs/content.zh/docs/core-concept/transform.md b/docs/content.zh/docs/core-concept/transform.md index f3a11ea7cc8..fec0a007a60 100644 --- a/docs/content.zh/docs/core-concept/transform.md +++ b/docs/content.zh/docs/core-concept/transform.md @@ -153,6 +153,23 @@ Flink CDC uses [Calcite](https://calcite.apache.org/) to parse expressions and [ | COALESCE(value1 [, value2]*) | coalesce(Object... objects) | Returns the first argument that is not NULL.If all arguments are NULL, it returns NULL as well. The return type is the least restrictive, common type of all of its arguments. The return type is nullable if all arguments are nullable as well. | | IF(condition, true_value, false_value) | condition ? true_value : false_value | Returns the true_value if condition is met, otherwise false_value. E.g., IF(5 > 3, 5, 3) returns 5. | +## Casting Functions + +You can use `CAST( AS )` syntax to convert the type of expressions. Possible conversion paths are: + +| Source Type | Target Type | Notes | +|-------------------------------------|-------------|--------------------------------------------------------------------------------------------| +| ANY | STRING | All types can be cast to STRING. | +| NUMERIC, STRING | BOOLEAN | Any non-zero numerics will be evaluated to `TRUE`. | +| NUMERIC | BYTE | Value must be in the range of Byte (-128 ~ 127). | +| NUMERIC | SHORT | Value must be in the range of Short (-32768 ~ 32767). | +| NUMERIC | INTEGER | Value must be in the range of Integer (-2147483648 ~ 2147483647). | +| NUMERIC | LONG | Value must be in the range of Long (-9223372036854775808 ~ 9223372036854775807). | +| NUMERIC | FLOAT | Value must be in the range of Float (1.40239846e-45f ~ 3.40282347e+38f). | +| NUMERIC | DOUBLE | Value must be in the range of Double (4.94065645841246544e-324 ~ 1.79769313486231570e+308) | +| NUMERIC | DECIMAL | Value must be in the range of BigDecimal(10, 0). | +| STRING, TIMESTAMP_TZ, TIMESTAMP_LTZ | TIMESTAMP | String type value must be a valid `ISO_LOCAL_DATE_TIME` string. | + # Example ## Add computed columns Evaluation expressions can be used to generate new columns. For example, if we want to append two computed columns based on the table `web_order` in the database `mydb`, we may define a transform rule as follows: diff --git a/docs/content/docs/core-concept/transform.md b/docs/content/docs/core-concept/transform.md index f3a11ea7cc8..fec0a007a60 100644 --- a/docs/content/docs/core-concept/transform.md +++ b/docs/content/docs/core-concept/transform.md @@ -153,6 +153,23 @@ Flink CDC uses [Calcite](https://calcite.apache.org/) to parse expressions and [ | COALESCE(value1 [, value2]*) | coalesce(Object... objects) | Returns the first argument that is not NULL.If all arguments are NULL, it returns NULL as well. The return type is the least restrictive, common type of all of its arguments. The return type is nullable if all arguments are nullable as well. | | IF(condition, true_value, false_value) | condition ? true_value : false_value | Returns the true_value if condition is met, otherwise false_value. E.g., IF(5 > 3, 5, 3) returns 5. | +## Casting Functions + +You can use `CAST( AS )` syntax to convert the type of expressions. Possible conversion paths are: + +| Source Type | Target Type | Notes | +|-------------------------------------|-------------|--------------------------------------------------------------------------------------------| +| ANY | STRING | All types can be cast to STRING. | +| NUMERIC, STRING | BOOLEAN | Any non-zero numerics will be evaluated to `TRUE`. | +| NUMERIC | BYTE | Value must be in the range of Byte (-128 ~ 127). | +| NUMERIC | SHORT | Value must be in the range of Short (-32768 ~ 32767). | +| NUMERIC | INTEGER | Value must be in the range of Integer (-2147483648 ~ 2147483647). | +| NUMERIC | LONG | Value must be in the range of Long (-9223372036854775808 ~ 9223372036854775807). | +| NUMERIC | FLOAT | Value must be in the range of Float (1.40239846e-45f ~ 3.40282347e+38f). | +| NUMERIC | DOUBLE | Value must be in the range of Double (4.94065645841246544e-324 ~ 1.79769313486231570e+308) | +| NUMERIC | DECIMAL | Value must be in the range of BigDecimal(10, 0). | +| STRING, TIMESTAMP_TZ, TIMESTAMP_LTZ | TIMESTAMP | String type value must be a valid `ISO_LOCAL_DATE_TIME` string. | + # Example ## Add computed columns Evaluation expressions can be used to generate new columns. For example, if we want to append two computed columns based on the table `web_order` in the database `mydb`, we may define a transform rule as follows: From 43810b9448bdda5eeb41996361e1fa60321d8102 Mon Sep 17 00:00:00 2001 From: yuxiqian <34335406+yuxiqian@users.noreply.github.com> Date: Fri, 11 Oct 2024 13:56:06 +0800 Subject: [PATCH 2/2] explain cryptic arguments Signed-off-by: yuxiqian <34335406+yuxiqian@users.noreply.github.com> --- docs/content.zh/docs/core-concept/transform.md | 2 +- docs/content/docs/core-concept/transform.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/content.zh/docs/core-concept/transform.md b/docs/content.zh/docs/core-concept/transform.md index fec0a007a60..382a7c34155 100644 --- a/docs/content.zh/docs/core-concept/transform.md +++ b/docs/content.zh/docs/core-concept/transform.md @@ -155,7 +155,7 @@ Flink CDC uses [Calcite](https://calcite.apache.org/) to parse expressions and [ ## Casting Functions -You can use `CAST( AS )` syntax to convert the type of expressions. Possible conversion paths are: +You can use `CAST( AS )` syntax to convert any valid expression `` to a specific type ``. Possible conversion paths are: | Source Type | Target Type | Notes | |-------------------------------------|-------------|--------------------------------------------------------------------------------------------| diff --git a/docs/content/docs/core-concept/transform.md b/docs/content/docs/core-concept/transform.md index fec0a007a60..382a7c34155 100644 --- a/docs/content/docs/core-concept/transform.md +++ b/docs/content/docs/core-concept/transform.md @@ -155,7 +155,7 @@ Flink CDC uses [Calcite](https://calcite.apache.org/) to parse expressions and [ ## Casting Functions -You can use `CAST( AS )` syntax to convert the type of expressions. Possible conversion paths are: +You can use `CAST( AS )` syntax to convert any valid expression `` to a specific type ``. Possible conversion paths are: | Source Type | Target Type | Notes | |-------------------------------------|-------------|--------------------------------------------------------------------------------------------|