fix: carry hypertable partitioning functions, leave hierarchical aggregates out

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Ruben Fiszel
2026-12-02 12:29:15 +01:00
co-authored by Claude Opus 5.5
parent 4c71c42e49
commit 63adb2afb9
3 changed files with 34 additions and 7 deletions
+1 -1
View File
@@ -1 +1 @@
91f96ba70bbcc44ebea06e04e10a053eeb43af74
bfb31c16fbb210924ac973cd8cb7939d8406aa1a
@@ -75,6 +75,8 @@ struct Dimension {
time_interval: Option<String>,
integer_interval: Option<i64>,
num_partitions: Option<i16>,
/// The function the column's values go through before they are partitioned, qualified.
partitioning_func: Option<String>,
}
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})"
),
&params,
)
+4 -2
View File
@@ -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,