maropu commented on a change in pull request #29056:
URL: https://github.com/apache/spark/pull/29056#discussion_r453384603



##########
File path: docs/sql-ref-syntax-qry-select-lateral-view.md
##########
@@ -0,0 +1,123 @@
+---
+layout: global
+title: LATERAL VIEW Clause
+displayTitle: LATERAL VIEW Clause
+license: |
+  Licensed to the Apache Software Foundation (ASF) under one or more
+  contributor license agreements.  See the NOTICE file distributed with
+  this work for additional information regarding copyright ownership.
+  The ASF licenses this file to You under the Apache License, Version 2.0
+  (the "License"); you may not use this file except in compliance with
+  the License.  You may obtain a copy of the License at
+
+     http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+---
+
+### Description
+
+`LATERAL VIEW` clause  is used in conjunction with user-defined table 
generating functions such as explode(), a UDTF generates zero or more output 
rows foreach input row. A lateral view first applies the UDTF to each row of 
base table and then joins resulting output rows to the input rows to form a 
virtual table having the supplied table alias.
+ 
+
+### Syntax
+
+```sql
+LATERAL VIEW [ OUTER ] { udtf_Expression [ table_Alias ] AS column_alias [ , 
... ] } [ ... ]
+```
+
+### Parameters
+
+* **OUTER**
+
+    If `LATERAL VIEW` is used without `OUTER`, and `udtf_Expression` return 
empty, then no results will be output in select.
+    If `LATERAL VIEW` is used with `OUTER`, and `udtf_Expression` return 
empty, then results will be output normally with `NULL` as `udtf_Expression` 
output.  .
+    
+* **udtf_Expression**
+
+    This expression will output an vitual table with single input row.
+    
+* **table_Alias**
+
+    It is the alias for `udtf_Expression`, which is optional.
+     
+* **column_alias**
+
+    It lists the column alias of `udtf_Expression`, which may be used in 
output rows, we may have multiple alias if `udtf_Expression` have multiple 
output columns.
+         
+### Examples
+
+```sql
+CREATE TABLE person (id INT, name STRING, age INT, class INT, address STRING);
+INSERT INTO person VALUES
+    (100, 'John', 30, 1, 'Street 1'),
+    (200, 'Mary', NULL, 1, 'Street 2'),
+    (300, 'Mike', 80, 3, 'Street 3'),
+    (400, 'Dan',  50, 4, 'Street 4');
+
+SELECT * FROM person
+LATERAL VIEW EXPLODE(ARRAY(30,60)) tabelName AS c_age
+LATERAL VIEW EXPLODE(ARRAY(40,80)) AS d_age;
++------+-------+-------+--------+-----------+--------+--------+--+
+| 100  | John  | 30    | 1      | Street 1  | 30     | 40     |
+| 100  | John  | 30    | 1      | Street 1  | 30     | 80     |
+| 100  | John  | 30    | 1      | Street 1  | 60     | 40     |
+| 100  | John  | 30    | 1      | Street 1  | 60     | 80     |
+| 200  | Mary  | NULL  | 1      | Street 2  | 30     | 40     |
+| 200  | Mary  | NULL  | 1      | Street 2  | 30     | 80     |
+| 200  | Mary  | NULL  | 1      | Street 2  | 60     | 40     |
+| 200  | Mary  | NULL  | 1      | Street 2  | 60     | 80     |
+| 300  | Mike  | 80    | 3      | Street 3  | 30     | 40     |
+| 300  | Mike  | 80    | 3      | Street 3  | 30     | 80     |
+| 300  | Mike  | 80    | 3      | Street 3  | 60     | 40     |
+| 300  | Mike  | 80    | 3      | Street 3  | 60     | 80     |
+| 400  | Dan   | 50    | 4      | Street 4  | 30     | 40     |
+| 400  | Dan   | 50    | 4      | Street 4  | 30     | 80     |
+| 400  | Dan   | 50    | 4      | Street 4  | 60     | 40     |
+| 400  | Dan   | 50    | 4      | Street 4  | 60     | 80     |
++------+-------+-------+--------+-----------+--------+--------+--+
+
+SELECT c_age,COUNT(1) FROM person

Review comment:
       nit: add a space ` c_age, COUNT(1)`




----------------------------------------------------------------
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:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to