coral icon indicating copy to clipboard operation
coral copied to clipboard

Feature: Consider supporting flink sql

Open caicancai opened this issue 1 year ago • 22 comments

Whether to consider supporting flink sql

caicancai avatar Sep 08 '23 02:09 caicancai

Yes, it is in the roadmap, but as far as I know no one is actively working on it at the moment. Do you have a use case in mind?

wmoustafa avatar Sep 08 '23 16:09 wmoustafa

Since Flink supports streaming, you might check out Coral's incremental view maintenance features as well. It complements streaming on the batch side.

wmoustafa avatar Sep 08 '23 16:09 wmoustafa

FYI @aastha25 @ljfgem @KevinGe00 @yiqiangin

wmoustafa avatar Sep 08 '23 16:09 wmoustafa

Thank you for your answer. I will try this part of the work myself first. If there is any progress, I will be happy to contribute PR.

caicancai avatar Sep 08 '23 16:09 caicancai

Are you thinking of Flink SQL as a dialect on the input or output side? (or which one will you focus on)?

wmoustafa avatar Sep 08 '23 16:09 wmoustafa

Strictly speaking, I don’t think this is a conversion between dialects. I think it is a conversion between models. If it is just a conversion between dialects, why not use ANTLR to extract key information to spell SQL (if you do this, obviously this is a trap)

caicancai avatar Sep 08 '23 16:09 caicancai

你是否认为 Flink SQL 是输入端或输出端的一种方言?(或者你会关注哪一个)?

I have tried the conversion of spark sql before, and I am still learning, and I am more concerned about spark sql and flink sql

caicancai avatar Sep 08 '23 16:09 caicancai

Sorry should have clarified my question. When you said you would consider implementing Flink SQL integration with Coral, did you refer to integration on the input side (Flink SQL to Coral) or the output side (Coral to Flink SQL)?

wmoustafa avatar Sep 08 '23 16:09 wmoustafa

sink

caicancai avatar Sep 08 '23 16:09 caicancai

As in (Coral to Flink SQL)?

wmoustafa avatar Sep 08 '23 17:09 wmoustafa

如(珊瑚到Flink SQL)?

yes

caicancai avatar Sep 08 '23 17:09 caicancai

What I thought before was that maybe it would be easier to use a standard SQL method to convert to any other SQL dialect. But obviously your goals are much bigger

caicancai avatar Sep 08 '23 17:09 caicancai

I hope I can make a contribution to the project in the future, because this is what I wanted to do before

caicancai avatar Sep 08 '23 17:09 caicancai

Thanks @caicancai. Happy to collaborate.

wmoustafa avatar Sep 08 '23 17:09 wmoustafa

Thank you for your patient reply

caicancai avatar Sep 09 '23 02:09 caicancai

@caicancai thank you for picking this line of work. Please refer to the provided sample pseudo-code below to structure your code:

Convert(RelNode coralRelNode) {
          // Step 1: Convert CoralRel IR to CoralSqlNode
          CoralRelToSqlNodeConverter rel2sql = new CoralRelToSqlNodeConverter();
          SqlNode coralSqlNode = rel2sql.convert(coralRelNode);

         // Step 2: Apply Coral to Flink SQL transformations using a custom SqlShuttle
          SqlNode flinkSqlNode = coralSqlNode.accept(new CoralToFlinkSqlNodeConverter())

         // Step 3: Convert the resulting Flink SQL to a string
          String flinkSQL = flinkSqlNode.toSqlString();
}

In this code:

  1. CoralRelToSqlNodeConverter is an existing class in Coral that converts Coral IR represented as a RelNode to its SqlNode representation.
  2. To implement the CoralToFlinkSqlNodeConverter, please use DataTypeDerivedSqlCallConverter and CoralToTrinoSqlCallConverter as a reference. Each transformer in the SqlShuttle for this converter should extend SqlCallTransformer to modify the SqlCalls in the input.

By following this structure, you can effectively model your code for converting Coral IR to Flink SQL.

aastha25 avatar Sep 13 '23 17:09 aastha25

Re-opening since Flink is not yet supported.

wmoustafa avatar Sep 13 '23 21:09 wmoustafa

@aastha25 Thanks for the tip, I'll try it

caicancai avatar Sep 14 '23 07:09 caicancai

I'm going to start trying this part out

caicancai avatar Sep 17 '23 03:09 caicancai

I want to ask if sink is fully supported by spark sql.

caicancai avatar Sep 17 '23 03:09 caicancai

Coral to Spark SQL is fully supported. If you notice small differences in the class organization compared to what @aastha25 shared above, expect Spark module to converge to that pattern (which @aastha25 shared) soon.

wmoustafa avatar Sep 18 '23 16:09 wmoustafa

@wmoustafa Sorry, I was a little busy a while ago, I will start to try now. I want to put this idea into practice

caicancai avatar Dec 07 '23 06:12 caicancai