[ 
https://issues.apache.org/jira/browse/CALCITE-3470?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16967260#comment-16967260
 ] 

jamie12221 edited comment on CALCITE-3470 at 11/5/19 6:07 AM:
--------------------------------------------------------------

Thank you for your patience.

I'm actually writing a DSL based on RelBuilder but not based on RelOptRule (not 
originally intended to optimize relational expressions). A friend told me about 
Optgen DSL. So I thought that Calcite's development team might be doing 
something similar.Or everyone is going to do better together. So I sent an 
issue. (The following is another topic.) For example, calcite.piglet is also a 
DSL, which was recently updated, but not designed for Calcite's optimizer.

My DSL design is divided into two parts. The first part is analysis, which is 
simple. Lexer is SQL Lexer. The syntax is a mixture of infix expressions and 
function calls.
 like this:

 

 
{code:java}
join (travelrecord as t,address as a, t.id = a.id)
.filter (t.id = 1 or a.id = 2)
.map(t.id,t.user_id)
{code}
 

Then Method chaining and name will be converted into three possible ways:
{code:java}
MAP(FILTER(JOIN(AS(travelrecord,t),AS(address,a),EQ(DOT(t,id),DOT(a,id))),OR(EQ(DOT(t,id),1),EQ(DOT(a,id),2))),DOT(t,id),DOT(t,user_id))
{code}
{code:java}
MAP(FILTER(JOIN(AS(travelrecord,t),AS(address,a),EQ(t.id,a.id)),OR(EQ(t.id,1),EQ(a.id,2))),t.id,t.user_id)

{code}
Based on the above, the DOT(t, id) form can be replaced by a string or some 
related object, such as ColumnObject\{db1.travelrecord.id}

 
{code:java}
MAP(FILTER(JOIN(AS(TABLE("travelrecord"),t),AS(TABLE("address"),"a"),EQ(PROPERTY("t","id"),(PROPERTY("a"."id")),OR(EQ(PROPERTY("t","id"),1),EQ(PROPERTY("a","id"),2))),PROPERTY("t","id"),PROPERTY("t","user_id"))
{code}
 

 

The second part of the implementation is to use map, filter these 'extension 
functions', they establish AST, traverse AST when calling RelBuilder function 
to achieve the execution plan construction (I am referring to Apache Pig to do 
this)

What I described above may not be a AST conversion syntax (distinguishing 
matching patterns, extracting AstNode,build new patterns), but may be a design 
like linq's RelBuilder.

 

My project, it can't even run, is a toy.I am still developing.

[syntax 
conversion|https://github.com/junwen12221/describer/blob/master/src/test/java/cn/lightfish/describer/BuilderTest.java]

[bulid 
ast|https://github.com/junwen12221/describer/blob/master/src/main/java/cn/lightfish/wu/Ast.java]

[with 
relbuilder|https://github.com/junwen12221/describer/blob/master/src/main/java/cn/lightfish/wu/AstTest.java]



was (Author: jamie12221):
Thank you for your patience.

I'm actually writing a DSL based on RelBuilder but not based on RelOptRule (not 
originally intended to optimize relational expressions). A friend told me about 
Optgen DSL. So I thought that Calcite's development team might be doing 
something similar.Or everyone is going to do better together. So I sent an 
issue. (The following is another topic.) For example, calcite.piglet is also a 
DSL, which was recently updated, but not designed for Calcite's optimizer.

My DSL design is divided into two parts. The first part is analysis, which is 
simple. Lexer is SQL Lexer. The syntax is a mixture of infix expressions and 
function calls.
 like this:

 

 
{code:java}
join (travelrecord as t,address as a, t.id = a.id)
.filter (t.id = 1 or a.id = 2)
.map(t.id,t.user_id)
{code}
 

Then Method chaining and name will be converted into three possible ways:
{code:java}
MAP(FILTER(JOIN(AS(travelrecord,t),AS(address,a),EQ(DOT(t,id),DOT(a,id))),OR(EQ(DOT(t,id),1),EQ(DOT(a,id),2))),DOT(t,id),DOT(t,user_id))
{code}
{code:java}
MAP(FILTER(JOIN(AS(travelrecord,t),AS(address,a),EQ(t.id,a.id)),OR(EQ(t.id,1),EQ(a.id,2))),t.id,t.user_id)

{code}
Based on the above, the DOT(t, id) form can be replaced by a string or some 
related object, such as ColumnObject\{db1.travelrecord.id}

 
{code:java}
MAP(FILTER(JOIN(AS(TABLE("travelrecord"),t),AS(TABLE("address"),"a"),EQ(PROPERTY("t","id"),(PROPERTY("a"."id")),OR(EQ(PROPERTY("t","id"),1),EQ(PROPERTY("a","id"),2))),PROPERTY("t","id"),PROPERTY("t","user_id"))
{code}
 

 

The second part of the implementation is to use map, filter these 'extension 
functions', they establish AST, traverse AST when calling RelBuilder function 
to achieve the execution plan construction (I am referring to Apache Pig to do 
this)

What I described above may not be a AST conversion syntax (distinguishing 
matching patterns, extracting AstNode,build new patterns), but may be a design 
like linq's RelBuilder.

 

My project, it can't even run, is a toy.I am still developing.

[syntax 
conversion|https://github.com/junwen12221/describer/blob/master/src/test/java/cn/lightfish/describer/BuilderTest.java]

[bulid 
ast|https://github.com/junwen12221/describer/blob/master/src/main/java/cn/lightfish/wu/Ast.java]

> a RelOptRule-based text DSL
> ---------------------------
>
>                 Key: CALCITE-3470
>                 URL: https://issues.apache.org/jira/browse/CALCITE-3470
>             Project: Calcite
>          Issue Type: New Feature
>            Reporter: jamie12221
>            Priority: Trivial
>
> Is there a development plan to convert a structure based on a 
> RelOptRule-based text DSL to express relational expressions to generate 
> optimization rules like Optgen of 
> Cockroach.[building-cost-based-sql-optimizer?|[https://www.cockroachlabs.com/blog/building-cost-based-sql-optimizer/]]
>  



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to