From 63adb2afb966ea1b358d6b0c3afafcf781ebfcf8 Mon Sep 17 00:00:00 2001 From: Ruben Fiszel Date: Wed, 2 Dec 2026 12:29:15 +0100 Subject: [PATCH] fix: carry hypertable partitioning functions, leave hierarchical aggregates out Co-Authored-By: Claude Opus 5.5 --- backend/ee-repo-ref.txt | 2 +- .../src/datatable_extensions.rs | 33 ++++++++++++++++--- cli/src/commands/workspace/fork.ts | 6 ++-- 3 files changed, 34 insertions(+), 7 deletions(-) diff --git a/backend/ee-repo-ref.txt b/backend/ee-repo-ref.txt index 2da6853e5e..dc87a76805 100644 --- a/backend/ee-repo-ref.txt +++ b/backend/ee-repo-ref.txt @@ -1 +1 @@ -91f96ba70bbcc44ebea06e04e10a053eeb43af74 +bfb31c16fbb210924ac973cd8cb7939d8406aa1a diff --git a/backend/windmill-api-workspaces/src/datatable_extensions.rs b/backend/windmill-api-workspaces/src/datatable_extensions.rs index dfb86bb7ac..55bd1f2bc1 100644 --- a/backend/windmill-api-workspaces/src/datatable_extensions.rs +++ b/backend/windmill-api-workspaces/src/datatable_extensions.rs @@ -75,6 +75,8 @@ struct Dimension { time_interval: Option, integer_interval: Option, num_partitions: Option, + /// The function the column's values go through before they are partitioned, qualified. + partitioning_func: Option, } impl Hypertable { @@ -277,14 +279,16 @@ async fn read_hypertables( FROM dependent JOIN pg_class c ON c.oid = dependent.oid JOIN pg_namespace n ON n.oid = c.relnamespace - WHERE n.nspname <> $1 ORDER BY 1, 2", - &[&TIMESCALEDB_INTERNAL], + &[], ) .await .map_err(source_err(dbname))?; + // The internal views of an aggregate built on another one are among them, already left out + // with `_timescaledb_internal`. plan.left_out_views = left_out .iter() + .filter(|row| row.get::<_, &str>(0) != TIMESCALEDB_INTERNAL) .map(|row| { format!( "{}.{}", @@ -353,11 +357,18 @@ async fn read_hypertables( let rows = client .query( "SELECT d.hypertable_schema::text, d.hypertable_name::text, d.column_name::text, - d.time_interval::text, d.integer_interval::bigint, d.num_partitions::smallint + d.time_interval::text, d.integer_interval::bigint, d.num_partitions::smallint, + CASE WHEN c.partitioning_func IS NOT NULL + THEN format('%I.%I', c.partitioning_func_schema, c.partitioning_func) + END FROM timescaledb_information.dimensions d JOIN timescaledb_information.hypertables h ON h.hypertable_schema = d.hypertable_schema AND h.hypertable_name = d.hypertable_name + JOIN _timescaledb_catalog.hypertable t + ON t.schema_name = d.hypertable_schema AND t.table_name = d.hypertable_name + JOIN _timescaledb_catalog.dimension c + ON c.hypertable_id = t.id AND c.column_name = d.column_name ORDER BY d.hypertable_schema, d.hypertable_name, d.dimension_number", &[], ) @@ -370,6 +381,7 @@ async fn read_hypertables( time_interval: row.get(3), integer_interval: row.get(4), num_partitions: row.get(5), + partitioning_func: row.get(6), }; match plan.hypertables.last_mut() { Some(last) if last.schema == schema && last.name == name => { @@ -861,10 +873,23 @@ impl ExtensionPlan { }; let mut params: Vec<&(dyn ToSql + Sync)> = vec![&relation, &dimension.column]; params.extend(value); + // A column TimescaleDB cannot partition by itself, such as a time inside a jsonb, + // goes through its function. `create_hypertable` names the first one apart. + let partitioning = match &dimension.partitioning_func { + Some(func) => { + params.push(func); + format!( + ", {}partitioning_func => ${}::text::regproc", + if i == 0 { "time_" } else { "" }, + params.len() + ) + } + None => String::new(), + }; tx.execute( &format!( "SELECT {timescaledb}.{function}($1::text::regclass, \ - $2::text::name{argument}{extra})" + $2::text::name{argument}{partitioning}{extra})" ), ¶ms, ) diff --git a/cli/src/commands/workspace/fork.ts b/cli/src/commands/workspace/fork.ts index 494b2decdd..d16f4cad5e 100644 --- a/cli/src/commands/workspace/fork.ts +++ b/cli/src/commands/workspace/fork.ts @@ -23,8 +23,10 @@ import { readConfigFile, } from "../../core/conf.ts"; -/** Wait for a fork creation started in the background, by the id its request answered with. */ -/** Resolves to what the created fork goes without. */ +/** + * Wait for a fork creation started in the background, by the id its request answered with. + * Resolves to what the created fork goes without. + */ async function waitForForkCreation( parentWorkspace: string, creationId: string,