flink-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fhueske <...@git.apache.org>
Subject [GitHub] flink pull request: [FLINK-3639] add methods for registering datas...
Date Tue, 22 Mar 2016 20:46:25 GMT
Github user fhueske commented on a diff in the pull request:

    https://github.com/apache/flink/pull/1827#discussion_r57065751
  
    --- Diff: flink-libraries/flink-table/src/main/scala/org/apache/flink/api/java/table/TableEnvironment.scala
---
    @@ -87,5 +90,72 @@ class TableEnvironment {
         new JavaBatchTranslator(config).translate[T](table.relNode)(typeInfo)
       }
     
    -}
    +  /**
    +   * Registers a DataSet under a unique name, so that it can be used in SQL queries.
    +   * The fields of the DataSet type are used to name the Table fields.
    +   * @param name the Table name
    +   * @param dataset the DataSet to register
    +   */
    +  def registerDataSet[T](name: String, dataset: DataSet[T]): Unit = {
    +
    +    val (fieldNames, fieldIndexes) = TranslationContext.getFieldInfo[T](dataset.getType)
    +    val dataSetTable = new DataSetTable[T](
    +      dataset,
    +      fieldIndexes,
    +      fieldNames
    +    )
    +    TranslationContext.addAndRegisterDataSet(dataSetTable, name)
    +  }
    +
    +  /**
    +   * Registers a DataSet under a unique name, so that it can be used in SQL queries.
    +   * The fields of the DataSet type are renamed to the given set of fields.
    +   *
    +   * @param name the Table name
    +   * @param dataset the DataSet to register
    +   * @param fields the Table field names
    +   */
    +  def registerDataSet[T](name: String, dataset: DataSet[T], fields: String): Unit = {
    +
    +    val exprs = ExpressionParser
    +      .parseExpressionList(fields)
    +      .toArray
    +
    +    val (fieldNames, fieldIndexes) = TranslationContext.getFieldInfo[T](dataset.getType,
exprs)
     
    +    val dataSetTable = new DataSetTable[T](
    +      dataset,
    +      fieldIndexes.toArray,
    +      fieldNames.toArray
    +    )
    +    TranslationContext.addAndRegisterDataSet(dataSetTable, name)
    +  }
    +
    +  /**
    +   * Registers a Table under a unique name, so that it can be used in SQL queries.
    +   * @param name the Table name
    +   * @param table the Table to register
    +   */
    +  def registerTable[T](name: String, table: Table): Unit = {
    +    val tableTable = new TableTable(table.getRelNode())
    +    TranslationContext.registerTable(tableTable, name)
    +  }
    +
    +  /**
    +   * Retrieve a registered Table.
    +   * @param tableName the name under which the Table has been registered
    +   * @return the Table object
    +   */
    +  @throws[TableException]
    +  def scan(tableName: String): Table = {
    +    if (TranslationContext.isRegistered(tableName)) {
    +      val relBuilder = TranslationContext.getRelBuilder
    +      relBuilder.scan(tableName)
    +      new Table(relBuilder.build(), relBuilder)
    +    }
    +    else {
    +      throw new TableException("Table \"" + tableName + "\" was not found in the registry.")
    --- End diff --
    
    Strings can be build with Scala like this `s"Table \"$tableName\" was not found in the
registry."`


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message