You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@calcite.apache.org by Marc Prud'hommeaux <ma...@glimpse.io> on 2015/08/05 23:21:10 UTC

Executing a RelJson directly

Is there a simple way to execute a RelJson directly on a CalciteConnection, bypassing the SQL parsing stage?


Re: Executing a RelJson directly

Posted by Vladimir Sitnikov <si...@gmail.com>.
Fixup (I've hit send by mistake):

1) You implement a function that maps input String to a
TranslatableTable like here
https://github.com/apache/incubator-calcite/blob/5cb95e644f38da1a13d6def96eeec935b650289c/core/src/test/java/org/apache/calcite/test/JdbcTest.java#L6507-L6509
You probably do not need "view" or "viewmacro"

2) Your implementation of TranslatableTable just deserializes the
string in respond to toRel. Well,

3) Profit.
It would work similar to org.apache.calcite.test.JdbcTest#testTableMacro.

Well, you might want using something like ViewTable, however I do not
find it immediately useful for "deserializing" case.

Does that make sense?

Vladimir

Re: Executing a RelJson directly

Posted by Vladimir Sitnikov <si...@gmail.com>.
You are not going to use bind variables, are you?

TranslatableTable is your friend.

For instance,
1) You implement a function that maps input String to a Tra

For going "without binds", view macro is probably the closest option.
You just use "deserialization" in place of "expandView".
Implementation:
https://github.com/apache/incubator-calcite/blob/3e50232b681e8dadb921580ee6f3e0376dd0f664/core/src/main/java/org/apache/calcite/schema/impl/ViewTable.java#L119

Test: https://github.com/apache/incubator-calcite/blob/5cb95e644f38da1a13d6def96eeec935b650289c/core/src/test/java/org/apache/calcite/test/JdbcTest.java#L645-L647

Vladimir

Re: Executing a RelJson directly

Posted by Marc Prud'hommeaux <ma...@glimpse.io>.
Can you give me a nudge in the right direction for getting a RelNode to execute as a query? I figure it must be possible, since that seems to be the motive behind the recent RelBuilder addition. I'm guessing there is some step to convert the RelNode into a QueryProvider Expression, but I'm stuck figuring out where that happens.


> On Aug 5, 2015, at 6:58 PM, Julian Hyde <jh...@apache.org> wrote:
> 
> Or… write a user-defined table function “jsonPlan”. It takes a varchar argument (the json plan) and expands to the plan. Then use “select * from (table jsonPlan(‘xxx’)”. The nice thing about that is that all the magic happens server side, and you don’t need to change the JDBC framework.
> 
> Julian
> 
>> On Aug 5, 2015, at 3:52 PM, Marc Prud'hommeaux <ma...@glimpse.io> wrote:
>> 
>> 
>> That would explain why I couldn't figure out how to do it.
>> 
>> For the project I'm working on, I want to be able to serialize RelJson to .json files and then re-execute them later in a web microservices framework. It occurs to me that the Avatica server does 90% of what I want. Is it plausible that a "rel" JSON property might be queried in org.apache.calcite.avatica.Meta and used to execute the query (preempting the "sql" JSON property)? If the idea is sound, I may take a stab at implementing it.
>> 
>> Bonus question: has anyone considered creating a JSON Schema definition for the RelJson and ModelHandler JSON formats? It could come in handy for people who want to implement an Avatica client in another language.
>> 
>> 
>>> On Aug 5, 2015, at 5:27 PM, Julian Hyde <jh...@apache.org> wrote:
>>> 
>>> I don’t think there is — but I always hoped to create one.
>>> 
>>> 
>>>> On Aug 5, 2015, at 2:21 PM, Marc Prud'hommeaux <ma...@glimpse.io> wrote:
>>>> 
>>>> 
>>>> Is there a simple way to execute a RelJson directly on a CalciteConnection, bypassing the SQL parsing stage?
>>>> 
>>> 
>> 
> 


Re: Executing a RelJson directly

Posted by Julian Hyde <jh...@apache.org>.
Or… write a user-defined table function “jsonPlan”. It takes a varchar argument (the json plan) and expands to the plan. Then use “select * from (table jsonPlan(‘xxx’)”. The nice thing about that is that all the magic happens server side, and you don’t need to change the JDBC framework.

Julian

> On Aug 5, 2015, at 3:52 PM, Marc Prud'hommeaux <ma...@glimpse.io> wrote:
> 
> 
> That would explain why I couldn't figure out how to do it.
> 
> For the project I'm working on, I want to be able to serialize RelJson to .json files and then re-execute them later in a web microservices framework. It occurs to me that the Avatica server does 90% of what I want. Is it plausible that a "rel" JSON property might be queried in org.apache.calcite.avatica.Meta and used to execute the query (preempting the "sql" JSON property)? If the idea is sound, I may take a stab at implementing it.
> 
> Bonus question: has anyone considered creating a JSON Schema definition for the RelJson and ModelHandler JSON formats? It could come in handy for people who want to implement an Avatica client in another language.
> 
> 
>> On Aug 5, 2015, at 5:27 PM, Julian Hyde <jh...@apache.org> wrote:
>> 
>> I don’t think there is — but I always hoped to create one.
>> 
>> 
>>> On Aug 5, 2015, at 2:21 PM, Marc Prud'hommeaux <ma...@glimpse.io> wrote:
>>> 
>>> 
>>> Is there a simple way to execute a RelJson directly on a CalciteConnection, bypassing the SQL parsing stage?
>>> 
>> 
> 


Re: Executing a RelJson directly

Posted by Marc Prud'hommeaux <ma...@glimpse.io>.
That would explain why I couldn't figure out how to do it.

For the project I'm working on, I want to be able to serialize RelJson to .json files and then re-execute them later in a web microservices framework. It occurs to me that the Avatica server does 90% of what I want. Is it plausible that a "rel" JSON property might be queried in org.apache.calcite.avatica.Meta and used to execute the query (preempting the "sql" JSON property)? If the idea is sound, I may take a stab at implementing it.

Bonus question: has anyone considered creating a JSON Schema definition for the RelJson and ModelHandler JSON formats? It could come in handy for people who want to implement an Avatica client in another language.


> On Aug 5, 2015, at 5:27 PM, Julian Hyde <jh...@apache.org> wrote:
> 
> I don’t think there is — but I always hoped to create one.
> 
> 
>> On Aug 5, 2015, at 2:21 PM, Marc Prud'hommeaux <ma...@glimpse.io> wrote:
>> 
>> 
>> Is there a simple way to execute a RelJson directly on a CalciteConnection, bypassing the SQL parsing stage?
>> 
> 


Re: Executing a RelJson directly

Posted by Julian Hyde <jh...@apache.org>.
I don’t think there is — but I always hoped to create one.


> On Aug 5, 2015, at 2:21 PM, Marc Prud'hommeaux <ma...@glimpse.io> wrote:
> 
> 
> Is there a simple way to execute a RelJson directly on a CalciteConnection, bypassing the SQL parsing stage?
>