Zoltan Borok-Nagy has posted comments on this change. ( http://gerrit.cloudera.org:8080/25216 )
Change subject: IMPALA-14971: [DOCS] Documenation for UNPIVOT clause ...................................................................... Patch Set 4: (15 comments) Thanks for working on this! http://gerrit.cloudera.org:8080/#/c/25216/4/docs/topics/impala_unpivot.xml File docs/topics/impala_unpivot.xml: http://gerrit.cloudera.org:8080/#/c/25216/4/docs/topics/impala_unpivot.xml@41 PS4, Line 41: occur:: nit: occur: http://gerrit.cloudera.org:8080/#/c/25216/4/docs/topics/impala_unpivot.xml@42 PS4, Line 42: target columns nit: this says "target columns", the rest of the page (and the example) says "unpivot columns". Please use one term throughout (also on line 90). http://gerrit.cloudera.org:8080/#/c/25216/4/docs/topics/impala_unpivot.xml@53 PS4, Line 53: operation:<codeblock>SELECT <varname>columns</varname> FROM <varname>table_name</varname> Could you mention what can be the source? It must be a table, view or WITH clause name. A subquery is not accepted, and the source table can't have its own alias, e.g. these are syntax errors: SELECT * FROM (SELECT ...) s UNPIVOT (...) AS t; SELECT * FROM tbl s UNPIVOT (...) AS t; http://gerrit.cloudera.org:8080/#/c/25216/4/docs/topics/impala_unpivot.xml@55 PS4, Line 55: <varname>data_column</varname> FOR <varname>header_column</varname> IN (<varname>column_x</varname> AS '<varname>label_x</varname>', <varname>column_y</varname> AS '<varname>label_y</varname>', ...) The AS clause is optional here, and the label doesn't have to be a string: IN (column_x [AS label_x], column_y [AS label_y], ...) Without AS, the label is the column name as a STRING. With AS, it can be any literal (e.g. v1 AS 1, v2 AS 2), but all labels must have the same type. http://gerrit.cloudera.org:8080/#/c/25216/4/docs/topics/impala_unpivot.xml@56 PS4, Line 56: ) [AS <varname>result_alias</varname>];</codeblock></p> The alias is mandatory, only the AS keyword is optional: ) [AS] result_alias; http://gerrit.cloudera.org:8080/#/c/25216/4/docs/topics/impala_unpivot.xml@61 PS4, Line 61: help you identify the original source column.</li> Please extend this with the rules from line 55: the AS clause is optional and defaults to the column name; all labels must be literals of the same type, otherwise the query fails with "Expressions for the UNPIVOT header column should have the same type". The same label can be used for several columns, but listing the same column twice is an error. http://gerrit.cloudera.org:8080/#/c/25216/4/docs/topics/impala_unpivot.xml@65 PS4, Line 65: the result set by default unless a predicate is applied to filter them.</li> It's worth being explicit here, because Oracle and Spark drop NULLs by default (EXCLUDE NULLS). Something like: Rows are generated for NULL values as well, so the data column contains NULL for them. Impala has no INCLUDE NULLS / EXCLUDE NULLS option; to drop these rows, add WHERE data_column IS NOT NULL to the query. http://gerrit.cloudera.org:8080/#/c/25216/4/docs/topics/impala_unpivot.xml@69 PS4, Line 69: integer nit: INT http://gerrit.cloudera.org:8080/#/c/25216/4/docs/topics/impala_unpivot.xml@70 PS4, Line 70: one:<codeblock>SELECT * FROM s UNPIVOT (a FOR b IN (x AS 'x', y AS 'y') The example uses an undefined table 's' and shows no output. Could you use a self-contained one with output instead? E.g. (from unpivot-clause.test): WITH t1 (a, v1, v2) AS ( VALUES (1, 2, 3), (4, 5, 6) ) SELECT * FROM t1 UNPIVOT ( c FOR b IN (v1 AS 'v1', v2 AS 'v2') ) AS t; +---+---+----+ | a | c | b | +---+---+----+ | 1 | 2 | v1 | | 1 | 3 | v2 | | 4 | 5 | v1 | | 4 | 6 | v2 | +---+---+----+ http://gerrit.cloudera.org:8080/#/c/25216/4/docs/topics/impala_unpivot.xml@90 PS4, Line 90: If your columns have different data : types, you can cast them to a matching data type to complete the operation successfully. This is repeated in the following workaround at L92 http://gerrit.cloudera.org:8080/#/c/25216/4/docs/topics/impala_unpivot.xml@95 PS4, Line 95: with nit: please use upper-cased keywords to make examples consistent http://gerrit.cloudera.org:8080/#/c/25216/4/docs/topics/impala_unpivot.xml@120 PS4, Line 120: subquery The subquery option doesn't work, because the source of UNPIVOT can't be a subquery. Suggestion: Workaround: Define a CTE over one of the tables, and use it as the source of one of the UNPIVOT clauses. http://gerrit.cloudera.org:8080/#/c/25216/4/docs/topics/impala_unpivot.xml@122 PS4, Line 122: GROUP BY This was copied from impala_pivot.xml. UNPIVOT doesn't do a GROUP BY, so please remove it. http://gerrit.cloudera.org:8080/#/c/25216/4/docs/topics/impala_unpivot.xml@124 PS4, Line 124: <p><b>Nested fields as header columns</b></p> This section also came from the PIVOT doc and doesn't apply. In UNPIVOT the header column is a new column name, not an existing column, so it can't be a nested field. The related UNPIVOT restriction is on the IN list: each item must be a top-level column name, so a struct field like s.f1 can't be listed there directly. The workaround is the same: select the field into a column in a CTE, then unpivot that column. http://gerrit.cloudera.org:8080/#/c/25216/4/docs/topics/impala_unpivot.xml@148 PS4, Line 148: 0.11 nit: 0.11s -- To view, visit http://gerrit.cloudera.org:8080/25216 To unsubscribe, visit http://gerrit.cloudera.org:8080/settings Gerrit-Project: Impala-ASF Gerrit-Branch: master Gerrit-MessageType: comment Gerrit-Change-Id: I46973ce1c1a09c8647a8a4b00ae6f76bd6b6c661 Gerrit-Change-Number: 25216 Gerrit-PatchSet: 4 Gerrit-Owner: Sanjana Malhotra <[email protected]> Gerrit-Reviewer: Arnab Karmakar <[email protected]> Gerrit-Reviewer: Impala Public Jenkins <[email protected]> Gerrit-Reviewer: Noemi Pap-Takacs <[email protected]> Gerrit-Reviewer: Sanjana Malhotra <[email protected]> Gerrit-Reviewer: Xuebin Su <[email protected]> Gerrit-Reviewer: Zoltan Borok-Nagy <[email protected]> Gerrit-Comment-Date: Thu, 29 Oct 2026 12:44:31 +0000 Gerrit-HasComments: Yes
