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

    https://github.com/apache/flink/pull/3623#discussion_r109965960
  
    --- Diff: 
flink-libraries/flink-table/src/test/scala/org/apache/flink/table/utils/UserDefinedTableFunctions.scala
 ---
    @@ -109,6 +110,133 @@ class TableFunc3(data: String, conf: Map[String, 
String]) extends TableFunction[
       }
     }
     
    +class DynamicSchema extends TableFunction[Row] {
    +
    +  def eval(str: String, column: Int): Unit = {
    +    if (str.contains("#")) {
    +      str.split("#").foreach({ s =>
    +        val row = new Row(column)
    +        row.setField(0, s)
    +        var i = 0
    +        for (i <- 1 until column) {
    +          row.setField(i, s.length)
    +        }
    +        collect(row)
    +      })
    +    }
    +  }
    +
    +  override def getResultType(arguments: java.util.List[AnyRef]): 
TypeInformation[Row] = {
    +    val column = arguments.get(1).asInstanceOf[Int]
    +    val basicTypeInfos = new Array[TypeInformation[_]](column)
    +    basicTypeInfos(0) = BasicTypeInfo.STRING_TYPE_INFO
    +    for (i <- 1 until column) {
    +      basicTypeInfos(i) = BasicTypeInfo.INT_TYPE_INFO
    +    }
    +    new RowTypeInfo(basicTypeInfos: _*)
    +  }
    +}
    +
    +class DynamicSchema0 extends TableFunction[Row] {
    +
    +  def eval(str: String, cols: String): Unit = {
    +    val columns = cols.split(",")
    +
    +    if (str.contains("#")) {
    +      str.split("#").foreach({ s =>
    +        val row = new Row(columns.length)
    +        row.setField(0, s)
    +        for (i <- 1 until columns.length) {
    +          if (columns(i).equals("string")) {
    +            row.setField(i, s.length.toString)
    +          } else if (columns(i).equals("int")) {
    +            row.setField(i, s.length)
    +          }
    +        }
    +        collect(row)
    +      })
    +    }
    +  }
    +
    +  override def getResultType(arguments: java.util.List[AnyRef]): 
TypeInformation[Row] = {
    +    val columnStr = arguments.get(1).asInstanceOf[String]
    +    val columns = columnStr.split(",")
    +
    +    val basicTypeInfos = new Array[TypeInformation[_]](columns.length)
    +    for (i <- 0 until columns.length) {
    +      if (columns(i).equals("string")) {
    +        basicTypeInfos(i) = BasicTypeInfo.STRING_TYPE_INFO
    +      } else if (columns(i).equals("int")) {
    +        basicTypeInfos(i) = BasicTypeInfo.INT_TYPE_INFO
    +      }
    +    }
    +    new RowTypeInfo(basicTypeInfos: _*)
    +  }
    +}
    +
    +class DynamicSchemaWithRexNodes extends TableFunction[Row] {
    +
    +  def eval(str: String, i: Int, si: Int, bi: Int, flt: Double, real: 
Double, d: Double, b: Boolean):
    +  Unit = {
    +    val row = new Row(8)
    +    row.setField(0, str)
    +    row.setField(1, i)
    +    row.setField(2, si)
    +    row.setField(3, bi)
    +    row.setField(4, flt)
    +    row.setField(5, real)
    +    row.setField(6, d)
    +    row.setField(7, b)
    +    collect(row)
    +  }
    +
    +  override def getResultType(arguments: util.List[AnyRef]): 
TypeInformation[Row] = {
    --- End diff --
    
    Can we add a more non primitive types like `Timestamp`?


---
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