Files
greptimedb/tests/cases/standalone/common/function/geo.result
T
2b05da4c06 fix: backport suggested independent fixes to release/5e02efa9 (#9795)
* fix(servers): resolve port from IPv6 bind addresses (#9142)

Signed-off-by: immanuwell <pchpr.00@list.ru>
(cherry picked from commit 5ec679fed9)
Signed-off-by: Lei, HUANG <ratuthomm@gmail.com>

* fix: register region migration procedures before returning IDs (#9163)

Signed-off-by: jeremyhi <fengjiachun@gmail.com>
(cherry picked from commit c65e8d0962)
Signed-off-by: Lei, HUANG <ratuthomm@gmail.com>

* fix(promql): skip empty batches in SeriesDivide stream (#9178)

Signed-off-by: discord9 <55937128+discord9@users.noreply.github.com>
(cherry picked from commit 5e57b00a95)
Signed-off-by: Lei, HUANG <ratuthomm@gmail.com>

* fix(servers): merge duplicate timeseries across RecordBatches in Prometheus remote read (#9032)

* fix(servers): merge timeseries across RecordBatches in Prometheus remote read

Signed-off-by: Tyagiquamar <mohdquamartyagi@gmail.com>

* fix(servers): exercise recordbatches_to_timeseries and sort samples with sort_unstable_by_key

---------

Signed-off-by: Tyagiquamar <mohdquamartyagi@gmail.com>
Co-authored-by: dennis zhuang <killme2008@gmail.com>
(cherry picked from commit 59eb63c663)
Signed-off-by: Lei, HUANG <ratuthomm@gmail.com>

* fix(prometheus): honor label matchers in __name__ values query (#9134)

* fix(prometheus): honor label matchers in __name__ values query

`/api/v1/label/__name__/values?match[]={pod="abc"}` dropped every matcher
other than `__name__` and returned all metrics in the schema. No error,
just the wrong list. Grafana's metrics browser sends this request, so
picking a label value there did nothing.

Selectors that only constrain `__name__` keep answering from table
metadata. A selector constraining an ordinary label now goes to the data:
scan each metric engine physical table for distinct `__table_id` in the
time range, map the ids back to metric names, then apply the selector's
own `__name__` matchers.

Only metric engine tables are covered; other engines share no column space
to scan.

Signed-off-by: Dennis Zhuang <killme2008@gmail.com>

* refactor(prometheus): batch-resolve metric names by table id

Building a full table-id-to-name map meant walking every table in the
schema and holding all of them in memory, just to name the handful the
scan returned. Use `tables_by_ids` instead — one batch KV read over the
ids the scan actually produced.

The catalog walk stays, but only to find the physical tables to scan.

Signed-off-by: Dennis Zhuang <killme2008@gmail.com>

* fix(promql): read an absent label as the empty string

A matcher on a label the series does not carry only worked when the table
had no column for it at all. Where the column exists but is NULL on that
row -- the norm for logical metrics sharing a metric engine physical
table, which holds the union of their label columns -- three-valued logic
dropped the row, so `host!="host1"` and `host=""` missed every metric
without a host label.

Coalesce nullable string label columns to "" for matchers that accept the
empty string, rather than only for the OTLP temporality marker. Equality
matchers are untouched; they cannot match NULL either way.

This is the Prometheus compatibility fix #8970 deliberately kept out of
its own scope. The cost is visible in the regex sqlness plan: the
predicate becomes a CASE, so the scan loses its LastRow selector and
grows a FilterExec. Only negative and empty-accepting matchers pay it.

Signed-off-by: Dennis Zhuang <killme2008@gmail.com>

* fix(promql): don't panic on pre-epoch label value bounds

`rewrite_label_values_query` unwrapped `duration_since(UNIX_EPOCH)`, which
returns an error for an instant before the epoch. `start=1969-12-31T23:59:59Z`
parses as valid RFC3339, so the request panicked instead of answering.

Recover the sign from the error branch, and report a value beyond i64
milliseconds as an error rather than wrapping the cast.

Signed-off-by: Dennis Zhuang <killme2008@gmail.com>

* refactor(prometheus): drop applicable_matchers, share the distinct scan

With the planner reading an absent label as empty, the frontend no longer
needs to pre-filter matchers per physical table. Removing that exposed a
second problem: a physical table that never took a column from a logical
table exposes no `__table_id`, and projecting it failed the whole request.
Skip those tables; the only thing that can miss is a metric with no labels.

Also pulls out the plan-build-execute-collect sequence the two label value
scans had in common.

Signed-off-by: Dennis Zhuang <killme2008@gmail.com>

---------

Signed-off-by: Dennis Zhuang <killme2008@gmail.com>
(cherry picked from commit 007836ba7a)
Signed-off-by: Lei, HUANG <ratuthomm@gmail.com>

* fix(mito2): cancel cache construction for incomplete scans (#9254)

* fix(mito2): cancel cache construction for incomplete scans

CacheBatchBuffer spawned the background concat task and dropped its join
handle. A scan that was cancelled or failed therefore left the task alive:
it kept compacting already queued batches, and while waiting for a range
result memory permit it held them, even though without a finish command
the result can never be put into the cache.

Keep the handle and abort it when the buffer is dropped. The handle is
cleared once the task owns the finish command, so a completed scan still
populates the cache after its stream is dropped. Abort does not preempt a
concat that is already running; it takes effect the next time the task is
polled.

Signed-off-by: Dennis Zhuang <killme2008@gmail.com>

* test(mito2): wait for the permit park before cancelling the buffer

An empty buffered_batches only proves the batches were enqueued, so the
cancellation test could abort a concat task that had never been polled.
Count acquisitions that find too few permits, a test-only signal, and drop
the buffer once the task has reached that wait. Nothing awaits between the
check and the parking, so an observed increment means the caller is about
to wait for permits the test holds for the rest of the case.

Signed-off-by: Dennis Zhuang <killme2008@gmail.com>

---------

Signed-off-by: Dennis Zhuang <killme2008@gmail.com>
(cherry picked from commit 43ce07fa69)
Signed-off-by: Lei, HUANG <ratuthomm@gmail.com>

* fix: merge every state row in geo_path and json_encode_path (#9339)

Signed-off-by: Dennis Zhuang <killme2008@gmail.com>
(cherry picked from commit cc1be82858)
Signed-off-by: Lei, HUANG <ratuthomm@gmail.com>

* fix: align ordered aggregate state type with the accumulator output (#9340)

* fix: align ordered aggregate state type with the accumulator output

Signed-off-by: Dennis Zhuang <killme2008@gmail.com>

* fix: reject mismatched aggregate states and keep hard-ordered aggregates unsplit

Signed-off-by: Dennis Zhuang <killme2008@gmail.com>

* fix: keep WITHIN GROUP aggregates splittable and relabel state fields by position

Signed-off-by: Dennis Zhuang <killme2008@gmail.com>

---------

Signed-off-by: Dennis Zhuang <killme2008@gmail.com>
(cherry picked from commit affc0a1b1d)
Signed-off-by: Lei, HUANG <ratuthomm@gmail.com>

* fix(mito2): stop parallel flat scan tasks once the receiver is dropped (#9368)

* fix(mito2): stop parallel flat scan tasks once the receiver is dropped

spawn_flat_scan_task ignored send errors, so after a query was cancelled the
detached task kept reading its source to EOF. Break out of the loop when the
receiver is gone.

Signed-off-by: Dennis Zhuang <killme2008@gmail.com>

* chore(mito2): log when a parallel scan task stops on a dropped receiver

Signed-off-by: Dennis Zhuang <killme2008@gmail.com>

* chore(mito2): include the send error in the parallel scan stop log

Signed-off-by: Dennis Zhuang <killme2008@gmail.com>

---------

Signed-off-by: Dennis Zhuang <killme2008@gmail.com>
(cherry picked from commit 411c0f173e)
Signed-off-by: Lei, HUANG <ratuthomm@gmail.com>

* fix(catalog): skip backend batch_get on full cache hits (#9431)

fix(catalog): return cached batch values without an empty backend call

Count backend batch_get invocations in regression tests and cover empty input.

Signed-off-by: WenyXu <wenymedia@gmail.com>
(cherry picked from commit acebd6b35b)
Signed-off-by: Lei, HUANG <ratuthomm@gmail.com>

* fix: coalesce equal histogram quantile bucket boundaries (#9451)

* fix: coalesce equal histogram quantile bucket boundaries

Merge numerically equivalent bucket boundaries before monotonicity repair, preserving the allocation-free path for unique boundaries. Share coalescing with histogram_fraction and cover duplicate boundaries with unit and SQL regressions.

Fixes #9443

Signed-off-by: evenyag <realevenyag@gmail.com>

* fix: keep duplicate infinity buckets in one histogram group

Confirm classic histogram completion at a series/timestamp boundary or EOF instead of the first positive infinity. Retain lookahead across batches and reject incomplete optimistic groups so equivalent infinity labels reach numeric coalescing together.

Add stream and SQL regressions for duplicate infinity labels, including established bucket counts and EOF. Correct older fixtures to use distinct keys for distinct histogram groups.

Signed-off-by: evenyag <realevenyag@gmail.com>

* fix: avoid buffering histogram groups with invalid trailing bounds

Discover candidate bucket counts at the first group boundary and let optimistic validation fall back to safe mode for malformed bounds. Document discovery and cover trailing invalid and null labels with a focused streaming regression.

Signed-off-by: evenyag <realevenyag@gmail.com>

---------

Signed-off-by: evenyag <realevenyag@gmail.com>
(cherry picked from commit 97913b4b3a)
Signed-off-by: Lei, HUANG <ratuthomm@gmail.com>

* fix(otlp): coerce empty and "-" trace attribute strings to null (#9461)

* fix(otlp): coerce empty and "-" trace attribute strings to null

Instrumentations fill numeric attributes from absent headers with an empty
string (PSR-7 getHeaderLine returns ""). Coercing that into an existing
numeric column failed and rejected the whole span.

Signed-off-by: Dennis Zhuang <killme2008@gmail.com>

* test: trim redundant row from empty-string rewrite test

Signed-off-by: Dennis Zhuang <killme2008@gmail.com>

---------

Signed-off-by: Dennis Zhuang <killme2008@gmail.com>
(cherry picked from commit d640ab8bc5)
Signed-off-by: Lei, HUANG <ratuthomm@gmail.com>

* fix(metasrv): retry failed heartbeat address updates (#9437)

* fix(metasrv): retry failed heartbeat address updates

Signed-off-by: WenyXu <wenymedia@gmail.com>

* refactor(metasrv): move shared heartbeat helpers to utils

Signed-off-by: WenyXu <wenymedia@gmail.com>

---------

Signed-off-by: WenyXu <wenymedia@gmail.com>
(cherry picked from commit 65b9a35692)
Signed-off-by: Lei, HUANG <ratuthomm@gmail.com>

* fix: align TWCS assignment with half-open time windows (#9464)

Signed-off-by: Lei, HUANG <ratuthomm@gmail.com>
(cherry picked from commit 5126623e63)
Signed-off-by: Lei, HUANG <ratuthomm@gmail.com>

* fix(promql): keep vector labels when a computed scalar is on the right (#9478)

* fix(promql): keep vector labels when a computed scalar is on the right

`metric + time()` or `metric * scalar(other)` planned the join with the
scalar side's context, which has no tags, so every series collapsed into
one unlabeled series. Use the vector side's context when the right operand
is scalar-typed.

Signed-off-by: Dennis Zhuang <killme2008@gmail.com>

* test(promql): update results for labels kept with a computed scalar on the right

v * pi() and v + time() now keep the vector's labels and time index name,
as in Prometheus.

Signed-off-by: Dennis Zhuang <killme2008@gmail.com>

* fix(promql): qualify columns of an unnamed operand in vector joins

A comparison filter's projection has no table name, so after the join its
time index resolved unqualified and was ambiguous when the other operand had
the same column. Also keep the empty-metric branch unchanged for scalar
left operands.

Signed-off-by: Dennis Zhuang <killme2008@gmail.com>

* test(promql): cover comparison filters joined with a scalar

Signed-off-by: Dennis Zhuang <killme2008@gmail.com>

---------

Signed-off-by: Dennis Zhuang <killme2008@gmail.com>
(cherry picked from commit 6da5352c53)
Signed-off-by: Lei, HUANG <ratuthomm@gmail.com>

* fix(promql): keep metric name for comparison operators (#9332)

* fix(promql): keep metric name for comparison operators

`collect_metric_names` dropped the response `__name__` for every binary
operator except `and` / `or` / `unless`, so comparisons such as
`node_load1 > 5` came back without the metric name. Grafana rendered them
as `{instance="..."}` and alert templates reading `$labels.__name__` got
nothing.

Follow Prometheus' `shouldDropMetricName` / `resultMetric`: arithmetic
operators drop the name, comparisons keep the left-hand name, except when
the comparison returns a bool or is a one-to-one `on(...)` match. A
`group_left` / `group_right` modifier does not reduce the labels, so the
name is kept there.

Both the HTTP PromQL API and the gRPC gateway share
`retrieve_metric_name_and_result_type`, so one fix covers both.

Signed-off-by: Aumnertic <hznuzc@gmail.com>

* docs: document binary_keeps_metric_name

Signed-off-by: Aumnertic <hznuzc@gmail.com>

* fix(promql): handle on(__name__), scalar lhs and group_right

Signed-off-by: Aumnertic <hznuzc@gmail.com>

* chore(promql): correct result-side docs and drop unreachable String arm

Signed-off-by: Aumnertic <hznuzc@gmail.com>

* fix(promql): drop metric name when explicitly ignored

Handle ignoring(__name__) for one-to-one comparisons and cover
comparison, group_left, group_right and unless behavior.

Signed-off-by: Aumnertic <hznuzc@gmail.com>

---------

Signed-off-by: Aumnertic <hznuzc@gmail.com>
(cherry picked from commit c33a6cfa56)
Signed-off-by: Lei, HUANG <ratuthomm@gmail.com>

* fix(query): keep filter fetch when rewriting matches term (#9521)

* test: cover matches term limit dropped by constant rewrite

Signed-off-by: discord9 <55937128+discord9@users.noreply.github.com>

* fix(query): keep filter fetch when rewriting matches term

Signed-off-by: discord9 <55937128+discord9@users.noreply.github.com>

---------

Signed-off-by: discord9 <55937128+discord9@users.noreply.github.com>
(cherry picked from commit 483d1e49a3)
Signed-off-by: Lei, HUANG <ratuthomm@gmail.com>

* style: format #9437 test imports for the release toolchain

Signed-off-by: Lei, HUANG <ratuthomm@gmail.com>

* test: regenerate array_agg result for release plan rendering

Signed-off-by: Lei, HUANG <ratuthomm@gmail.com>

---------

Signed-off-by: immanuwell <pchpr.00@list.ru>
Signed-off-by: Lei, HUANG <ratuthomm@gmail.com>
Signed-off-by: jeremyhi <fengjiachun@gmail.com>
Signed-off-by: discord9 <55937128+discord9@users.noreply.github.com>
Signed-off-by: Tyagiquamar <mohdquamartyagi@gmail.com>
Signed-off-by: Dennis Zhuang <killme2008@gmail.com>
Signed-off-by: WenyXu <wenymedia@gmail.com>
Signed-off-by: evenyag <realevenyag@gmail.com>
Signed-off-by: Aumnertic <hznuzc@gmail.com>
Co-authored-by: Immanuel Tikhonov <122638311+immanuwell@users.noreply.github.com>
Co-authored-by: jeremyhi <jiachun_feng@proton.me>
Co-authored-by: discord9 <discord9@163.com>
Co-authored-by: Mohd Quamar Tyagi <104281681+Tyagiquamar@users.noreply.github.com>
Co-authored-by: dennis zhuang <killme2008@gmail.com>
Co-authored-by: Weny Xu <wenymedia@gmail.com>
Co-authored-by: Yingwen <realevenyag@gmail.com>
Co-authored-by: Aum <hznuzc@gmail.com>
2026-10-20 09:46:46 -07:00

484 lines
44 KiB
Plaintext

SELECT h3_latlng_to_cell(37.76938, -122.3889, 0), h3_latlng_to_cell_string(37.76938, -122.3889, 0);;
+------------------------------------------------------------------+-------------------------------------------------------------------------+
| h3_latlng_to_cell(Float64(37.76938),Float64(-122.3889),Int64(0)) | h3_latlng_to_cell_string(Float64(37.76938),Float64(-122.3889),Int64(0)) |
+------------------------------------------------------------------+-------------------------------------------------------------------------+
| 577199624117288959 | 8029fffffffffff |
+------------------------------------------------------------------+-------------------------------------------------------------------------+
SELECT h3_latlng_to_cell(37.76938, -122.3889, 1), h3_latlng_to_cell_string(37.76938, -122.3889, 1);
+------------------------------------------------------------------+-------------------------------------------------------------------------+
| h3_latlng_to_cell(Float64(37.76938),Float64(-122.3889),Int64(1)) | h3_latlng_to_cell_string(Float64(37.76938),Float64(-122.3889),Int64(1)) |
+------------------------------------------------------------------+-------------------------------------------------------------------------+
| 581672437419081727 | 81283ffffffffff |
+------------------------------------------------------------------+-------------------------------------------------------------------------+
SELECT h3_latlng_to_cell(37.76938, -122.3889, 8), h3_latlng_to_cell_string(37.76938, -122.3889, 8);
+------------------------------------------------------------------+-------------------------------------------------------------------------+
| h3_latlng_to_cell(Float64(37.76938),Float64(-122.3889),Int64(8)) | h3_latlng_to_cell_string(Float64(37.76938),Float64(-122.3889),Int64(8)) |
+------------------------------------------------------------------+-------------------------------------------------------------------------+
| 613196570438926335 | 88283082e7fffff |
+------------------------------------------------------------------+-------------------------------------------------------------------------+
SELECT h3_latlng_to_cell(37.76938, -122.3889, 100), h3_latlng_to_cell_string(37.76938, -122.3889, 100);
Error: 3001(EngineExecuteQuery), Execution error: H3 error: invalid resolution (got Some(100)): out of range
SELECT h3_latlng_to_cell(37.76938, -122.3889, -1), h3_latlng_to_cell_string(37.76938, -122.3889, -1);
Error: 3001(EngineExecuteQuery), Cast error: Can't cast value -1 to type UInt8
SELECT h3_latlng_to_cell(37.76938, -122.3889, 8::Int8), h3_latlng_to_cell_string(37.76938, -122.3889, 8::Int8);
+--------------------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------+
| h3_latlng_to_cell(Float64(37.76938),Float64(-122.3889),arrow_cast(Int64(8),Utf8("Int64"))) | h3_latlng_to_cell_string(Float64(37.76938),Float64(-122.3889),arrow_cast(Int64(8),Utf8("Int64"))) |
+--------------------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------+
| 613196570438926335 | 88283082e7fffff |
+--------------------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------+
SELECT h3_latlng_to_cell(37.76938, -122.3889, 8::Int16), h3_latlng_to_cell_string(37.76938, -122.3889, 8::Int16);
+--------------------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------+
| h3_latlng_to_cell(Float64(37.76938),Float64(-122.3889),arrow_cast(Int64(8),Utf8("Int16"))) | h3_latlng_to_cell_string(Float64(37.76938),Float64(-122.3889),arrow_cast(Int64(8),Utf8("Int16"))) |
+--------------------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------+
| 613196570438926335 | 88283082e7fffff |
+--------------------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------+
SELECT h3_latlng_to_cell(37.76938, -122.3889, 8::Int32), h3_latlng_to_cell_string(37.76938, -122.3889, 8::Int32);
+--------------------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------+
| h3_latlng_to_cell(Float64(37.76938),Float64(-122.3889),arrow_cast(Int64(8),Utf8("Int32"))) | h3_latlng_to_cell_string(Float64(37.76938),Float64(-122.3889),arrow_cast(Int64(8),Utf8("Int32"))) |
+--------------------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------+
| 613196570438926335 | 88283082e7fffff |
+--------------------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------+
SELECT h3_latlng_to_cell(37.76938, -122.3889, 8::Int64), h3_latlng_to_cell_string(37.76938, -122.3889, 8::Int64);
+--------------------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------+
| h3_latlng_to_cell(Float64(37.76938),Float64(-122.3889),arrow_cast(Int64(8),Utf8("Int64"))) | h3_latlng_to_cell_string(Float64(37.76938),Float64(-122.3889),arrow_cast(Int64(8),Utf8("Int64"))) |
+--------------------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------+
| 613196570438926335 | 88283082e7fffff |
+--------------------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------+
SELECT h3_latlng_to_cell(37.76938, -122.3889, 8::UInt8), h3_latlng_to_cell_string(37.76938, -122.3889, 8::UInt8);
+--------------------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------+
| h3_latlng_to_cell(Float64(37.76938),Float64(-122.3889),arrow_cast(Int64(8),Utf8("UInt8"))) | h3_latlng_to_cell_string(Float64(37.76938),Float64(-122.3889),arrow_cast(Int64(8),Utf8("UInt8"))) |
+--------------------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------+
| 613196570438926335 | 88283082e7fffff |
+--------------------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------+
SELECT h3_latlng_to_cell(37.76938, -122.3889, 8::UInt16), h3_latlng_to_cell_string(37.76938, -122.3889, 8::UInt8);
+---------------------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------+
| h3_latlng_to_cell(Float64(37.76938),Float64(-122.3889),arrow_cast(Int64(8),Utf8("UInt16"))) | h3_latlng_to_cell_string(Float64(37.76938),Float64(-122.3889),arrow_cast(Int64(8),Utf8("UInt8"))) |
+---------------------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------+
| 613196570438926335 | 88283082e7fffff |
+---------------------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------+
SELECT h3_latlng_to_cell(37.76938, -122.3889, 8::UInt32), h3_latlng_to_cell_string(37.76938, -122.3889, 8::UInt32);
+---------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------+
| h3_latlng_to_cell(Float64(37.76938),Float64(-122.3889),arrow_cast(Int64(8),Utf8("UInt32"))) | h3_latlng_to_cell_string(Float64(37.76938),Float64(-122.3889),arrow_cast(Int64(8),Utf8("UInt32"))) |
+---------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------+
| 613196570438926335 | 88283082e7fffff |
+---------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------+
SELECT h3_latlng_to_cell(37.76938, -122.3889, 8::UInt64), h3_latlng_to_cell_string(37.76938, -122.3889, 8::UInt64);
+---------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------+
| h3_latlng_to_cell(Float64(37.76938),Float64(-122.3889),arrow_cast(Int64(8),Utf8("UInt64"))) | h3_latlng_to_cell_string(Float64(37.76938),Float64(-122.3889),arrow_cast(Int64(8),Utf8("UInt64"))) |
+---------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------+
| 613196570438926335 | 88283082e7fffff |
+---------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------+
SELECT h3_cell_to_string(h3_latlng_to_cell(37.76938, -122.3889, 8::UInt64)) AS cell_str, h3_string_to_cell(h3_latlng_to_cell_string(37.76938, -122.3889, 8::UInt64)) AS cell_index;
+-----------------+--------------------+
| cell_str | cell_index |
+-----------------+--------------------+
| 88283082e7fffff | 613196570438926335 |
+-----------------+--------------------+
SELECT h3_cell_center_latlng(h3_latlng_to_cell(37.76938, -122.3889, 8::UInt64)) AS cell_center;
+------------------------------------------+
| cell_center |
+------------------------------------------+
| [37.77246152245501, -122.39010997087324] |
+------------------------------------------+
SELECT
h3_cell_resolution(cell) AS resolution,
h3_cell_base(cell) AS base,
h3_cell_is_pentagon(cell) AS pentagon,
h3_cell_parent(cell, 6::UInt64) AS parent,
h3_cell_to_children(cell, 10::UInt64) AS children,
h3_cell_to_children_size(cell, 10) AS children_count,
h3_cell_to_child_pos(cell, 6) AS child_pos,
h3_child_pos_to_cell(25, cell, 11) AS child
FROM (SELECT h3_latlng_to_cell(37.76938, -122.3889, 8::UInt64) AS cell);
+------------+------+----------+--------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------+-----------+--------------------+
| resolution | base | pentagon | parent | children | children_count | child_pos | child |
+------------+------+----------+--------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------+-----------+--------------------+
| 8 | 20 | false | 604189371209351167 | [622203769691602943, 622203769691635711, 622203769691668479, 622203769691701247, 622203769691734015, 622203769691766783, 622203769691799551, 622203769691865087, 622203769691897855, 622203769691930623, 622203769691963391, 622203769691996159, 622203769692028927, 622203769692061695, 622203769692127231, 622203769692159999, 622203769692192767, 622203769692225535, 622203769692258303, 622203769692291071, 622203769692323839, 622203769692389375, 622203769692422143, 622203769692454911, 622203769692487679, 622203769692520447, 622203769692553215, 622203769692585983, 622203769692651519, 622203769692684287, 622203769692717055, 622203769692749823, 622203769692782591, 622203769692815359, 622203769692848127, 622203769692913663, 622203769692946431, 622203769692979199, 622203769693011967, 622203769693044735, 622203769693077503, 622203769693110271, 622203769693175807, 622203769693208575, 622203769693241343, 622203769693274111, 622203769693306879, 622203769693339647, 622203769693372415] | 49 | 45 | 626707369319059455 |
+------------+------+----------+--------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------+-----------+--------------------+
SELECT
h3_grid_disk(cell, 0) AS current_cell,
h3_grid_disk(cell, 3) AS grids,
h3_grid_disk_distances(cell, 3) AS all_grids,
FROM (SELECT h3_latlng_to_cell(37.76938, -122.3889, 8::UInt64) AS cell);
+----------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| current_cell | grids | all_grids |
+----------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| [613196570438926335] | [613196570438926335, 613196570436829183, 613196569755254783, 613196570378108927, 613196570373914623, 613196570434732031, 613196570432634879, 613196570445217791, 613196570250182655, 613196569753157631, 613196569744769023, 613196569746866175, 613196570369720319, 613196570365526015, 613196570376011775, 613196570336165887, 613196570344554495, 613196570443120639, 613196570441023487, 613196570220822527, 613196570258571263, 613196570248085503, 613196570254376959, 613196569757351935, 613196569748963327, 613196569751060479, 613196569686048767, 613196569688145919, 613196570371817471, 613196570367623167, 613196570394886143, 613196570338263039, 613196570331971583, 613196570340360191, 613196570405371903, 613196570403274751, 613196570216628223] | [613196570438926335, 613196570436829183, 613196569755254783, 613196570378108927, 613196570373914623, 613196570434732031, 613196570432634879, 613196570445217791, 613196570250182655, 613196569753157631, 613196569744769023, 613196569746866175, 613196570369720319, 613196570365526015, 613196570376011775, 613196570336165887, 613196570344554495, 613196570443120639, 613196570441023487, 613196570220822527, 613196570258571263, 613196570248085503, 613196570254376959, 613196569757351935, 613196569748963327, 613196569751060479, 613196569686048767, 613196569688145919, 613196570371817471, 613196570367623167, 613196570394886143, 613196570338263039, 613196570331971583, 613196570340360191, 613196570405371903, 613196570403274751, 613196570216628223] |
+----------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
SELECT
h3_grid_distance(cell1, cell2) AS distance,
h3_grid_path_cells(cell1, cell2) AS path_cells,
round(h3_distance_sphere_km(cell1, cell2), 5) AS sphere_distance,
round(h3_distance_degree(cell1, cell2), 14) AS euclidean_distance,
FROM
(
SELECT
h3_string_to_cell('86283082fffffff') AS cell1,
h3_string_to_cell('86283470fffffff') AS cell2
);
+----------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+-----------------+--------------------+
| distance | path_cells | sphere_distance | euclidean_distance |
+----------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+-----------------+--------------------+
| 9 | [604189371209351167, 604189371075133439, 604189375235883007, 604189375101665279, 604189638034194431, 604189638571065343, 604189638436847615, 604189642597597183, 604189642463379455, 604189641255419903] | 55.05017 | 0.54939243697098 |
+----------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+-----------------+--------------------+
SELECT
unnest(h3_grid_path_cells(cell1, cell2)) AS path_cells,
FROM
(
SELECT
h3_string_to_cell('86283082fffffff') AS cell1,
h3_string_to_cell('86283470fffffff') AS cell2
);
+--------------------+
| path_cells |
+--------------------+
| 604189371209351167 |
| 604189371075133439 |
| 604189375235883007 |
| 604189375101665279 |
| 604189638034194431 |
| 604189638571065343 |
| 604189638436847615 |
| 604189642597597183 |
| 604189642463379455 |
| 604189641255419903 |
+--------------------+
SELECT
h3_cells_contains('86283470fffffff,862834777ffffff, 862834757ffffff, 86283471fffffff, 862834707ffffff', '8b283470d112fff') AS R00,
h3_cells_contains('86283470fffffff,862834777ffffff, 862834757ffffff, 86283471fffffff, 862834707ffffff', 604189641792290815) AS R01,
h3_cells_contains('86283470fffffff,862834777ffffff, 862834757ffffff, 86283471fffffff, 862834707ffffff', 626707639343067135) AS R02;
+------+-------+------+
| r00 | r01 | r02 |
+------+-------+------+
| true | false | true |
+------+-------+------+
SELECT
h3_cells_contains(['86283470fffffff', '862834777ffffff', '862834757ffffff', '86283471fffffff', '862834707ffffff'], '86283472fffffff') AS R10,
h3_cells_contains(['86283470fffffff', '862834777ffffff', '862834757ffffff', '86283471fffffff', '862834707ffffff'], '8b283470d112fff') AS R11,
h3_cells_contains(['86283470fffffff', '862834777ffffff', '862834757ffffff', '86283471fffffff', '862834707ffffff'], 626707639343067135) AS R12;
+-------+------+------+
| r10 | r11 | r12 |
+-------+------+------+
| false | true | true |
+-------+------+------+
SELECT
h3_cells_contains([604189641255419903, 604189643000250367, 604189642463379455, 604189641523855359, 604189641121202175], '8b283470d112fff') AS R20,
h3_cells_contains([604189641255419903, 604189643000250367, 604189642463379455, 604189641523855359, 604189641121202175], 604189641792290815) AS R21,
h3_cells_contains([604189641255419903, 604189643000250367, 604189642463379455, 604189641523855359, 604189641121202175], 626707639343067135) AS R22;
+------+-------+------+
| r20 | r21 | r22 |
+------+-------+------+
| true | false | true |
+------+-------+------+
SELECT geohash(37.76938, -122.3889, 9);
+--------------------------------------------------------+
| geohash(Float64(37.76938),Float64(-122.3889),Int64(9)) |
+--------------------------------------------------------+
| 9q8yygxne |
+--------------------------------------------------------+
SELECT geohash(37.76938, -122.3889, 10);
+---------------------------------------------------------+
| geohash(Float64(37.76938),Float64(-122.3889),Int64(10)) |
+---------------------------------------------------------+
| 9q8yygxnef |
+---------------------------------------------------------+
SELECT geohash(37.76938, -122.3889, 11);
+---------------------------------------------------------+
| geohash(Float64(37.76938),Float64(-122.3889),Int64(11)) |
+---------------------------------------------------------+
| 9q8yygxneft |
+---------------------------------------------------------+
SELECT geohash(37.76938, -122.3889, 100);
Error: 3001(EngineExecuteQuery), Execution error: Invalid geohash resolution 100, valid value range: [1, 12]
SELECT geohash(37.76938, -122.3889, -1);
Error: 3001(EngineExecuteQuery), Cast error: Can't cast value -1 to type UInt8
SELECT geohash(37.76938, -122.3889, 11::Int8);
+-----------------------------------------------------------------------------------+
| geohash(Float64(37.76938),Float64(-122.3889),arrow_cast(Int64(11),Utf8("Int64"))) |
+-----------------------------------------------------------------------------------+
| 9q8yygxneft |
+-----------------------------------------------------------------------------------+
SELECT geohash(37.76938, -122.3889, 11::Int16);
+-----------------------------------------------------------------------------------+
| geohash(Float64(37.76938),Float64(-122.3889),arrow_cast(Int64(11),Utf8("Int16"))) |
+-----------------------------------------------------------------------------------+
| 9q8yygxneft |
+-----------------------------------------------------------------------------------+
SELECT geohash(37.76938, -122.3889, 11::Int32);
+-----------------------------------------------------------------------------------+
| geohash(Float64(37.76938),Float64(-122.3889),arrow_cast(Int64(11),Utf8("Int32"))) |
+-----------------------------------------------------------------------------------+
| 9q8yygxneft |
+-----------------------------------------------------------------------------------+
SELECT geohash(37.76938, -122.3889, 11::Int64);
+-----------------------------------------------------------------------------------+
| geohash(Float64(37.76938),Float64(-122.3889),arrow_cast(Int64(11),Utf8("Int64"))) |
+-----------------------------------------------------------------------------------+
| 9q8yygxneft |
+-----------------------------------------------------------------------------------+
SELECT geohash(37.76938, -122.3889, 11::UInt8);
+-----------------------------------------------------------------------------------+
| geohash(Float64(37.76938),Float64(-122.3889),arrow_cast(Int64(11),Utf8("UInt8"))) |
+-----------------------------------------------------------------------------------+
| 9q8yygxneft |
+-----------------------------------------------------------------------------------+
SELECT geohash(37.76938, -122.3889, 11::UInt16);
+------------------------------------------------------------------------------------+
| geohash(Float64(37.76938),Float64(-122.3889),arrow_cast(Int64(11),Utf8("UInt16"))) |
+------------------------------------------------------------------------------------+
| 9q8yygxneft |
+------------------------------------------------------------------------------------+
SELECT geohash(37.76938, -122.3889, 11::UInt32);
+------------------------------------------------------------------------------------+
| geohash(Float64(37.76938),Float64(-122.3889),arrow_cast(Int64(11),Utf8("UInt32"))) |
+------------------------------------------------------------------------------------+
| 9q8yygxneft |
+------------------------------------------------------------------------------------+
SELECT geohash(37.76938, -122.3889, 11::UInt64);
+------------------------------------------------------------------------------------+
| geohash(Float64(37.76938),Float64(-122.3889),arrow_cast(Int64(11),Utf8("UInt64"))) |
+------------------------------------------------------------------------------------+
| 9q8yygxneft |
+------------------------------------------------------------------------------------+
SELECT geohash_neighbours(37.76938, -122.3889, 11);
+----------------------------------------------------------------------------------------------------------+
| geohash_neighbours(Float64(37.76938),Float64(-122.3889),Int64(11)) |
+----------------------------------------------------------------------------------------------------------+
| [9q8yygxnefv, 9q8yygxnefu, 9q8yygxnefs, 9q8yygxnefk, 9q8yygxnefm, 9q8yygxnefq, 9q8yygxnefw, 9q8yygxnefy] |
+----------------------------------------------------------------------------------------------------------+
WITH cell_cte AS (
SELECT s2_latlng_to_cell(37.76938, -122.3889) AS cell
)
SELECT cell,
s2_cell_to_token(cell),
s2_cell_level(cell),
s2_cell_parent(cell, 3)
FROM cell_cte;
+---------------------+---------------------------------+------------------------------+----------------------------------------+
| cell | s2_cell_to_token(cell_cte.cell) | s2_cell_level(cell_cte.cell) | s2_cell_parent(cell_cte.cell,Int64(3)) |
+---------------------+---------------------------------+------------------------------+----------------------------------------+
| 9263763445276221387 | 808f7fc59ef01fcb | 30 | 9277415232383221760 |
+---------------------+---------------------------------+------------------------------+----------------------------------------+
SELECT json_encode_path(37.76938, -122.3889, 1728083375::TimestampSecond);
+-----------------------------------------------------------------------------------------------------------+
| json_encode_path(Float64(37.76938),Float64(-122.3889),arrow_cast(Int64(1728083375),Utf8("Timestamp(s)"))) |
+-----------------------------------------------------------------------------------------------------------+
| [[-122.3889,37.76938]] |
+-----------------------------------------------------------------------------------------------------------+
SELECT json_encode_path(lat, lon, ts)
FROM(
SELECT 37.76938 AS lat, -122.3889 AS lon, 1728083375::TimestampSecond AS ts
UNION ALL
SELECT 37.76928 AS lat, -122.3839 AS lon, 1728083373::TimestampSecond AS ts
UNION ALL
SELECT 37.76930 AS lat, -122.3820 AS lon, 1728083379::TimestampSecond AS ts
UNION ALL
SELECT 37.77001 AS lat, -122.3888 AS lon, 1728083372::TimestampSecond AS ts
);
+-------------------------------------------------------------------------------------+
| json_encode_path(lat,lon,ts) |
+-------------------------------------------------------------------------------------+
| [[-122.3888,37.77001],[-122.3839,37.76928],[-122.3889,37.76938],[-122.382,37.7693]] |
+-------------------------------------------------------------------------------------+
SELECT UNNEST(geo_path(37.76938, -122.3889, 1728083375::TimestampSecond));
+-----------------------------------------------------------------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------+
| __unnest_placeholder(geo_path(Float64(37.76938),Float64(-122.3889),arrow_cast(Int64(1728083375),Utf8("Timestamp(s)")))).lat | __unnest_placeholder(geo_path(Float64(37.76938),Float64(-122.3889),arrow_cast(Int64(1728083375),Utf8("Timestamp(s)")))).lng |
+-----------------------------------------------------------------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------+
| [37.76938] | [-122.3889] |
+-----------------------------------------------------------------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------+
SELECT UNNEST(geo_path(lat, lon, ts))
FROM(
SELECT 37.76938 AS lat, -122.3889 AS lon, 1728083375::TimestampSecond AS ts
UNION ALL
SELECT 37.76928 AS lat, -122.3839 AS lon, 1728083373::TimestampSecond AS ts
UNION ALL
SELECT 37.76930 AS lat, -122.3820 AS lon, 1728083379::TimestampSecond AS ts
UNION ALL
SELECT 37.77001 AS lat, -122.3888 AS lon, 1728083372::TimestampSecond AS ts
);
+------------------------------------------------+------------------------------------------------+
| __unnest_placeholder(geo_path(lat,lon,ts)).lat | __unnest_placeholder(geo_path(lat,lon,ts)).lng |
+------------------------------------------------+------------------------------------------------+
| [37.77001, 37.76928, 37.76938, 37.7693] | [-122.3888, -122.3839, -122.3889, -122.382] |
+------------------------------------------------+------------------------------------------------+
SELECT wkt_point_from_latlng(37.76938, -122.3889) AS point;
+---------------------------+
| point |
+---------------------------+
| POINT(-122.3889 37.76938) |
+---------------------------+
SELECT
st_distance(p1, p2) AS euclidean_dist,
st_distance_sphere_m(p1, p2) AS sphere_dist_m,
st_distance(p1, polygon1) AS euclidean_dist_pp,
st_area(p1) as area_point,
st_area(polygon1) as area_polygon,
FROM
(
SELECT
wkt_point_from_latlng(37.76938, -122.3889) AS p1,
wkt_point_from_latlng(38.5216, -121.4247) AS p2,
'POLYGON ((-121.491698 38.653343, -121.582353 38.556757, -121.469721 38.449287, -121.315883 38.541721, -121.491698 38.653343))' AS polygon1,
);
+--------------------+--------------------+--------------------+------------+----------------------+
| euclidean_dist | sphere_dist_m | euclidean_dist_pp | area_point | area_polygon |
+--------------------+--------------------+--------------------+------------+----------------------+
| 1.2229131483470166 | 118766.03647159638 | 1.1271559800391486 | 0.0 | 0.027022178074000106 |
+--------------------+--------------------+--------------------+------------+----------------------+
SELECT st_distance_sphere_m(wkt_point_from_latlng(37.76938, -122.3889), 'POLYGON ((-121.491698 38.653343, -121.582353 38.556757, -121.469721 38.449287, -121.315883 38.541721, -121.491698 38.653343))');
Error: 3001(EngineExecuteQuery), Great circle distance between non-point objects are not supported for now.
SELECT
st_contains(polygon1, p1),
st_contains(polygon2, p1),
st_within(p1, polygon1),
st_within(p1, polygon2),
st_intersects(polygon1, polygon2),
st_intersects(polygon1, polygon3),
FROM
(
SELECT
wkt_point_from_latlng(37.383287, -122.01325) AS p1,
'POLYGON ((-122.031661 37.428252, -122.139829 37.387072, -122.135365 37.361971, -122.057759 37.332222, -121.987707 37.328946, -121.943754 37.333041, -121.919373 37.349145, -121.945814 37.376705, -121.975689 37.417345, -121.998696 37.409164, -122.031661 37.428252))' AS polygon1,
'POLYGON ((-121.491698 38.653343, -121.582353 38.556757, -121.469721 38.449287, -121.315883 38.541721, -121.491698 38.653343))' AS polygon2,
'POLYGON ((-122.089628 37.450332, -122.20535 37.378342, -122.093062 37.36088, -122.044301 37.372886, -122.089628 37.450332))' AS polygon3,
);
+--------------------------+--------------------------+------------------------+------------------------+----------------------------------+----------------------------------+
| st_contains(polygon1,p1) | st_contains(polygon2,p1) | st_within(p1,polygon1) | st_within(p1,polygon2) | st_intersects(polygon1,polygon2) | st_intersects(polygon1,polygon3) |
+--------------------------+--------------------------+------------------------+------------------------+----------------------------------+----------------------------------+
| true | false | true | false | false | true |
+--------------------------+--------------------------+------------------------+------------------------+----------------------------------+----------------------------------+
CREATE TABLE geo_path_partitioned (
ts TIMESTAMP TIME INDEX,
k INT,
lat DOUBLE,
lon DOUBLE,
PRIMARY KEY(k)
)
PARTITION ON COLUMNS (k) (k < 10, k >= 10 AND k < 20, k >= 20);
Affected Rows: 0
INSERT INTO geo_path_partitioned VALUES
(1000, 1, 1, 11),
(2000, 11, 2, 12),
(3000, 21, 3, 13),
(4000, 2, 4, 14),
(5000, 12, 5, 15),
(6000, 22, 6, 16),
(7000, 3, 7, 17);
Affected Rows: 7
SELECT lat > 3 AS g, geo_path(lat, lon, ts) FROM geo_path_partitioned GROUP BY g ORDER BY g;
+-------+-------------------------------------------------------------------------------------+
| g | geo_path(geo_path_partitioned.lat,geo_path_partitioned.lon,geo_path_partitioned.ts) |
+-------+-------------------------------------------------------------------------------------+
| false | {lat: [1.0, 2.0, 3.0], lng: [11.0, 12.0, 13.0]} |
| true | {lat: [4.0, 5.0, 6.0, 7.0], lng: [14.0, 15.0, 16.0, 17.0]} |
+-------+-------------------------------------------------------------------------------------+
SELECT lat > 3 AS g, json_encode_path(lat, lon, ts) FROM geo_path_partitioned GROUP BY g ORDER BY g;
+-------+---------------------------------------------------------------------------------------------+
| g | json_encode_path(geo_path_partitioned.lat,geo_path_partitioned.lon,geo_path_partitioned.ts) |
+-------+---------------------------------------------------------------------------------------------+
| false | [[11.0,1.0],[12.0,2.0],[13.0,3.0]] |
| true | [[14.0,4.0],[15.0,5.0],[16.0,6.0],[17.0,7.0]] |
+-------+---------------------------------------------------------------------------------------------+
DROP TABLE geo_path_partitioned;
Affected Rows: 0