[
https://issues.apache.org/jira/browse/FLINK-9430?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16494759#comment-16494759
]
ASF GitHub Bot commented on FLINK-9430:
---------------------------------------
GitHub user suez1224 opened a pull request:
https://github.com/apache/flink/pull/6100
[FLINK-9430][Table API & SQL] add cast rule in SQL to cast Object to other
assignable types
## What is the purpose of the change
Add cast rule in SQL to cast Object to other assignable types.
## Brief change log
- Add Cast rule to handle casting from Object.
- Add unittests.
## Verifying this change
This change added tests and can be verified as follows:
- Added unittest to test casting from Object to other basic type.
## Does this pull request potentially affect one of the following parts:
- Dependencies (does it add or upgrade a dependency): (no)
- The public API, i.e., is any changed class annotated with
`@Public(Evolving)`: (yno)
- The serializers: (no)
- The runtime per-record code paths (performance sensitive): (no)
- Anything that affects deployment or recovery: JobManager (and its
components), Checkpointing, Yarn/Mesos, ZooKeeper: (no)
- The S3 file system connector: (no)
## Documentation
- Does this pull request introduce a new feature? ( no)
- If yes, how is the feature documented? (not applicable)
You can merge this pull request into a Git repository by running:
$ git pull https://github.com/suez1224/flink object-cast
Alternatively you can review and apply these changes as the patch at:
https://github.com/apache/flink/pull/6100.patch
To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:
This closes #6100
----
commit 6d1d4ba8e956fd4f17a6dddc4613530f6fe343fa
Author: Shuyi Chen <shuyi@...>
Date: 2018-05-24T05:39:15Z
add cast support in SQL to cast GenericTypeInfo to other types
----
> Support Casting of Object to Primitive types for Flink SQL UDF
> --------------------------------------------------------------
>
> Key: FLINK-9430
> URL: https://issues.apache.org/jira/browse/FLINK-9430
> Project: Flink
> Issue Type: New Feature
> Components: Table API & SQL
> Reporter: Shuyi Chen
> Assignee: Shuyi Chen
> Priority: Major
>
> We want to add a SQL UDF to access specific element in a JSON string using
> JSON path. However, the JSON element can be of different types, e.g. Int,
> Float, Double, String, Boolean and etc.. Since return type is not part of the
> method signature, we can not use overload. So we will end up writing a UDF
> for each type, e.g. GetFloatFromJSON, GetIntFromJSON and etc., which has a
> lot of duplication.
> One way to unify all these UDF functions is to implement one UDF and return
> java.lang.Object, and in the SQL statement, use CAST AS to cast the returned
> Object into the correct type. Below is an example:
>
> {code:java}
> object JsonPathUDF extends ScalarFunction {
> def eval(jsonStr: String, path: String): Object = {
> JSONParser.parse(jsonStr).read(path)
> }
> }{code}
> {code:java}
> SELECT CAST(jsonpath(json, "$.store.book.title") AS VARCHAR(32)) as
> bookTitle FROM table1{code}
> The current Flink SQL cast implementation does not support casting from
> GenericTypeInfo<java.lang.Object> to another type, I have already got a local
> branch to fix this. Please comment if there are alternatives to the problem
> above.
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)