stack
table-värd generatorfunktion
Gäller för: Databricks SQL
Databricks Runtime
Separerar expr1
, ..., exprN
i numRows
rader.
Syntax
stack(numRows, expr1 [, ...] )
Argument
-
numRows
: EnINTEGER
literal större än 0 som anger antalet rader som skapas. -
exprN
: Ett uttryck av valfri typ. Vilken typ av som helstexprN
måste matcha typen avexpr(N+numRows)
.
Returer
En set med numRows
rader, som innehåller max(1, (N/numRows))
columns och produceras av denna funktion.
En ofullständig rad är vadderad med NULL
s.
Som standard ges det producerade columns namnet col0, … col(n-1)
.
stack
motsvarar VALUES
-satsen.
Gäller för:
Databricks Runtime 12.1 och tidigare:
stack
kan bara placeras iSELECT
list som rot för ett uttryck eller efter en LATERAL VIEW. När funktionen placeras iSELECT
list får det inte finnas någon annan generatorfunktion i sammaSELECT
list eller , annars utlöses UNSUPPORTED_GENERATOR.MULTI_GENERATOR.Gäller för:
Databricks SQL
Databricks Runtime 12.2 LTS och senare:
Anrop från LATERAL VIEW-satsen eller
SELECT
list är inaktuellt. Anropastack
i stället som en table_reference.
Exempel
Gäller för: Databricks Runtime 12.1 och tidigare:
> SELECT 'hello', stack(2, 1, 2, 3) AS (first, second), 'world';
hello 1 2 world
hello 3 NULL world
> SELECT 'hello', stack(2, 1, 2, 3) AS (first, second), stack(2, 'a', 'b') AS (third) 'world';
Error: UNSUPPORTED_GENERATOR.MULTI_GENERATOR
-- Equivalent usage of VALUES
> SELECT 'hello', s1.*, s2.*, 'world'
FROM VALUES(1, 2), (3, NULL) AS s1(first, second),
VALUES('a'), ('b') AS s2(third);
hello 1 2 a world
hello 3 NULL a world
hello 1 2 b world
hello 3 NULL b world
Gäller för: Databricks SQL
Databricks Runtime 12.2 LTS och senare:
> SELECT 'hello', s.*, 'world'
FROM stack(2, 1, 2, 3) AS s(first, second);
hello 1 2 world
hello 3 NULL world
> SELECT 'hello', s1.*, s2.*, 'world'
FROM stack(2, 1, 2, 3) AS s1(first, second),
stack(2, 'a', 'b') AS s2(third);
hello 1 2 a world
hello 3 NULL a world
hello 1 2 b world
hello 3 NULL b world