Github user twalthr commented on a diff in the pull request:

    https://github.com/apache/flink/pull/4488#discussion_r131705390
  
    --- Diff: 
flink-libraries/flink-table/src/main/scala/org/apache/flink/table/api/StreamTableEnvironment.scala
 ---
    @@ -677,12 +748,43 @@ abstract class StreamTableEnvironment(
     
         val rootParallelism = plan.getParallelism
     
    -    conversion match {
    -      case mapFunction: MapFunction[CRow, A] =>
    -        plan.map(mapFunction)
    -          .returns(tpe)
    -          .name(s"to: ${tpe.getTypeClass.getSimpleName}")
    -          .setParallelism(rootParallelism)
    +    val rowtimeFields = logicalType.getFieldList.asScala
    +      .filter(f => FlinkTypeFactory.isRowtimeIndicatorType(f.getType))
    +
    +    if (rowtimeFields.isEmpty) {
    +      // to rowtime field to set
    +
    +      conversion match {
    +        case mapFunction: MapFunction[CRow, A] =>
    +          plan.map(mapFunction)
    +            .returns(tpe)
    +            .name(s"to: ${tpe.getTypeClass.getSimpleName}")
    +            .setParallelism(rootParallelism)
    +      }
    +    } else if (rowtimeFields.size == 1) {
    +      // set the only rowtime field as event-time timestamp for DataStream
    +
    +      val mapFunction = conversion match {
    +        case mapFunction: MapFunction[CRow, A] => mapFunction
    +        case _ => new MapFunction[CRow, A] {
    +          override def map(cRow: CRow): A = cRow.asInstanceOf[A]
    +        }
    +      }
    +
    +      plan.process(
    +        new WrappingTimestampSetterProcessFunction[A](
    +          mapFunction,
    +          rowtimeFields.head.getIndex))
    +        .returns(tpe)
    +        .name(s"to: ${tpe.getTypeClass.getSimpleName}")
    +        .setParallelism(rootParallelism)
    +
    +    } else {
    +      throw new TableException(
    +        s"Found more than one rowtime field: 
[${rowtimeFields.map(_.getName).mkString(", ")}] in " +
    +          s"the table that should be converted to a DataStream.\n" +
    +          s"Please select the rowtime field that should be used as 
event-time timestamp for the " +
    +          s"DataStream by casting all other fields to TIMESTAMP or LONG.")
    --- End diff --
    
    I would just recommend TIMESTAMP. LONG is still not supported.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

Reply via email to