flink-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "ASF GitHub Bot (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (FLINK-6442) Extend TableAPI Support Sink Table Registration and ‘insert into’ Clause in SQL
Date Tue, 25 Jul 2017 10:18:00 GMT

    [ https://issues.apache.org/jira/browse/FLINK-6442?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16099824#comment-16099824

ASF GitHub Bot commented on FLINK-6442:

Github user fhueske commented on the issue:

    Hi @lincoln-lil, I think it is a very good idea to strive for consistency with JDBC. Here
is what I think about the proposed methods:
    - `sqlQuery(sql: String): Table`: Looks good to me
    - `sqlUpdate(sql: String): Option[Long]`: This method requires an optional `QueryConfig`
object (either as optional argument or in a second method). We also need a Java version that
does not use `Option` (maybe encode `None` as `-1L`). We should also think about whether we
want the Scala and Java APIs to be consistent.
    - `sql(sql: String): Option[Table]`: I'm not sure about this method. I think it would
rather confuses than helps. IMO, there is a clear separation between `sqlQuery` and `sqlUpdate`
that users have to be aware of. This is even true, if they would use `sql()` because they
would need to handle the returned `Option`. Moreover, we would need to change the signature
of a method which is a more significant change than deprecating the method.
    I think the decision about this API change should not be done in this PR but discussed
on the dev@f.a.o mailing list. Would you like to start a [DISCUSS] thread and propose your
ideas there?
    Regarding the issue of distinguishing `SELECT` queries from `INSERT` or `UPDATE` queries,
we can change `FlinkPlannerImpl.parse()` to call `SqlParser.parseQuery()` instead of `SqlParser.parseStmt()`.
`parseQuery()` accepts `SELECT` queries + `UNION`, `INTERSECT` and `EXCEPT`.
    Thanks, Fabian

> Extend TableAPI Support Sink Table Registration and ‘insert into’ Clause in SQL
> -------------------------------------------------------------------------------
>                 Key: FLINK-6442
>                 URL: https://issues.apache.org/jira/browse/FLINK-6442
>             Project: Flink
>          Issue Type: New Feature
>          Components: Table API & SQL
>            Reporter: lincoln.lee
>            Assignee: lincoln.lee
>            Priority: Minor
> Currently in TableAPI  there’s only registration method for source table,  when we
use SQL writing a streaming job, we should add additional part for the sink, like TableAPI
> {code}
> val sqlQuery = "SELECT * FROM MyTable WHERE _1 = 3"
> val t = StreamTestData.getSmall3TupleDataStream(env)
> tEnv.registerDataStream("MyTable", t)
> // one way: invoke tableAPI’s writeToSink method directly
> val result = tEnv.sql(sqlQuery)
> result.writeToSink(new YourStreamSink)
> // another way: convert to datastream first and then invoke addSink 
> val result = tEnv.sql(sqlQuery).toDataStream[Row]
> result.addSink(new StreamITCase.StringSink)
> {code}
> From the api we can see the sink table always be a derived table because its 'schema'
is inferred from the result type of upstream query.
> Compare to traditional RDBMS which support DML syntax, a query with a target output could
be written like this:
> {code}
> insert into table target_table_name
> [(column_name [ ,...n ])]
> query
> {code}
> The equivalent form of the example above is as follows:
> {code}
>     tEnv.registerTableSink("targetTable", new YourSink)
>     val sql = "INSERT INTO targetTable SELECT a, b, c FROM sourceTable"
>     val result = tEnv.sql(sql)
> {code}
> It is supported by Calcite’s grammar: 
> {code}
>  insert:( INSERT | UPSERT ) INTO tablePrimary
>  [ '(' column [, column ]* ')' ]
>  query
> {code}
> I'd like to extend Flink TableAPI to support such feature.  see design doc: https://goo.gl/n3phK5

This message was sent by Atlassian JIRA

View raw message