Cube Store 1.7: HAVING on decimal sum + ORDER BY measure fails with Arrow Decimal128 comparison error (top-k full_merge default)
Describe the bug
Since v1.7.x, Cube Store fails with an Arrow error when a query filters on a decimal sum measure (HAVING) and orders by a measure, and the query is served from an external pre-aggregation:
Error: Internal: Arrow error: Invalid argument error: Invalid comparison operation: Decimal128(38, 5) > Decimal128(28, 5)The same query works on v1.6.69. It also works on v1.7.46 when the order is by a dimension (no top-k path), and when Cube Store runs with CUBESTORE_TOPK_STRATEGY=streaming.
Likely cause
#11600 (commit 33dc677fb, "turn on the performance toggles by default") changed the default top-k merge strategy from Streaming to FullMerge. In rust/cubestore/cubestore/src/queryplanner/topk/plan.rs (v1.7.46, around L846-848) the full-merge path compiles the HAVING predicate against the pre-merge schema and applies it to the re-aggregated output:
let having = planner.create_physical_expr(predicate, &lower_node.schema, ctx)?;
Arc::new(FilterExec::try_new(having, reagg)?)After re-aggregation the decimal sum is widened (here to Decimal128(38, 5)), while the literal was coerced for the pre-merge type (Decimal128(28, 5)), so the comparison fails. Compiling the predicate against reagg.schema() looks like the fix.
To Reproduce
Schema below (no tables; SQL Server data source, the SQL is only a synthetic row generator). Build the daily pre-aggregation, then query:
{
"measures": ["Repro.amount"],
"dimensions": ["Repro.store"],
"timeDimensions": [{"dimension": "Repro.day", "dateRange": ["2026-01-01", "2026-03-01"]}],
"filters": [{"member": "Repro.amount", "operator": "gt", "values": ["100"]}],
"order": {"Repro.amount": "desc"}
}| Setup | Result |
|---|---|
| Cube 1.6.69 + Cube Store 1.6.69 | 200 |
| Cube 1.7.46 + Cube Store 1.7.46 (defaults) | 400, error above |
same, "order": {"Repro.store": "asc"} |
200 |
Cube Store 1.7.46 with CUBESTORE_TOPK_STRATEGY=streaming |
200, rows identical to 1.6.69 |
Integer measures (count) are not affected; gt, lt and equals all fail on the decimal measure. On our production-like model, /v1/sql shows the same Cube Store SQL shape in both versions (... GROUP BY 1 HAVING (sum(<measure>) > ?) ORDER BY 2 DESC LIMIT 10000, param '500'), so the difference is inside Cube Store.
Minimally reproducible Cube Schema
cubes:
- name: Repro
sql: >
SELECT DATEADD(day, a.d + 10 * b.d, CAST('2026-01-01' AS date)) AS day,
s.store AS store,
CAST(100.25 * (a.d + 10 * b.d + 1) + s.k AS DECIMAL(18, 5)) AS amount
FROM (VALUES (0),(1),(2),(3),(4),(5),(6),(7),(8),(9)) AS a(d)
CROSS JOIN (VALUES (0),(1),(2),(3),(4),(5)) AS b(d)
CROSS JOIN (VALUES ('A', 1.5), ('B', 2.5), ('C', 3.5)) AS s(store, k)
dimensions:
- name: day
sql: day
type: time
- name: store
sql: store
type: string
measures:
- name: amount
sql: amount
type: sum
pre_aggregations:
- name: daily
measures: [amount]
dimensions: [store]
time_dimension: day
granularity: day
external: trueVersion: Cube 1.7.46, Cube Store 1.7.46 (single node), data source mssql. Regression vs 1.6.69.
Additional context
Workaround: CUBESTORE_TOPK_STRATEGY=streaming.
Source: cube-js/cube