.
Operatore (segno punto)
Si applica a: controllo SQL databricks Databricks Runtime
Restituisce un fieldIdentifier
valore in un STRUCT
oggetto o un valore keyIdentifier
in un MAP
oggetto .
Sintassi
structExpr . fieldIdentifier
mapExpr . keyIdentifier
Argomenti
structExpr
: espressioneSTRUCT
.fieldIdentifier
: identificatore per il campo all'interno distructExpr
.mapExpr
: espressioneMAP
con chiavi di tipoSTRING
.keyIdentifier
: identificatore corrispondente a un valore di chiave nell'oggettomapExpr
.
Restituisce
Tipo corrispondente a quello del fieldIdentifier
tipo o del tipo dei mapExpr
valori.
La risoluzione dei nomi ha la precedenza sulla risoluzione di questo operatore.
Ovvero, dato una serie di identificatori separati da punti, Azure Databricks risolverà il nome completo più lungo possibile.
Se il nome risolto è un MAP
o STRUCT
Azure Databricks interpreterà gli identificatori rimanenti usando l'operatore di segno punto.
Quando viene usato con STRUCT
, Azure Databricks verifica l'esistenza dell'oggetto fieldIdentifier
nello struct quando viene compilata l'istruzione.
Se usato con un MAP
oggetto e non esiste alcuna chiave corrispondente keyIdentifier
a , Azure Databricks restituisce null.
Per restituire NULL
invece usare la funzione try_element_at.
Avviso
In Databricks Runtime, se spark.sql.ansi.enabled è false
, il risultato è NULL
se non viene trovata alcuna chiave corrispondente per .mapExpr
Esempi
-- Names take precedence over the dot sign operator
> CREATE SCHEMA a;
> CREATE TABLE a.a(a struct<a INT, b STRING>);
> INSERT INTO a.a VALUES (named_struct('a', 5, 'b', 'Spark'));
-- Column `a` in table `a`
> SELECT a.a FROM a.a;
{"a":5,"b":"Spark"}
-- Field `b` in column `a`
> SELECT a.b FROM a.a;
Spark
-- Column `a` in table `a.a`
> SELECT a.a.a FROM a.a;
{"a":5,"b":"Spark"}
-- Field `a` in column `a` in table `a.a`
> SELECT a.a.a.a FROM a.a;
5
-- Resolving a map value:
> SELECT map('three', 3).three;
3
-- Resolving a map value using the [ ] notation:
> SELECT map('three', 3)['three']
3
-- Resolving a map value using back quotes:
> SELECT map('서울시', 'Seoul').`서울시`;
Seoul
-- Cannot resolve a non existing key
> SELECT map('three', 3).four;
NULL