Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ Three compilation paths based on view type (`RefreshType`):
| `SIMPLE_PROJECTION` | `CompileProjectionsFilters()` | Counting-based consolidation (GROUP BY + generate_series/rowid for bag semantics) |
| `WINDOW_PARTITION` | `CompileWindowRecompute()` or DuckLake snapshot diff | Delete/reinsert only affected partitions |
| `GROUP_RECOMPUTE` | `CompileGroupRecompute()` | Delete/reinsert only affected groups; used for inner DISTINCT under aggregate and other non-linear group cases |
| `DISTINCT_INCREMENTAL` | `CompileDistinctIncremental()` | Aux-state path for single-source inner DISTINCT under one SUM when `openivm_distinct_aux_state=true`; falls back to group-recompute if metadata is missing |
| `DISTINCT_INCREMENTAL` | `CompileDistinctIncremental()` | Aux-state path for single-source inner DISTINCT under one SUM when `openivm_distinct_aux_state=true`; refresh throws if aux metadata is missing (no silent fallback) |
| `FULL_REFRESH` | `BuildRecomputeQuery()` | DELETE all rows from `openivm_data_<view>`, INSERT full query, then cleanup deltas |

MIN/MAX and ARG_MIN/ARG_MAX usually force group-recompute unless insert-only fast paths are enabled and safe. AVG is decomposed to SUM+COUNT; STDDEV/VARIANCE are decomposed to SUM, COUNT, and sum-of-squares helper columns.
Expand Down
12 changes: 3 additions & 9 deletions src/upsert/refresh_sql.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1155,7 +1155,7 @@
case RefreshType::COUNT_DISTINCT_INCREMENTAL: {
RefreshMetadata::CountDistinctAuxMeta aux_meta;
if (!metadata.GetCountDistinctAuxMeta(view_name, aux_meta)) {
throw InternalException("COUNT_DISTINCT_INCREMENTAL view '%s' has no aux metadata", view_name);
throw InvalidInputException("COUNT_DISTINCT_INCREMENTAL view '%s' has no aux metadata", view_name);
} else {
if (!active_facts.compile_only) {
EnsureCountDistinctAuxState(metadata, con, view_name, aux_meta, delta_table_names,
Expand Down Expand Up @@ -1207,10 +1207,7 @@
aux_meta.sum_out.c_str());
break;
}
OPENIVM_DEBUG_PRINT("[UPSERT] DISTINCT_INCREMENTAL view has no aux meta — "
"falling through to "
"GROUP_RECOMPUTE\n");
[[fallthrough]];
throw InvalidInputException("DISTINCT_INCREMENTAL view '%s' has no aux metadata", view_name);
}
case RefreshType::SEMI_ANTI_RECOMPUTE: {
RefreshMetadata::SemiAntiAuxMeta aux_meta;
Expand Down Expand Up @@ -1241,10 +1238,7 @@
aux_meta.join_type.c_str(), aux_meta.left_cols.size());
break;
}
OPENIVM_DEBUG_PRINT("[UPSERT] SEMI_ANTI_RECOMPUTE view has no aux meta — "
"falling through to "
"GROUP_RECOMPUTE\n");
[[fallthrough]];
throw InvalidInputException("SEMI_ANTI_RECOMPUTE view '%s' has no aux metadata", view_name);
}
case RefreshType::GROUP_RECOMPUTE: {
auto group_columns = metadata.GetGroupColumns(view_name);
Expand Down Expand Up @@ -1296,7 +1290,7 @@
break;
}
case RefreshType::TOP_K:
[[fallthrough]];

Check warning on line 1293 in src/upsert/refresh_sql.cpp

View workflow job for this annotation

GitHub Actions / Build extension binaries / Windows (windows_amd64, windows-latest, x64-windows-static-release, x64-windows-static-release, t...

attribute [[fallthrough]] requires at least '/std:c++17'; ignored

Check warning on line 1293 in src/upsert/refresh_sql.cpp

View workflow job for this annotation

GitHub Actions / Build extension binaries / Windows (windows_amd64, windows-latest, x64-windows-static-release, x64-windows-static-release, t...

attribute [[fallthrough]] requires at least '/std:c++17'; ignored

Check warning on line 1293 in src/upsert/refresh_sql.cpp

View workflow job for this annotation

GitHub Actions / Build extension binaries / Windows (windows_amd64, windows-latest, x64-windows-static-release, x64-windows-static-release, t...

attribute [[fallthrough]] requires at least '/std:c++17'; ignored

Check warning on line 1293 in src/upsert/refresh_sql.cpp

View workflow job for this annotation

GitHub Actions / Build extension binaries / Windows (windows_amd64, windows-latest, x64-windows-static-release, x64-windows-static-release, t...

attribute [[fallthrough]] requires at least '/std:c++17'; ignored
case RefreshType::FULL_REFRESH: {
string full_recompute_query = view_query_sql;
if (active_facts.target_dialect == SqlDialect::SPARK) {
Expand Down
72 changes: 72 additions & 0 deletions test/sql/missing_aux_meta_refresh_error.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# name: test/sql/missing_aux_meta_refresh_error.test
# description: Refresh of aux-state views with lost aux metadata fails instead of silently falling back to GROUP_RECOMPUTE
# group: [sql]

require openivm

statement ok
CREATE TABLE mam_l (id INT, x INT);

statement ok
CREATE TABLE mam_r (rid INT, y INT);

statement ok
INSERT INTO mam_l VALUES (1, 10), (2, 20), (3, 30);

statement ok
INSERT INTO mam_r VALUES (100, 9);

statement ok
CREATE MATERIALIZED VIEW mam_semi AS
SELECT l.id, l.x FROM mam_l l SEMI JOIN mam_r r ON abs(l.x - r.y) <= 2;

query I
SELECT type FROM openivm_views WHERE type = 9;
----
9

statement ok
UPDATE openivm_views SET semi_anti_aux_meta_json = NULL WHERE type = 9;

statement ok
INSERT INTO mam_r VALUES (101, 21);

statement error
PRAGMA refresh('mam_semi');
----
has no aux metadata

# DISTINCT_INCREMENTAL: same contract.
statement ok
SET openivm_distinct_aux_state = true;

statement ok
CREATE TABLE mam_src (grp INT, machine VARCHAR, cores INT);

statement ok
INSERT INTO mam_src VALUES (1, 'm1', 8), (1, 'm1', 8), (1, 'm2', 16), (2, 'm3', 4);

statement ok
CREATE MATERIALIZED VIEW mam_distinct AS
SELECT grp, SUM(cores) AS total_cores
FROM (SELECT DISTINCT grp, machine, cores FROM mam_src) d
GROUP BY grp;

query I
SELECT type FROM openivm_views WHERE type = 8;
----
8

statement ok
UPDATE openivm_views SET distinct_aux_meta_json = NULL WHERE type = 8;

statement ok
INSERT INTO mam_src VALUES (2, 'm4', 5);

statement error
PRAGMA refresh('mam_distinct');
----
has no aux metadata

statement ok
SET openivm_distinct_aux_state = false;
Loading