Skip to content

Commit

Permalink
Remove unused functions from utils.c
Browse files Browse the repository at this point in the history
Remove the following unused functions:
_timescaledb_internal.to_microseconds(TIMESTAMPTZ)
_timescaledb_internal.to_timestamp_pg(BIGINT)
_timescaledb_internal.time_to_internal(anyelement)
  • Loading branch information
svenklemm committed Dec 12, 2018
1 parent 98615f4 commit c59a30f
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 75 deletions.
3 changes: 3 additions & 0 deletions sql/updates/1.0.1--1.1.0-dev.sql
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@ DROP FUNCTION IF EXISTS _timescaledb_internal.drop_chunks_impl(BIGINT, NAME, NAM
DROP FUNCTION IF EXISTS _timescaledb_internal.drop_chunks_type_check(REGTYPE, NAME, NAME);
DROP FUNCTION IF EXISTS _timescaledb_internal.dimension_get_time(INTEGER);
DROP FUNCTION IF EXISTS create_hypertable(regclass, name, name, integer, name, name, anyelement, boolean, boolean, regproc, boolean, text, regproc);
DROP FUNCTION IF EXISTS _timescaledb_internal.to_microseconds(TIMESTAMPTZ);
DROP FUNCTION IF EXISTS _timescaledb_internal.to_timestamp_pg(BIGINT);
DROP FUNCTION IF EXISTS _timescaledb_internal.time_to_internal(anyelement);
10 changes: 1 addition & 9 deletions sql/util_time.sql
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,14 @@
-- at the top level directory of the TimescaleDB distribution.

-- This file contains utilities for time conversion.
CREATE OR REPLACE FUNCTION _timescaledb_internal.to_microseconds(ts TIMESTAMPTZ) RETURNS BIGINT
AS '@MODULE_PATHNAME@', 'ts_pg_timestamp_to_microseconds' LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;

CREATE OR REPLACE FUNCTION _timescaledb_internal.to_unix_microseconds(ts TIMESTAMPTZ) RETURNS BIGINT
AS '@MODULE_PATHNAME@', 'ts_pg_timestamp_to_unix_microseconds' LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;

CREATE OR REPLACE FUNCTION _timescaledb_internal.to_timestamp(unixtime_us BIGINT) RETURNS TIMESTAMPTZ
AS '@MODULE_PATHNAME@', 'ts_pg_unix_microseconds_to_timestamp' LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;

CREATE OR REPLACE FUNCTION _timescaledb_internal.to_timestamp_pg(postgres_us BIGINT) RETURNS TIMESTAMPTZ
AS '@MODULE_PATHNAME@', 'ts_pg_microseconds_to_timestamp' LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;

-- Time can be represented in a hypertable as an int* (bigint/integer/smallint) or as a timestamp type (
-- with or without timezones). In or metatables and other internal systems all time values are stored as bigint.
-- with or without timezones). In metatables and other internal systems all time values are stored as bigint.
-- Converting from int* columns to internal representation is a cast to bigint.
-- Converting from timestamps to internal representation is conversion to epoch (in microseconds).

Expand Down Expand Up @@ -60,5 +54,3 @@ $BODY$
SELECT (int_sec * 1000000)::bigint from extract(epoch from chunk_interval) as int_sec;
$BODY$;

CREATE OR REPLACE FUNCTION _timescaledb_internal.time_to_internal(time_element anyelement) RETURNS BIGINT
AS '@MODULE_PATHNAME@', 'ts_time_to_internal' LANGUAGE C IMMUTABLE PARALLEL SAFE STRICT;
66 changes: 0 additions & 66 deletions src/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,60 +34,6 @@
#include <utils/fmgrprotos.h>
#endif

TS_FUNCTION_INFO_V1(ts_pg_timestamp_to_microseconds);

/*
* Convert a Postgres TIMESTAMP to BIGINT microseconds relative the Postgres epoch.
*/
Datum
ts_pg_timestamp_to_microseconds(PG_FUNCTION_ARGS)
{
TimestampTz timestamp = PG_GETARG_TIMESTAMPTZ(0);
int64 microseconds;

if (!IS_VALID_TIMESTAMP(timestamp))
ereport(ERROR,
(errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
errmsg("timestamp out of range")));

#ifdef HAVE_INT64_TIMESTAMP
microseconds = timestamp;
#else
if (1)
{
int64 seconds = (int64) timestamp;

microseconds = (seconds * USECS_PER_SEC) + ((timestamp - seconds) * USECS_PER_SEC);
}
#endif
PG_RETURN_INT64(microseconds);
}

TS_FUNCTION_INFO_V1(ts_pg_microseconds_to_timestamp);

/*
* Convert BIGINT microseconds relative the UNIX epoch to a Postgres TIMESTAMP.
*/
Datum
ts_pg_microseconds_to_timestamp(PG_FUNCTION_ARGS)
{
int64 microseconds = PG_GETARG_INT64(0);
TimestampTz timestamp;

#ifdef HAVE_INT64_TIMESTAMP
timestamp = microseconds;
#else
timestamp = microseconds / USECS_PER_SEC;
#endif

if (!IS_VALID_TIMESTAMP(timestamp))
ereport(ERROR,
(errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
errmsg("timestamp out of range")));

PG_RETURN_TIMESTAMPTZ(timestamp);
}

TS_FUNCTION_INFO_V1(ts_pg_timestamp_to_unix_microseconds);

/*
Expand Down Expand Up @@ -157,18 +103,6 @@ ts_pg_unix_microseconds_to_timestamp(PG_FUNCTION_ARGS)
PG_RETURN_TIMESTAMPTZ(timestamp);
}

TS_FUNCTION_INFO_V1(ts_time_to_internal);

Datum
ts_time_to_internal(PG_FUNCTION_ARGS)
{
if (PG_ARGISNULL(0))
PG_RETURN_NULL();

PG_RETURN_INT64(ts_time_value_to_internal(PG_GETARG_DATUM(0), get_fn_expr_argtype(fcinfo->flinfo, 0), false));
}


/* Convert valid timescale time column type to internal representation */
int64
ts_time_value_to_internal(Datum time_val, Oid type_oid, bool failure_ok)
Expand Down

0 comments on commit c59a30f

Please sign in to comment.