Skip to content

Commit

Permalink
Cleanup 2
Browse files Browse the repository at this point in the history
  • Loading branch information
fabriziomello committed Mar 3, 2025
1 parent b6d3952 commit ab70d3b
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 49 deletions.
33 changes: 1 addition & 32 deletions src/time_bucket.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,38 +58,7 @@ ts_int16_bucket(PG_FUNCTION_ARGS)
int16 timestamp = PG_GETARG_INT16(1);
int16 offset = PG_NARGS() > 2 ? PG_GETARG_INT16(2) : 0;

// TIME_BUCKET(period, timestamp, offset, min, max, result)

// TIME_BUCKET(period, timestamp, offset, PG_INT16_MIN, PG_INT16_MAX, result);
if (period <= 0)
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("period must be greater than 0")));
if (offset != 0)
{
/* We need to ensure that the timestamp is in range _after_ the */
/* offset is applied: when the offset is positive we need to make */
/* sure the resultant time is at least min, and when negative that */
/* it is less than the max. */
(offset) = (offset) % (period);
if (((offset) > 0 && (timestamp) < (PG_INT16_MIN) + (offset)) ||
((offset) < 0 && (timestamp) > (PG_INT16_MAX) + (offset)))
ereport(ERROR,
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
errmsg("timestamp out of range")));
(timestamp) -= (offset);
}
(result) = ((timestamp) / (period)) * (period);
if ((timestamp) < 0 && (timestamp) % (period))
{
if ((result) < (PG_INT16_MIN) + (period))
ereport(ERROR,
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
errmsg("timestamp out of range")));
else
(result) = (result) - (period);
}
(result) += (offset);
TIME_BUCKET(period, timestamp, offset, PG_INT16_MIN, PG_INT16_MAX, result);

PG_RETURN_INT16(result);
}
Expand Down
8 changes: 0 additions & 8 deletions src/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -206,14 +206,6 @@ int64_min(int64 a, int64 b)
return b;
}

static inline int64
int64_max(int64 a, int64 b)
{
if (a >= b)
return a;
return b;
}

static inline int64
int64_saturating_add(int64 a, int64 b)
{
Expand Down
4 changes: 0 additions & 4 deletions tsl/src/continuous_aggs/invalidation.c
Original file line number Diff line number Diff line change
Expand Up @@ -490,15 +490,11 @@ invalidation_expand_to_bucket_boundaries(Invalidation *inv, Oid time_type_oid,
int64 bucket_width = ts_continuous_agg_fixed_bucket_width(bucket_function);
Assert(bucket_width > 0);

// if (IS_TIMESTAMP_TYPE(time_type_oid))
/* Compute the start of the "first" bucket for the type. The min value
* must be at the start of the "first" bucket or somewhere in the
* bucket. If the min value falls on the exact start of the bucket we are
* good. Otherwise, we need to move to the next full bucket. */
min_bucket_start = ts_time_saturating_add(time_dimension_min, bucket_width - 1, time_type_oid);
// else
// min_bucket_start = time_dimension_min;

min_bucket_start = ts_time_bucket_by_type(bucket_width, min_bucket_start, time_type_oid);

/* Compute the end of the "last" bucket for the time type. Remember that
Expand Down
9 changes: 5 additions & 4 deletions tsl/src/continuous_aggs/materialize.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@
* LICENSE-TIMESCALE for a copy of the license.
*/
#include <postgres.h>

#include <executor/spi.h>
#include <fmgr.h>
#include <lib/stringinfo.h>
#include <scan_iterator.h>
#include <scanner.h>
#include <time_utils.h>
#include <utils/builtins.h>
#include <utils/date.h>
#include <utils/guc.h>
Expand All @@ -24,6 +22,8 @@
#include "debug_assert.h"
#include "guc.h"
#include "materialize.h"
#include "scan_iterator.h"
#include "scanner.h"
#include "time_utils.h"
#include "ts_catalog/continuous_agg.h"
#include "ts_catalog/continuous_aggs_watermark.h"
Expand Down Expand Up @@ -761,7 +761,8 @@ log_refresh_window(int elevel, const ContinuousAgg *cagg, const InternalTimeRang
Assert(!isvarlena);

elog(elevel,
"%s \"%s\" in window [ %s, %s ] internal [ %ld, %ld ] minimum [ %s ]",
"%s \"%s\" in window [ %s, %s ] internal [ " INT64_FORMAT ", " INT64_FORMAT
" ] minimum [ %s ]",
msg,
NameStr(cagg->data.user_view_name),
DatumGetCString(OidFunctionCall1(outfuncid, start_ts)),
Expand Down
1 change: 0 additions & 1 deletion tsl/src/continuous_aggs/refresh.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
#include "materialize.h"
#include "process_utility.h"
#include "refresh.h"
// #include "time_bucket.h"
#include "time_utils.h"
#include "ts_catalog/catalog.h"
#include "ts_catalog/continuous_agg.h"
Expand Down

0 comments on commit ab70d3b

Please sign in to comment.