h3_compact 函数

适用于:check marked yes Databricks SQL check marked yes Databricks Runtime 11.2 及更高版本

压缩 H3 单元格的输入集。 压缩集涵盖与原始集相同的 H3 单元格集。

语法

h3_compact ( h3CellIdsExpr )

参数

  • h3CellIdsExpr:表示 H3 单元格 ID 数组的 BIGINT 表达式的 ARRAY 或十六进制 STRING 表达式的 ARRAY。

返回

与输入 ARRAY 表达式 h3CellIdsExpr 中的值类型相同的 H3 单元格 ID 的 ARRAY。

如果输入为 NULL,则该函数返回 NULL。 该函数对输入参数是否为有效的 H3 单元格 ID 进行部分验证。 有效 H3 ID 的必要不充分条件是其值介于 0x08001fffffffffff0x08ff3b6db6db6db6 之间。 如果输入 ARRAY 中有任何单元格 ID 不是有效的单元格 ID,则表示该函数的行为未定义。 输入数组中的 NULL 值将被忽略。

错误条件

  • 如果 h3CellIdExpr 是无法转换为 BIGINT 的 STRING 或对应于小于 0x08001fffffffffff 或大于 0x08ff3b6db6db6db6 的 BIGINT 值,则该函数返回 H3_INVALID_CELL_ID

示例

-- 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