What is JSON_TABLE? Is it in the SQL standard? Can you give a simple example?

On Tue, May 31, 2022 at 10:03 AM Gavin Ray <ray.gavi...@gmail.com> wrote:
>
> I dug up some examples from Github of using the "TableFunctionImpl" class:
>
> mat-calcite-plugin/TableFunctions.java at
> a57a5ba80768066714c22bd9e8a9b529d4cb9a6b · vlsi/mat-calcite-plugin
> (github.com)
> <https://github.com/vlsi/mat-calcite-plugin/blob/a57a5ba80768066714c22bd9e8a9b529d4cb9a6b/MatCalcitePlugin/src/com/github/vlsi/mat/calcite/functions/TableFunctions.java>
> Calcite_sql_driver/MazeTable.java at
> 6819088123e67631367ca927b112b58e4eb90829 · dream001/Calcite_sql_driver
> (github.com)
> <https://github.com/dream001/Calcite_sql_driver/blob/6819088123e67631367ca927b112b58e4eb90829/src/test/java/com/yonyou/calcite/MazeTable.java>
>
> Currently trying to get a TableFunction that just returns a Map<String,
> Object> as a relation to work
> Have the below -- calling this shows that the function IS invoked, but the
> data it gives back is garbage:
>
> Calcite JSON_TABLE WIP (github.com)
> <https://gist.github.com/GavinRay97/b42c69992a0d0c3a01f1c7e1b9ab1999>
>
> This is the output of main()
>
> json = {"id":1, "name":"John"}
> json = {"id":1, "name":"John"}
> json = {"id":1, "name":"John"}
> EXPR$0: id
> EXPR$0: id
>
> I'm doing something wrong here for sure, lol.
>
>
> On Tue, May 31, 2022 at 11:35 AM Gavin Ray <ray.gavi...@gmail.com> wrote:
>
> > I'm interested in implementing JSON_TABLE functionality for Calcite
> >
> > This opens up some neat usecases, like adding HTTP request UDF's
> > then using JSON_TABLE to convert the result into a table:
> >
> > SELECT JSON_TABLE(
> > HTTP_GET('http://localhost:8080/api/v1/users/1'))
> >
> > Adding support for all of the functionality seems difficult,
> > but I'm wondering whether this could be done as a "SqlTableFunction" UDF?
> >
> > I'm thinking it might be possible if the JSON_TABLE udf
> > expects Map<String, Object> and does inference based on that?
> >
> > Something like:
> >
> > WITH users AS (
> >     SELECT HTTP_GET('http://localhost:8080/api/v1/users')
> > ) SELECT
> >     id,
> >     name
> > FROM
> >     JSON_TABLE(JSON_PATH(users, "$.0"))
> >
> > Does anyone have ideas or see issues with this approach?
> > Thank you =)
> >
> >
> >
> >

Reply via email to