Github user fhueske commented on a diff in the pull request: https://github.com/apache/flink/pull/3623#discussion_r109964147 --- 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) --- End diff -- can be simplified to ``` val basicTypeInfos = for (c <- columns) yield c match { case "string" => BasicTypeInfo.STRING_TYPE_INFO case "int" => BasicTypeInfo.INT_TYPE_INFO } ```
--- 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. ---