Nota
L'accesso a questa pagina richiede l'autorizzazione. È possibile provare ad accedere o modificare le directory.
L'accesso a questa pagina richiede l'autorizzazione. È possibile provare a modificare le directory.
L'indice <indexValue> è fuori dai limiti. La matrice include elementi <arraySize>. Usare try_element_at per tollerare l'accesso all'elemento in corrispondenza dell'indice non valido e restituire invece NULL. Se necessario, impostare <ansiConfig> su "false" per ignorare questo errore.
Parameters
- indexValue: indice richiesto nella matrice.
- arraySize: cardinalità della matrice.
- ansiConfig: impostazione di configurazione per modificare la modalità ANSI.
Spiegazione
indexValuesupera il limite degli elementi di matrice definiti per un'espressione element_at(arrayExpr, indexValue)o elt(arrayExpr, indexValue).
Il valore deve essere compreso tra -arraySize e arraySize, escluso 0.
Mitigazione
La mitigazione per questo errore dipende dalla causa:
La cardinalità della matrice è inferiore al previsto?
Correggere la matrice di input ed eseguire nuovamente la query.
È stato calcolato erroneamente
indexValue?Modificare
indexValueed eseguire nuovamente la query.Si prevede di ottenere un valore
NULLda restituire per gli elementi al di fuori della cardinalità dell'indice?Se è possibile modificare l'espressione, utilizzare try_element_at(arrayExpr, indexValue) per gestire i riferimenti fuori dai limiti.
Se non è possibile modificare l'espressione, come ultima risorsa, impostare temporaneamente
ansiConfigsufalseper tollerare riferimenti fuori limite.
Examples
-- An INVALID_ARRAY_INDEX_IN_ELEMENT_AT error because of mismatched indexing
> SELECT element_at(array('a', 'b', 'c'), index) FROM VALUES(1), (4) AS T(index);
[INVALID_ARRAY_INDEX_IN_ELEMENT_AT] The index 4 is out of bounds. The array has 3 elements. If necessary set "ANSI_MODE" to false to bypass this error.
-- Increase the aray size to cover the index
> SELECT element_at(array('a', 'b', 'c', 'd'), index) FROM VALUES(1), (4) AS T(index);
a
d
-- Adjusting the index to match the array
> SELECT element_at(array('a', 'b', 'c'), index) FROM VALUES(1), (3) AS T(index);
a
c
-- Tolerating out of bound array index with adjustment to 1-based indexing
> SELECT try_element_at(array('a', 'b', 'c'), index) FROM VALUES(1), (4) AS T(index);
a
NULL
-- Tolerating out of bound by setting ansiConfig in Databricks SQL
> SET ANSI_MODE = false;
> SELECT element_at(array('a', 'b', 'c'), index) FROM VALUES(1), (4) AS T(index);
a
NULL
> SET ANSI_MODE = true;
-- Tolerating out of bound by setting ansiConfig in Databricks Runtime
> SET spark.sql.ansi.enabled = false;
> SELECT element_at(array('a', 'b', 'c'), index) FROM VALUES(1), (4) AS T(index);
a
NULL
> SET spark.sql.ansi.enabled = true;