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

xingoo commented on FLINK-15579:
--------------------------------

Hi [~lzljs3620320] ,

how can i use upsert in batch jdbc sink. 
{code:java}
//代码占位符
case upsertSink: UpsertStreamTableSink[T] =>
  
  // 这里什么时候是true?
  val isAppendOnlyTable = UpdatingPlanChecker.isAppendOnly(this)

  upsertSink.setIsAppendOnly(isAppendOnlyTable)
  // 这里什么时候才能获取到keys?
  val tableKeys = {
    val sinkFieldNames = upsertSink.getTableSchema.getFieldNames
    UpdatingPlanChecker.getUniqueKeyFields(getInput, planner, sinkFieldNames) 
match {
      case Some(keys) => keys.sortBy(_.length).headOption
      case None => None
    }
  }
{code}

> UpsertStreamTableSink should work on batch mode
> -----------------------------------------------
>
>                 Key: FLINK-15579
>                 URL: https://issues.apache.org/jira/browse/FLINK-15579
>             Project: Flink
>          Issue Type: Bug
>          Components: Table SQL / Planner
>    Affects Versions: 1.9.2, 1.10.0
>            Reporter: Shu Li Zheng
>            Assignee: Shu Li Zheng
>            Priority: Major
>              Labels: pull-request-available
>             Fix For: 1.11.0
>
>          Time Spent: 40m
>  Remaining Estimate: 0h
>
> Because JDBCTableSourceSinkFactory.createStreamTableSink() create 
> JDBCUpsertTableSink. But BatchExecSink can not work with 
> UpsertStreamTableSink.
> {code:scala}
>   override protected def translateToPlanInternal(
>       planner: BatchPlanner): Transformation[Any] = {
>     val resultTransformation = sink match {
>       case _: RetractStreamTableSink[T] | _: UpsertStreamTableSink[T] =>
>         throw new TableException("RetractStreamTableSink and 
> UpsertStreamTableSink is not" +
>           " supported in Batch environment.")
> {code}
> DDL like:
> CREATE TABLE USER_RESULT(
> NAME VARCHAR,
> CITY VARCHAR,
> SCORE BIGINT
> ) WITH (
> 'connector.type' = 'jdbc',
> 'connector.url' = '',
> 'connector.table' = '',
> 'connector.driver' = 'com.mysql.cj.jdbc.Driver',
> 'connector.username' = 'root',
> 'connector.password' = '',
> 'connector.write.flush.interval' = '1s')



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

Reply via email to