h3_try_validate function (Databricks SQL)

Returns the input value, that is of type BIGINT or STRING, if it corresponds to a valid H3 cell, or NULL otherwise. In the case of STRING input, any leading zeros are trimmed.

Requires: SQL warehouse version 2022.35 or higher. This version is available in the Preview channel.

Syntax

h3_try_validate ( h3CellIdExpr )

Arguments

  • h3CellIdExpr: A BIGINT expression, or a STRING expression that is expected to represent a valid H3 cell ID.

Returns

A value of the same type as the type of the h3CellIdExpr expression, and equal to the value of the input h3CellIdExpr expression, or NULL. In the case of STRING input, any leading zeros are trimmed.

The function returns NULL if the input is NULL. The function can return NULL for non-NULL inputs.

Examples

-- Simple example taking a long as input.
> SELECT h3_try_validate(590112357393367039)
  590112357393367039

-- Simple example taking a hexadecimal string as input.
> SELECT h3_try_validate('85283473fffffff')
  85283473fffffff

-- Simple taking a long as input, that is not a valid H3 cell ID.
> SELECT h3_try_validate(599686042433355776)
  null