fhueske commented on a change in pull request #10078: [FLINK-14486][table-api, docs] Update documentation regarding Temporary Objects URL: https://github.com/apache/flink/pull/10078#discussion_r343210000
########## File path: docs/dev/table/common.md ########## @@ -345,133 +370,139 @@ tableEnv.registerTable("projectedTable", projTable) table_env = ... # see "Create a TableEnvironment" section # table is the result of a simple projection query -proj_table = table_env.scan("X").select(...) +proj_table = table_env.from_path("X").select(...) # register the Table projTable as table "projectedTable" table_env.register_table("projectedTable", proj_table) {% endhighlight %} </div> </div> -**Note:** A registered `Table` is treated similarly to a `VIEW` as known from relational database systems, i.e., the query that defines the `Table` is not optimized but will be inlined when another query references the registered `Table`. If multiple queries reference the same registered `Table`, it will be inlined for each referencing query and executed multiple times, i.e., the result of the registered `Table` will *not* be shared. +**Note:** `Table` objects are similar to `VIEW`'s from relational database +systems, i.e., the query that defines the `Table` is not optimized but will be inlined when another +query references the registered `Table`. If multiple queries reference the same registered `Table`, +it will be inlined for each referencing query and executed multiple times, i.e., the result of the +registered `Table` will *not* be shared. {% top %} -### Register a TableSource - -A `TableSource` provides access to external data which is stored in a storage system such as a database (MySQL, HBase, ...), a file with a specific encoding (CSV, Apache \[Parquet, Avro, ORC\], ...), or a messaging system (Apache Kafka, RabbitMQ, ...). - -Flink aims to provide TableSources for common data formats and storage systems. Please have a look at the [Table Sources and Sinks]({{ site.baseurl }}/dev/table/sourceSinks.html) page for a list of supported TableSources and instructions for how to build a custom `TableSource`. +#### Connector tables -A `TableSource` is registered in a `TableEnvironment` as follows: +It is also possible to create a `TABLE` as known from relational databases from a [connector]({{ site.baseurl }}/dev/table/connect.html) declaration. +The connector describes the external system that stores the data of a table. Storage systems such as Apacha Kafka or a regular file system can be declared here. <div class="codetabs" markdown="1"> <div data-lang="java" markdown="1"> {% highlight java %} -// get a TableEnvironment -TableEnvironment tableEnv = ...; // see "Create a TableEnvironment" section - -// create a TableSource -TableSource csvSource = new CsvTableSource("/path/to/file", ...); - -// register the TableSource as table "CsvTable" -tableEnv.registerTableSource("CsvTable", csvSource); +tableEnvironment + .connect(...) + .withFormat(...) + .withSchema(...) + .inAppendMode() + .createTemporaryTable("MyTable") {% endhighlight %} </div> <div data-lang="scala" markdown="1"> {% highlight scala %} -// get a TableEnvironment -val tableEnv = ... // see "Create a TableEnvironment" section - -// create a TableSource -val csvSource: TableSource = new CsvTableSource("/path/to/file", ...) - -// register the TableSource as table "CsvTable" -tableEnv.registerTableSource("CsvTable", csvSource) +tableEnvironment + .connect(...) + .withFormat(...) + .withSchema(...) + .inAppendMode() + .createTemporaryTable("MyTable") {% endhighlight %} </div> <div data-lang="python" markdown="1"> {% highlight python %} -# get a TableEnvironment -table_env = ... # see "Create a TableEnvironment" section - -# create a TableSource -csv_source = CsvTableSource("/path/to/file", ...) +table_environment \ + .connect(...) \ + .with_format(...) \ + .with_schema(...) \ + .in_append_mode() \ + .create_temporary_table("MyTable") +{% endhighlight %} +</div> -# register the TableSource as table "csvTable" -table_env.register_table_source("csvTable", csv_source) +<div data-lang="DDL" markdown="1"> +{% highlight sql %} +tableEnvironment.sqlUpdate("CREATE [TEMPORARY] TABLE MyTable (...) WITH (...)") {% endhighlight %} </div> </div> -**Note:** A `TableEnvironment` used for Blink planner only accepts `StreamTableSource`, `LookupableTableSource` and `InputFormatTableSource`, and a `StreamTableSource` used for Blink planner on batch must be bounded. +### Expanding table identifiers -{% top %} +Tables are always registered with a 3 part identifier consisting of catalog, database, and +table name. The first two parts are optional and if they are not provided the set default values will +be used. Identifiers follow SQL requirements which means that they can be escaped with ``` character. +Additionally all SQL reserved keywords must be escaped. -### Register a TableSink +<div class="codetabs" markdown="1"> +<div data-lang="java" markdown="1"> +{% highlight java %} +TableEnvironment tEnv = ...; +tEnv.useCatalog("default_catalog"); Review comment: These are the defaults anyway right? If so, we should use different names here, IMO. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services