Skip to content

Commit

Permalink
Encapsulate the TimestampTz output behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
fabriziomello committed Oct 4, 2024
1 parent e0cf83d commit bc5bffd
Showing 1 changed file with 31 additions and 22 deletions.
53 changes: 31 additions & 22 deletions tsl/src/continuous_aggs/materialize.c
Original file line number Diff line number Diff line change
Expand Up @@ -369,23 +369,35 @@ spi_update_watermark(Hypertable *mat_ht, SchemaAndName materialization_table,
}
}

static int SavedDateStyle;
static int SavedDateOrder;

static inline void
set_date_config(int newDateStyle, int newDateOrder)
static char *
OidSafeTimestampTzOutputFunctionCall(Oid type, Datum val)
{
SavedDateStyle = DateStyle;
SavedDateOrder = DateOrder;
DateStyle = newDateStyle;
DateOrder = newDateOrder;
}
char *result;
int SavedDateStyle, SavedDateOrder;
Oid functionId;
bool type_is_varlena;

static inline void
unset_date_config()
{
DateStyle = SavedDateStyle;
DateOrder = SavedDateOrder;
getTypeOutputInfo(type, &functionId, &type_is_varlena);

/* Save DateStyle and DateOrder and force it to use ISO dates and YMD order */
if (functionId == TIMESTAMPTZOID)
{
SavedDateStyle = DateStyle;
SavedDateOrder = DateOrder;
DateStyle = USE_ISO_DATES;
DateOrder = DATEORDER_YMD;

Check warning on line 388 in tsl/src/continuous_aggs/materialize.c

View check run for this annotation

Codecov / codecov/patch

tsl/src/continuous_aggs/materialize.c#L385-L388

Added lines #L385 - L388 were not covered by tests
}

result = OidOutputFunctionCall(functionId, val);

/* Restore previous date style and order configuration */
if (functionId == TIMESTAMPTZOID)
{
DateStyle = SavedDateStyle;
DateOrder = SavedDateOrder;

Check warning on line 397 in tsl/src/continuous_aggs/materialize.c

View check run for this annotation

Codecov / codecov/patch

tsl/src/continuous_aggs/materialize.c#L396-L397

Added lines #L396 - L397 were not covered by tests
}

return result;
}

static void
Expand All @@ -394,18 +406,15 @@ spi_update_materializations(Hypertable *mat_ht, const ContinuousAgg *cagg,
const NameData *time_column_name, TimeRange invalidation_range,
const int32 chunk_id)
{
Oid out_fn;
bool type_is_varlena;
char *invalidation_start;
char *invalidation_end;
StringInfo chunk_condition = makeStringInfo();
uint64 rows_processed = 0;

getTypeOutputInfo(invalidation_range.type, &out_fn, &type_is_varlena);
set_date_config(USE_ISO_DATES, DATEORDER_YMD);
invalidation_start = OidOutputFunctionCall(out_fn, invalidation_range.start);
invalidation_end = OidOutputFunctionCall(out_fn, invalidation_range.end);
unset_date_config();
invalidation_start =
OidSafeTimestampTzOutputFunctionCall(invalidation_range.type, invalidation_range.start);
invalidation_end =
OidSafeTimestampTzOutputFunctionCall(invalidation_range.type, invalidation_range.end);

/* MERGE statement is available starting on PG15 and we'll support it only in the new format of
* CAggs and for non-compressed hypertables */
Expand Down

0 comments on commit bc5bffd

Please sign in to comment.