flink-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vasia <...@git.apache.org>
Subject [GitHub] flink pull request: [FLINK-2828] [tableAPI] Add TableSource interf...
Date Tue, 26 Apr 2016 14:44:41 GMT
Github user vasia commented on a diff in the pull request:

    https://github.com/apache/flink/pull/1939#discussion_r61098440
  
    --- Diff: docs/apis/batch/libs/table.md ---
    @@ -67,6 +67,165 @@ The central concept of the Table API is a `Table` which represents
a table with
     
     The following sections show by example how to use the Table API embedded in the Scala
and Java DataSet APIs.
     
    +### Registering Tables to and Accessing Tables from TableEnvironments
    +
    +`TableEnvironment`s have an internal table catalog to which tables can be registered
with a unique name. After registration, a table can be accessed from the `TableEnvironment`
by its name. Tables can be registered in different ways.
    +
    +#### Register a DataSet
    +
    +A `DataSet` is registered as a `Table` in a `BatchTableEnvironment` as follows:
    +
    +<div class="codetabs" markdown="1">
    +<div data-lang="java" markdown="1">
    +{% highlight java %}
    +ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
    +BatchTableEnvironment tableEnv = TableEnvironment.getTableEnvironment(env);
    +
    +// register the DataSet cust as table "Customers" with fields derived from the dataset
    +tableEnv.registerDataSet("Customers", cust)
    +
    +// register the DataSet ord as table "Orders" with fields user, product, and amount
    +tableEnv.registerDataSet("Orders", ord, "user, product, amount");
    +{% endhighlight %}
    +</div>
    +
    +<div data-lang="scala" markdown="1">
    +{% highlight scala %}
    +val env = ExecutionEnvironment.getExecutionEnvironment
    +val tableEnv = TableEnvironment.getTableEnvironment(env)
    +
    +// register the DataSet cust as table "Customers" with fields derived from the dataset
    +tableEnv.registerDataSet("Customers", cust)
    +
    +// register the DataSet ord as table "Orders" with fields user, product, and amount
    +tableEnv.registerDataSet("Orders", ord, 'user, 'product, 'amount)
    +{% endhighlight %}
    +</div>
    +</div>
    +
    +*Note: DataSet table names are not allowed to follow the `^_DataSetTable_[0-9]+` pattern,
as these are reserved for internal use only.*
    +
    +#### Register a DataStream
    +
    +A `DataStream` is registered as a `Table` in a `StreamTableEnvironment` as follows:
    +
    +<div class="codetabs" markdown="1">
    +<div data-lang="java" markdown="1">
    +{% highlight java %}
    +StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
    +StreamTableEnvironment tableEnv = TableEnvironment.getTableEnvironment(env);
    +
    +// register the DataStream cust as table "Customers" with fields derived from the datastream
    +tableEnv.registerDataStream("Customers", cust)
    +
    +// register the DataStream ord as table "Orders" with fields user, product, and amount
    +tableEnv.registerDataStream("Orders", ord, "user, product, amount");
    +{% endhighlight %}
    +</div>
    +
    +<div data-lang="scala" markdown="1">
    +{% highlight scala %}
    +val env = StreamExecutionEnvironment.getExecutionEnvironment
    +val tableEnv = TableEnvironment.getTableEnvironment(env)
    +
    +// register the DataStream cust as table "Customers" with fields derived from the datastream
    +tableEnv.registerDataStream("Customers", cust)
    +
    +// register the DataStream ord as table "Orders" with fields user, product, and amount
    +tableEnv.registerDataStream("Orders", ord, 'user, 'product, 'amount)
    +{% endhighlight %}
    +</div>
    +</div>
    +
    +*Note: DataStream table names are not allowed to follow the `^_DataStreamTable_[0-9]+`
pattern, as these are reserved for internal use only.*
    +
    +#### Register a Table
    +
    +A `Table` that originates from a Table API operation or a SQL query is registered in
a `TableEnvironemnt` as follows:
    +
    +<div class="codetabs" markdown="1">
    +<div data-lang="java" markdown="1">
    +{% highlight java %}
    +// works for StreamExecutionEnvironment identically
    +ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
    +BatchTableEnvironment tableEnv = TableEnvironment.getTableEnvironment(env);
    +
    +// convert a DataSet into a Table
    +Table custT = tableEnv
    +  .toTable(custDs, "name, zipcode")
    +  .where("zipcode = '12345'")
    +  .select("name")
    +
    +// register the Table custT as table "custNames"
    +tableEnv.registerTable("custNames", custT)
    +{% endhighlight %}
    +</div>
    +
    +<div data-lang="scala" markdown="1">
    +{% highlight scala %}
    +// works for StreamExecutionEnvironment identically
    +val env = ExecutionEnvironment.getExecutionEnvironment
    +val tableEnv = TableEnvironment.getTableEnvironment(env)
    +
    +// convert a DataSet into a Table
    +val custT = custDs
    +  .toTable(tableEnv, 'name, 'zipcode)
    +  .where('zipcode === "12345")
    +  .select('name)
    +
    +// register the Table custT as table "custNames"
    +tableEnv.registerTable("custNames", custT)
    +{% endhighlight %}
    +</div>
    +</div>
    +
    +A registered `Table` that originates from a Table API operation or SQL query is treated
similarly as a view as known from relational DBMS, i.e., it can be inlined when optimizing
the query.
    +
    +#### Register an external table using a TableSource
    --- End diff --
    
    Capitalize Table to be consistent with previous titles?


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