From issues-return-186082-archive-asf-public=cust-asf.ponee.io@flink.apache.org Fri Aug 24 19:10:22 2018 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx-eu-01.ponee.io (Postfix) with SMTP id 9D243180629 for ; Fri, 24 Aug 2018 19:10:21 +0200 (CEST) Received: (qmail 89303 invoked by uid 500); 24 Aug 2018 17:10:20 -0000 Mailing-List: contact issues-help@flink.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@flink.apache.org Delivered-To: mailing list issues@flink.apache.org Received: (qmail 89283 invoked by uid 99); 24 Aug 2018 17:10:20 -0000 Received: from ec2-52-202-80-70.compute-1.amazonaws.com (HELO gitbox.apache.org) (52.202.80.70) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 24 Aug 2018 17:10:20 +0000 From: GitBox To: issues@flink.apache.org Subject: [GitHub] fhueske commented on a change in pull request #6606: [FLINK-10163] [sql-client] Support views in SQL Client Message-ID: <153513062019.2641.14372354003715968149.gitbox@gitbox.apache.org> Date: Fri, 24 Aug 2018 17:10:20 -0000 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit fhueske commented on a change in pull request #6606: [FLINK-10163] [sql-client] Support views in SQL Client URL: https://github.com/apache/flink/pull/6606#discussion_r212621362 ########## File path: docs/dev/table/sqlClient.md ########## @@ -459,6 +466,50 @@ Web interface: http://localhost:8081 {% top %} +SQL Views +--------- + +Views allow to define virtual tables from SQL queries. The view definition is parsed and validated immediately. However, the actual execution happens when the view is accessed during the submission of a general `INSERT INTO` or `SELECT` statement. + +Views can either be defined in [environment files](sqlClient.html#environment-files) or within the CLI session. + +The following example shows how to define multiple views in a file: + +{% highlight yaml %} +views: + - name: MyRestrictedView + query: "SELECT MyField2 FROM MyTableSource" + - name: MyComplexView + query: > + SELECT MyField2 + 42, CAST(MyField1 AS VARCHAR) + FROM MyTableSource + WHERE MyField2 > 200 +{% endhighlight %} + +Similar to table sources and sinks, views defined in a session environment file have highest precendence. + +Views can also be created within a CLI session using the `CREATE VIEW` statement: + +{% highlight text %} +CREATE VIEW MyNewView AS SELECT MyField2 FROM MyTableSource +{% endhighlight %} + +The `SHOW VIEW` statement allows for printing a previously created view again: Review comment: I think the way that these commands work is a bit inconsistent with the `SHOW TABLES`, `SHOW FUNCTIONS`, and `DESCRIBE xxx` commands. 1. Views are listed as regular tables when calling `SHOW TABLES`. * List tables and views together, but mark views as views * Or add a `SHOW VIEWS` to only list views (and only list tables with `LIST TABLES`) 2. The schema of a view is returned with `DESCRIBE xxx`. This is fine, but IMO, we should also return the query. Showing schema and query with different commands is not intuitive to me. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: users@infra.apache.org With regards, Apache Git Services