Κοινή χρήση μέσω


h3_compact function

Applies to: check marked yes Databricks SQL check marked yes Databricks Runtime 11.3 LTS and above

Compacts the input set of H3 cells. The compacted set covers the same set of H3 cells as the original one.

Syntax

h3_compact ( h3CellIdsExpr )

Arguments

  • h3CellIdsExpr: An ARRAY of BIGINTs expression, or an ARRAY of hexadecimal STRINGs expression representing an array of H3 cell IDs.

Returns

An ARRAY of H3 cell IDs of the same type as the values in the input ARRAY expression h3CellIdsExpr.

The function returns NULL if the input is NULL. The function does partial validation regarding whether the input argument is a valid H3 cell ID. A necessary, but not sufficient condition for a valid H3 ID is that its value is between 0x08001fffffffffff and 0x08ff3b6db6db6db6. The behavior of the function is undefined if any of the cell IDs in the input ARRAY is not a valid cell ID. NULL values in the input array are ignored.

Error conditions

  • If h3CellIdExpr is a STRING that cannot be converted to a BIGINT or corresponds to a BIGINT value that is smaller than 0x08001fffffffffff or larger than 0x08ff3b6db6db6db6, the function returns H3_INVALID_CELL_ID.

Examples

-- Example where the input is an ARRAY of BIGINTs
> SELECT h3_compact(ARRAY(599686042433355775,599686030622195711,599686044580839423,599686038138388479,599686043507097599,599686015589810175,599686014516068351,599686034917163007,599686029548453887,599686032769679359,599686198125920255,599686040285872127,599686041359613951,599686039212130303,599686023106002943,599686027400970239,599686013442326527,599686012368584703,599686018811035647));
      [599686030622195711,599686015589810175,599686014516068351,599686034917163007,599686029548453887,599686032769679359,599686198125920255,599686023106002943,599686027400970239,599686013442326527,599686012368584703,599686018811035647,595182446027210751]

-- Example where the input is an ARRAY of hexadecimal STRINGs
> SELECT h3_compact(ARRAY('85283473fffffff', '85283447fffffff', '8528347bfffffff', '85283463fffffff', '85283477fffffff', '8528340ffffffff', '8528340bfffffff', '85283457fffffff', '85283443fffffff', '8528344ffffffff', '852836b7fffffff', '8528346bfffffff', '8528346ffffffff', '85283467fffffff', '8528342bfffffff', '8528343bfffffff', '85283407fffffff', '85283403fffffff', '8528341bfffffff'));
 [85283447fffffff, 8528340ffffffff, 8528340bfffffff, 85283457fffffff, 85283443fffffff, 8528344ffffffff, 852836b7fffffff, 8528342bfffffff, 8528343bfffffff, 85283407fffffff, 85283403fffffff, 8528341bfffffff, 8428347ffffffff]

-- Example where the input ARRAY consists of a single element (and thus cannot be compacted further).
> SELECT h3_compact(ARRAY('85283473fffffff'));
 [85283473fffffff]

-- Example where we compare the size of the 2-ring of an H3 cell with its compacted version.
> SELECT ARRAY_SIZE(h3_kring(599686042433355775, 2)), ARRAY_SIZE(h3_compact(h3_kring(599686042433355775, 2)))
 19 13

-- Example where one of the cell IDs is out of range.
> SELECT h3_compact(ARRAY(599686042433355775, 0))
  [H3_INVALID_CELL_ID] 0 is not a valid H3 cell ID