You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@flink.apache.org by Shivam Sharma <28...@gmail.com> on 2018/07/11 17:56:49 UTC

Need to better way to create JSON If we have TableSchema and Row

Hi All,

I have TableSchema
<https://ci.apache.org/projects/flink/flink-docs-release-1.3/api/java/org/apache/flink/table/api/TableSchema.html>
object and a Flink Row object(or list). Do we have any straightforward way
to convert Row object into JSON by using Schema?

For Example:-
TableSchema-
   - columnNames: [name, count]
   - columnTypes: [String, Integer]
Row - ("shivam", 2)
JSON - {"name": "shivam", count: 2}

Thanks
-- 
Shivam Sharma
Data Engineer @ Goibibo
Indian Institute Of Information Technology, Design and Manufacturing
Jabalpur
Mobile No- (+91) 8882114744
Email:- 28shivamsharma@gmail.com
LinkedIn:-*https://www.linkedin.com/in/28shivamsharma
<https://www.linkedin.com/in/28shivamsharma>*

Re: Need to better way to create JSON If we have TableSchema and Row

Posted by Timo Walther <tw...@apache.org>.
Hi Shivam,

Flink 1.5 provides full Row-JSON-Row conversions. You can take a look at 
the `flink-json` module. A table schema can be converted into a 
TypeInformation (Types.ROW(schema.getColumns(), schema.getTypes())) 
which can be used to configure 
JsonRowSerialization/DeserializationSchemas. If you are looking for a 
string output. We might need to refactor those classes a little bit to 
also use the conversion functionality for non-binary output.

Regards,
Timo

Am 12.07.18 um 03:38 schrieb Hequn Cheng:
> Hi shivam,
>
> It seems there is no such a function but you can write one by 
> yourself, maybe use the com.fasterxml.jackson.databind.ObjectMapper.
>
> Best, Hequn
>
> On Thu, Jul 12, 2018 at 1:56 AM, Shivam Sharma 
> <28shivamsharma@gmail.com <ma...@gmail.com>> wrote:
>
>     Hi All,
>
>     I have TableSchema
>     <https://ci.apache.org/projects/flink/flink-docs-release-1.3/api/java/org/apache/flink/table/api/TableSchema.html>
>     object and a Flink Row object(or list). Do we have any
>     straightforward way to convert Row object into JSON by using Schema?
>
>     For Example:-
>     TableSchema-
>        - columnNames: [name, count]
>        - columnTypes: [String, Integer]
>     Row - ("shivam", 2)
>     JSON - {"name": "shivam", count: 2}
>
>     Thanks
>     -- 
>     Shivam Sharma
>     Data Engineer @ Goibibo
>     Indian Institute Of Information Technology, Design and
>     Manufacturing Jabalpur
>     Mobile No- (+91) 8882114744
>     Email:- 28shivamsharma@gmail.com <ma...@gmail.com>
>     LinkedIn:-_https://www.linkedin.com/in/28shivamsharma
>     <https://www.linkedin.com/in/28shivamsharma>_
>
>


Re: Need to better way to create JSON If we have TableSchema and Row

Posted by Hequn Cheng <ch...@gmail.com>.
Hi shivam,

It seems there is no such a function but you can write one by yourself,
maybe use the com.fasterxml.jackson.databind.ObjectMapper.

Best, Hequn

On Thu, Jul 12, 2018 at 1:56 AM, Shivam Sharma <28...@gmail.com>
wrote:

> Hi All,
>
> I have TableSchema
> <https://ci.apache.org/projects/flink/flink-docs-release-1.3/api/java/org/apache/flink/table/api/TableSchema.html>
> object and a Flink Row object(or list). Do we have any straightforward way
> to convert Row object into JSON by using Schema?
>
> For Example:-
> TableSchema-
>    - columnNames: [name, count]
>    - columnTypes: [String, Integer]
> Row - ("shivam", 2)
> JSON - {"name": "shivam", count: 2}
>
> Thanks
> --
> Shivam Sharma
> Data Engineer @ Goibibo
> Indian Institute Of Information Technology, Design and Manufacturing
> Jabalpur
> Mobile No- (+91) 8882114744
> Email:- 28shivamsharma@gmail.com
> LinkedIn:-*https://www.linkedin.com/in/28shivamsharma
> <https://www.linkedin.com/in/28shivamsharma>*
>