mirror of
https://github.com/GreptimeTeam/greptimedb.git
synced 2026-11-26 12:44:10 +00:00
On append-mode tables a region reports an exact row count. When it is zero, DataFusion's AggregateStatistics replaces the region-side __min_state/__max_state aggregate with a non-null struct literal, so the remote stream advertises the state column as non-nullable. The MergeScan schema check required equal nullability and failed the query. Accept a remote field that is non-nullable where the expected field is nullable, matching DataFusion's own physical-plan schema invariant. Batches are already rebuilt with the expected schema. Widening is still rejected, and nested field nullability is still compared exactly as part of the data type. Signed-off-by: Dennis Zhuang <killme2008@gmail.com>
127 lines
2.9 KiB
Plaintext
127 lines
2.9 KiB
Plaintext
-- Append-mode regions report exact row counts, so the datanode can answer
|
|
-- count/min/max over a region from statistics. This only happens when every
|
|
-- aggregate in the query can be answered that way.
|
|
CREATE TABLE a1 (ts TIMESTAMP(9) TIME INDEX, k STRING, v BIGINT)
|
|
PARTITION ON COLUMNS (k) (k < 'b', k >= 'b' AND k < 'c', k >= 'c')
|
|
WITH (append_mode = 'true');
|
|
|
|
Affected Rows: 0
|
|
|
|
-- All regions are empty.
|
|
SELECT min(v), max(v) FROM a1;
|
|
|
|
+-----------+-----------+
|
|
| min(a1.v) | max(a1.v) |
|
|
+-----------+-----------+
|
|
| | |
|
|
+-----------+-----------+
|
|
|
|
SELECT count(*), count(v) FROM a1;
|
|
|
|
+----------+-------------+
|
|
| count(*) | count(a1.v) |
|
|
+----------+-------------+
|
|
| 0 | 0 |
|
|
+----------+-------------+
|
|
|
|
INSERT INTO a1 VALUES (1000, 'a', 1), (2000, 'a', 2);
|
|
|
|
Affected Rows: 2
|
|
|
|
-- Two of three regions are empty.
|
|
SELECT min(v) FROM a1;
|
|
|
|
+-----------+
|
|
| min(a1.v) |
|
|
+-----------+
|
|
| 1 |
|
|
+-----------+
|
|
|
|
SELECT max(v) FROM a1;
|
|
|
|
+-----------+
|
|
| max(a1.v) |
|
|
+-----------+
|
|
| 2 |
|
|
+-----------+
|
|
|
|
SELECT min(ts), max(k) FROM a1;
|
|
|
|
+----------------------------+-----------+
|
|
| min(a1.ts) | max(a1.k) |
|
|
+----------------------------+-----------+
|
|
| 1970-01-01T00:00:00.000001 | a |
|
|
+----------------------------+-----------+
|
|
|
|
SELECT count(*), count(v) FROM a1;
|
|
|
|
+----------+-------------+
|
|
| count(*) | count(a1.v) |
|
|
+----------+-------------+
|
|
| 2 | 2 |
|
|
+----------+-------------+
|
|
|
|
SELECT min(v), count(*) FROM a1;
|
|
|
|
+-----------+----------+
|
|
| min(a1.v) | count(*) |
|
|
+-----------+----------+
|
|
| 1 | 2 |
|
|
+-----------+----------+
|
|
|
|
SELECT sum(v), avg(v) FROM a1;
|
|
|
|
+-----------+-----------+
|
|
| sum(a1.v) | avg(a1.v) |
|
|
+-----------+-----------+
|
|
| 3 | 1.5 |
|
|
+-----------+-----------+
|
|
|
|
SELECT k, min(v), max(v), count(*) FROM a1 GROUP BY k ORDER BY k;
|
|
|
|
+---+-----------+-----------+----------+
|
|
| k | min(a1.v) | max(a1.v) | count(*) |
|
|
+---+-----------+-----------+----------+
|
|
| a | 1 | 2 | 2 |
|
|
+---+-----------+-----------+----------+
|
|
|
|
INSERT INTO a1 VALUES (3000, 'b', 3);
|
|
|
|
Affected Rows: 1
|
|
|
|
-- One of three regions is empty.
|
|
SELECT min(v), max(v) FROM a1;
|
|
|
|
+-----------+-----------+
|
|
| min(a1.v) | max(a1.v) |
|
|
+-----------+-----------+
|
|
| 1 | 3 |
|
|
+-----------+-----------+
|
|
|
|
SELECT k, min(v), max(v), count(*) FROM a1 GROUP BY k ORDER BY k;
|
|
|
|
+---+-----------+-----------+----------+
|
|
| k | min(a1.v) | max(a1.v) | count(*) |
|
|
+---+-----------+-----------+----------+
|
|
| a | 1 | 2 | 2 |
|
|
| b | 3 | 3 | 1 |
|
|
+---+-----------+-----------+----------+
|
|
|
|
INSERT INTO a1 VALUES (4000, 'c', 4);
|
|
|
|
Affected Rows: 1
|
|
|
|
-- No region is empty.
|
|
SELECT min(v), max(v), count(*) FROM a1;
|
|
|
|
+-----------+-----------+----------+
|
|
| min(a1.v) | max(a1.v) | count(*) |
|
|
+-----------+-----------+----------+
|
|
| 1 | 4 | 4 |
|
|
+-----------+-----------+----------+
|
|
|
|
DROP TABLE a1;
|
|
|
|
Affected Rows: 0
|
|
|