diff --git a/include/doublen.h b/include/doublen.h index 9c3bf96773..cc5b5d7379 100644 --- a/include/doublen.h +++ b/include/doublen.h @@ -1,7 +1,4 @@ /***************************************************************************** - * - * doublen.h - * Internal types used for the average and centroid temporal aggregates. * * This MobilityDB code is provided under The PostgreSQL License. * @@ -27,6 +24,12 @@ * *****************************************************************************/ +/** + * @file doublen.h + * Internal types used in particular for computing the average and centroid + * temporal aggregates. + */ + #ifndef __DOUBLEN_H__ #define __DOUBLEN_H__ diff --git a/include/lifting.h b/include/lifting.h index 8b3f496122..05020059c6 100644 --- a/include/lifting.h +++ b/include/lifting.h @@ -1,7 +1,4 @@ /***************************************************************************** - * - * lifting.c - * Generic functions for lifting functions and operators on temporal types. * * This MobilityDB code is provided under The PostgreSQL License. * @@ -27,6 +24,11 @@ * *****************************************************************************/ +/** + * @file lifting.c + * Generic functions for lifting functions and operators on temporal types. + */ + #ifndef __LIFTING_H__ #define __LIFTING_H__ diff --git a/include/oidcache.h b/include/oidcache.h index 15edd06916..c3cc4e6644 100644 --- a/include/oidcache.h +++ b/include/oidcache.h @@ -1,7 +1,4 @@ /***************************************************************************** - * - * oidcache.h - * Functions for building a cache of type and operator Oids. * * This MobilityDB code is provided under The PostgreSQL License. * @@ -27,6 +24,11 @@ * *****************************************************************************/ +/** + * @file oidcache.h + * Functions for building a cache of type and operator Oids. + */ + #ifndef OIDCACHE_H #define OIDCACHE_H diff --git a/include/period.h b/include/period.h index 072d217590..8cf9d4e0ec 100644 --- a/include/period.h +++ b/include/period.h @@ -1,7 +1,4 @@ /***************************************************************************** - * - * period.h - * Basic routines for timestamptz periods * * This MobilityDB code is provided under The PostgreSQL License. * @@ -29,6 +26,12 @@ * *****************************************************************************/ +/** + * @file period.h + * Basic routines for time periods composed of two `TimestampTz` values and + * two Boolean values stating whether the bounds are inclusive or not. + */ + #ifndef __PERIOD_H__ #define __PERIOD_H__ @@ -79,7 +82,7 @@ extern void period_shift_tscale(Period *result, const Interval *start, /* period -> interval */ -extern Datum period_timespan(PG_FUNCTION_ARGS); +extern Datum period_duration(PG_FUNCTION_ARGS); /* Functions for defining B-tree index */ @@ -109,7 +112,7 @@ extern void period_set(Period *p, TimestampTz lower, TimestampTz upper, bool lower_inc, bool upper_inc); extern Period *period_copy(const Period *p); extern float8 period_to_secs(TimestampTz t1, TimestampTz t2); -extern Interval *period_timespan_internal(const Period *p); +extern Interval *period_duration_internal(const Period *p); extern Period **periodarr_normalize(Period **periods, int count, int *newcount); extern Period *period_super_union(const Period *p1, const Period *p2); extern void period_expand(Period *p1, const Period *p2); diff --git a/include/periodset.h b/include/periodset.h index 2933ae2370..4da01ea86a 100644 --- a/include/periodset.h +++ b/include/periodset.h @@ -1,7 +1,4 @@ /***************************************************************************** - * - * periodset.c - * Basic functions for set of periods. * * This MobilityDB code is provided under The PostgreSQL License. * @@ -27,6 +24,11 @@ * *****************************************************************************/ +/** + * @file periodset.c + * Basic functions for set of disjoint periods. + */ + #ifndef __PERIODSET_H__ #define __PERIODSET_H__ @@ -76,6 +78,7 @@ extern PeriodSet *timestampset_to_periodset_internal(const TimestampSet *ts); extern Datum periodset_mem_size(PG_FUNCTION_ARGS); extern Datum periodset_timespan(PG_FUNCTION_ARGS); +extern Datum periodset_duration(PG_FUNCTION_ARGS); extern Datum periodset_num_periods(PG_FUNCTION_ARGS); extern Datum periodset_start_period(PG_FUNCTION_ARGS); extern Datum periodset_end_period(PG_FUNCTION_ARGS); diff --git a/include/rangetypes_ext.h b/include/rangetypes_ext.h index 15666179d9..ca4f5efbef 100644 --- a/include/rangetypes_ext.h +++ b/include/rangetypes_ext.h @@ -1,7 +1,4 @@ /***************************************************************************** - * - * rangetypes_ext.h - * Extension of operators for range types. * * This MobilityDB code is provided under The PostgreSQL License. * @@ -27,6 +24,11 @@ * *****************************************************************************/ +/** + * @file rangetypes_ext.h + * Extended operators for range types. + */ + #ifndef __RANGETYPES_EXT_H__ #define __RANGETYPES_EXT_H__ diff --git a/include/tbool_boolops.h b/include/tbool_boolops.h index 276acfc085..a017386cfa 100644 --- a/include/tbool_boolops.h +++ b/include/tbool_boolops.h @@ -1,7 +1,4 @@ /***************************************************************************** - * - * tbool_boolops.h - * Temporal Boolean operators (and, or, not). * * This MobilityDB code is provided under The PostgreSQL License. * @@ -27,6 +24,11 @@ * *****************************************************************************/ +/** + * @file tbool_boolops.h + * Temporal Boolean operators (and, or, not). + */ + #ifndef __TBOOL_BOOLOPS_H__ #define __TBOOL_BOOLOPS_H__ diff --git a/include/tbox.h b/include/tbox.h index 3ec264bfb3..938611fe7d 100644 --- a/include/tbox.h +++ b/include/tbox.h @@ -1,7 +1,4 @@ /***************************************************************************** - * - * tbox.h - * Functions for temporal bounding boxes. * * This MobilityDB code is provided under The PostgreSQL License. * @@ -29,6 +26,11 @@ * *****************************************************************************/ +/** + * @file tbox.h + * Functions for temporal bounding boxes. + */ + #ifndef __TBOX_H__ #define __TBOX_H__ diff --git a/include/temporal.h b/include/temporal.h index b2dff5f7ff..6b1e42e689 100644 --- a/include/temporal.h +++ b/include/temporal.h @@ -1,7 +1,4 @@ /***************************************************************************** - * - * temporal.h - * Basic functions for temporal types of any subtype. * * This MobilityDB code is provided under The PostgreSQL License. * @@ -27,6 +24,11 @@ * *****************************************************************************/ +/** + * @file temporal.h + * Basic functions for temporal types of any subtype. + */ + #ifndef __TEMPORAL_H__ #define __TEMPORAL_H__ @@ -88,6 +90,9 @@ #define BBOX_TEST_NO false /** Symbolic constants for the make functions */ +#define MERGE true +#define MERGE_NO false + #define NORMALIZE true #define NORMALIZE_NO false @@ -486,7 +491,7 @@ extern void ensure_increasing_timestamps(const TInstant *inst1, const TInstant *inst2, bool strict); extern void ensure_same_overlapping_value(const TInstant *inst1, const TInstant *inst2); -extern void ensure_valid_tinstantarr(TInstant **instants, int count); +extern void ensure_valid_tinstantarr(TInstant **instants, int count, bool merge); extern void ensure_valid_tsequencearr(TSequence **sequences, int count); /* Input/output functions */ diff --git a/include/temporal_aggfuncs.h b/include/temporal_aggfuncs.h index 0a5288094e..441a8dcd3c 100644 --- a/include/temporal_aggfuncs.h +++ b/include/temporal_aggfuncs.h @@ -1,7 +1,4 @@ /***************************************************************************** - * - * temporal_aggfuncs.h - * Temporal aggregate functions * * This MobilityDB code is provided under The PostgreSQL License. * @@ -27,6 +24,11 @@ * *****************************************************************************/ +/** + * @file temporal_aggfuncs.h + * Temporal aggregate functions + */ + #ifndef __TEMPORAL_AGGFUNCS_H__ #define __TEMPORAL_AGGFUNCS_H__ diff --git a/include/temporal_analyze.h b/include/temporal_analyze.h index 02d401d957..cebe2d3eb0 100644 --- a/include/temporal_analyze.h +++ b/include/temporal_analyze.h @@ -1,7 +1,4 @@ /***************************************************************************** - * - * temporal_analyze.h - * Functions for gathering statistics from temporal alphanumeric columns * * This MobilityDB code is provided under The PostgreSQL License. * @@ -25,8 +22,13 @@ * AN "AS IS" BASIS, AND UNIVERSITE LIBRE DE BRUXELLES HAS NO OBLIGATIONS TO * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.  * - *------------------------------------------------------------------------- + *****************************************************************************/ + +/** + * @file temporal_analyze.h + * Functions for gathering statistics from temporal alphanumeric columns */ + #ifndef __TEMPORAL_ANALYZE_H__ #define __TEMPORAL_ANALYZE_H__ diff --git a/include/temporal_boxops.h b/include/temporal_boxops.h index 02be75855d..cfed3f0c0a 100644 --- a/include/temporal_boxops.h +++ b/include/temporal_boxops.h @@ -1,7 +1,4 @@ /***************************************************************************** - * - * temporal_boxops.h - * Bounding box operators for temporal types. * * This MobilityDB code is provided under The PostgreSQL License. * @@ -27,6 +24,11 @@ * *****************************************************************************/ +/** + * @file temporal_boxops.h + * Bounding box operators for temporal types. + */ + #ifndef __TEMPORAL_BOXOPS_H__ #define __TEMPORAL_BOXOPS_H__ diff --git a/include/temporal_compops.h b/include/temporal_compops.h index e2457ebc03..17d6cad0a1 100644 --- a/include/temporal_compops.h +++ b/include/temporal_compops.h @@ -1,7 +1,4 @@ /***************************************************************************** - * - * temporal_compops.h - * Temporal comparison operators (=, <>, <, >, <=, >=). * * This MobilityDB code is provided under The PostgreSQL License. * @@ -27,6 +24,11 @@ * *****************************************************************************/ +/** + * @file temporal_compops.h + * Temporal comparison operators (=, <>, <, >, <=, >=). + */ + #ifndef __TEMPORAL_COMPOPS_H__ #define __TEMPORAL_COMPOPS_H__ diff --git a/include/temporal_gist.h b/include/temporal_gist.h index 385b32b63f..01a13b2f82 100644 --- a/include/temporal_gist.h +++ b/include/temporal_gist.h @@ -1,7 +1,4 @@ /***************************************************************************** - * - * temporal_gist.c - * Quad-tree SP-GiST index for temporal boolean and temporal text types. * * This MobilityDB code is provided under The PostgreSQL License. * @@ -27,6 +24,11 @@ * *****************************************************************************/ +/** + * @file temporal_gist.h + * Quad-tree SP-GiST index for temporal boolean and temporal text types. + */ + #ifndef __TEMPORAL_GIST_H__ #define __TEMPORAL_GIST_H__ diff --git a/include/temporal_parser.h b/include/temporal_parser.h index 2420a7041d..61b9cb9a4e 100644 --- a/include/temporal_parser.h +++ b/include/temporal_parser.h @@ -1,7 +1,4 @@ /***************************************************************************** - * - * temporal_parser.h - * Functions for parsing temporal types. * * This MobilityDB code is provided under The PostgreSQL License. * @@ -27,6 +24,11 @@ * *****************************************************************************/ +/** + * @file temporal_parser.h + * Functions for parsing temporal types. + */ + #ifndef __TEMPORAL_PARSER_H__ #define __TEMPORAL_PARSER_H__ diff --git a/include/temporal_posops.h b/include/temporal_posops.h index d4d4d48df8..0533934f12 100644 --- a/include/temporal_posops.h +++ b/include/temporal_posops.h @@ -1,7 +1,4 @@ /***************************************************************************** - * - * temporal_posops.h - * Relative position operators for temporal types. * * This MobilityDB code is provided under The PostgreSQL License. * @@ -27,6 +24,11 @@ * *****************************************************************************/ +/** + * @file temporal_posops.h + * Relative position operators for temporal types. + */ + #ifndef __TEMPORAL_POSOPS_H__ #define __TEMPORAL_POSOPS_H__ diff --git a/include/temporal_selfuncs.h b/include/temporal_selfuncs.h index cc64eaad37..9d30779076 100644 --- a/include/temporal_selfuncs.h +++ b/include/temporal_selfuncs.h @@ -1,7 +1,4 @@ /***************************************************************************** - * - * temporal_selfuncs.h - * Selectivity functions for the temporal types * * This MobilityDB code is provided under The PostgreSQL License. * @@ -27,6 +24,11 @@ * *****************************************************************************/ +/** + * @file temporal_selfuncs.h + * Selectivity functions for temporal types + */ + #ifndef __TEMPORAL_SELFUNCS_H__ #define __TEMPORAL_SELFUNCS_H__ diff --git a/include/temporal_spgist.h b/include/temporal_spgist.h index e8fe154464..e2516741fb 100644 --- a/include/temporal_spgist.h +++ b/include/temporal_spgist.h @@ -1,7 +1,4 @@ /***************************************************************************** - * - * temporal_spgist.c - * Quad-tree SP-GiST index for temporal boolean and temporal text types. * * This MobilityDB code is provided under The PostgreSQL License. * @@ -27,6 +24,11 @@ * *****************************************************************************/ +/** + * @file temporal_spgist.c + * Quad-tree SP-GiST index for temporal boolean and temporal text types. + */ + #ifndef __TEMPORAL_SPGIST_H__ #define __TEMPORAL_SPGIST_H__ diff --git a/include/temporal_util.h b/include/temporal_util.h index 22feb7dbc7..7c30c8fd78 100644 --- a/include/temporal_util.h +++ b/include/temporal_util.h @@ -1,7 +1,4 @@ /***************************************************************************** - * - * temporal_util.c - * Miscellaneous utility functions for temporal types. * * This MobilityDB code is provided under The PostgreSQL License. * @@ -27,6 +24,11 @@ * *****************************************************************************/ +/** + * @file temporal_util.c + * Miscellaneous utility functions for temporal types. + */ + #ifndef __TEMPORAL_UTIL_H__ #define __TEMPORAL_UTIL_H__ diff --git a/include/temporal_waggfuncs.h b/include/temporal_waggfuncs.h index 56145f9b5b..078b197fbe 100644 --- a/include/temporal_waggfuncs.h +++ b/include/temporal_waggfuncs.h @@ -1,7 +1,4 @@ /***************************************************************************** - * - * temporal_waggfuncs.c - * Window temporal aggregate functions * * This MobilityDB code is provided under The PostgreSQL License. * @@ -27,6 +24,11 @@ * *****************************************************************************/ +/** + * @file temporal_waggfuncs.c + * Window temporal aggregate functions + */ + #ifndef __TEMPORAL_WAGGFUNCS_H__ #define __TEMPORAL_WAGGFUNCS_H__ diff --git a/include/temporaltypes.h b/include/temporaltypes.h index 0f3567ff2f..eff192be12 100644 --- a/include/temporaltypes.h +++ b/include/temporaltypes.h @@ -1,7 +1,4 @@ /***************************************************************************** - * - * temporaltypes.h - * Functions for temporal types. * * This MobilityDB code is provided under The PostgreSQL License. * @@ -27,6 +24,11 @@ * *****************************************************************************/ +/** + * @file temporaltypes.h + * General functions for temporal types. + */ + #ifndef __TEMPORALTYPES_H__ #define __TEMPORALTYPES_H__ diff --git a/include/time_analyze.h b/include/time_analyze.h index 075e7198c4..2fc1c42b17 100644 --- a/include/time_analyze.h +++ b/include/time_analyze.h @@ -1,7 +1,4 @@ /***************************************************************************** - * - * time_analyze.h - * Functions for gathering statistics from time type columns * * This MobilityDB code is provided under The PostgreSQL License. * @@ -27,6 +24,11 @@ * *****************************************************************************/ +/** + * @file time_analyze.h + * Functions for gathering statistics from time type columns + */ + #ifndef __TIME_ANALYZE_H__ #define __TIME_ANALYZE_H__ diff --git a/include/time_gist.h b/include/time_gist.h index b00aa15ac0..ee8d8eff0c 100644 --- a/include/time_gist.h +++ b/include/time_gist.h @@ -1,7 +1,4 @@ /***************************************************************************** - * - * time_gist.c - * R-tree GiST index for time types. * * This MobilityDB code is provided under The PostgreSQL License. * @@ -27,6 +24,11 @@ * *****************************************************************************/ +/** + * @file time_gist.c + * R-tree GiST index for time types. + */ + #ifndef __TIME_GIST_H__ #define __TIME_GIST_H__ diff --git a/include/time_selfuncs.h b/include/time_selfuncs.h index 22f86075ff..80eaa140eb 100644 --- a/include/time_selfuncs.h +++ b/include/time_selfuncs.h @@ -1,7 +1,4 @@ /***************************************************************************** - * - * time_selfuncs.c - * Functions for selectivity estimation of time types operators * * This MobilityDB code is provided under The PostgreSQL License. * @@ -27,6 +24,11 @@ * *****************************************************************************/ +/** + * @file time_selfuncs.c + * Functions for selectivity estimation of time types operators + */ + #ifndef __TIME_SELFUNCS_H__ #define __TIME_SELFUNCS_H__ diff --git a/include/time_spgist.h b/include/time_spgist.h index 70cb076773..968b4f8efb 100644 --- a/include/time_spgist.h +++ b/include/time_spgist.h @@ -1,7 +1,4 @@ /***************************************************************************** - * - * time_spgist.h - * Quad-tree SP-GiST index for time types. * * This MobilityDB code is provided under The PostgreSQL License. * @@ -27,6 +24,11 @@ * *****************************************************************************/ +/** + * @file time_spgist.h + * Quad-tree SP-GiST index for time types. + */ + #ifndef __TIME_SPGIST_H__ #define __TIME_SPGIST_H__ diff --git a/include/timeops.h b/include/timeops.h index 7696ead261..9ac46386fc 100644 --- a/include/timeops.h +++ b/include/timeops.h @@ -1,7 +1,4 @@ /***************************************************************************** - * - * timeops.h - * Operators for time types. * * This MobilityDB code is provided under The PostgreSQL License. * @@ -27,6 +24,11 @@ * *****************************************************************************/ +/** + * @file timeops.h + * Operators for time types. + */ + #ifndef __TIMEOPS_H__ #define __TIMEOPS_H__ diff --git a/include/timestampset.h b/include/timestampset.h index 16bf699cf9..0feef7a100 100644 --- a/include/timestampset.h +++ b/include/timestampset.h @@ -1,7 +1,4 @@ /***************************************************************************** - * - * timestampset.h - * Basic functions for set of timestamps. * * This MobilityDB code is provided under The PostgreSQL License. * @@ -27,6 +24,11 @@ * *****************************************************************************/ +/** + * @file timestampset.h + * Basic functions for set of (distinct) timestamps. + */ + #ifndef __TIMESTAMPSET_H__ #define __TIMESTAMPSET_H__ @@ -66,6 +68,7 @@ extern Datum timestampset_to_period(PG_FUNCTION_ARGS); /* Accessor functions */ extern Datum timestampset_mem_size(PG_FUNCTION_ARGS); +extern Datum timestampset_timespan(PG_FUNCTION_ARGS); extern Datum timestampset_num_timestamps(PG_FUNCTION_ARGS); extern Datum timestampset_start_timestamp(PG_FUNCTION_ARGS); extern Datum timestampset_end_timestamp(PG_FUNCTION_ARGS); diff --git a/include/timetypes.h b/include/timetypes.h index 7a425d55fb..3ad8c77c18 100644 --- a/include/timetypes.h +++ b/include/timetypes.h @@ -1,8 +1,4 @@ /***************************************************************************** - * - * timetypes.h - * Functions for time types based on timestamptz, that is, - * timestampset, period, periodset * * This MobilityDB code is provided under The PostgreSQL License. * @@ -28,15 +24,15 @@ * *****************************************************************************/ - /** @file timetypes.h - * Functions for time types based on `timestamptz`, that is, - * `timestampset`, `period`, and `periodset`. +/** @file timetypes.h + * Functions for time types based on `TimestampTz`, that is, + * `TimestampSet`, `Period`, and `PeriodSet`. * * The `Period` type is a specialized version of the `RangeType` in PostgreSQL. * It is considerably more efficient, in particular because it is a * fix-length type, it has finite bounds, and do not allow empty periods. - * The `TimestampSet` type represents a set of disjoint `timestamptz`. - * The `PeriodSet` type represents a set of disjoint periods. + * The `TimestampSet` type represents sets of disjoint `TimestampTz`. + * The `PeriodSet` type represents sets of disjoint `Period` values. */ #ifndef __TIMETYPES_H__ diff --git a/include/tinstant.h b/include/tinstant.h index 608ed2344c..33c67eb0fe 100644 --- a/include/tinstant.h +++ b/include/tinstant.h @@ -1,7 +1,4 @@ /***************************************************************************** - * - * tinstant.h - * Basic functions for temporal instants. * * This MobilityDB code is provided under The PostgreSQL License. * @@ -27,6 +24,11 @@ * *****************************************************************************/ +/** + * @file tinstant.h + * Basic functions for temporal instants. + */ + #ifndef __TINSTANT_H__ #define __TINSTANT_H__ diff --git a/include/tinstantset.h b/include/tinstantset.h index 0aa6861c82..958a5a239a 100644 --- a/include/tinstantset.h +++ b/include/tinstantset.h @@ -1,7 +1,4 @@ /***************************************************************************** - * - * tinstantset.h - * Basic functions for temporal instant sets. * * This MobilityDB code is provided under The PostgreSQL License. * @@ -27,6 +24,11 @@ * *****************************************************************************/ +/** + * @file tinstantset.h + * Basic functions for temporal instant sets. + */ + #ifndef __TINSTANTSET_H__ #define __TINSTANTSET_H__ @@ -41,8 +43,8 @@ extern TInstant *tinstantset_inst_n(const TInstantSet *ti, int index); extern bool tinstantset_find_timestamp(const TInstantSet *ti, TimestampTz t, int *pos); -extern TInstantSet *tinstantset_make(TInstant **instants, int count); -extern TInstantSet *tinstantset_make_free(TInstant **instants, int count); +extern TInstantSet *tinstantset_make(TInstant **instants, int count, bool merge); +extern TInstantSet *tinstantset_make_free(TInstant **instants, int count, bool merge); extern TInstantSet *tinstantset_copy(const TInstantSet *ti); /* Intersection functions */ @@ -93,6 +95,7 @@ extern void tinstantset_bbox(void *box, const TInstantSet *ti); extern Datum tinstantset_min_value(const TInstantSet *ti); extern Datum tinstantset_max_value(const TInstantSet *ti); extern void tinstantset_period(Period *p, const TInstantSet *ti); +extern Datum tinstantset_timespan(const TInstantSet *ti); extern TInstant **tinstantset_instants(const TInstantSet *ti); extern ArrayType *tinstantset_instants_array(const TInstantSet *ti); extern TimestampTz tinstantset_start_timestamp(const TInstantSet *ti); diff --git a/include/tnumber_distance.h b/include/tnumber_distance.h index 322e371e18..8de1d96442 100644 --- a/include/tnumber_distance.h +++ b/include/tnumber_distance.h @@ -1,7 +1,4 @@ /***************************************************************************** - * - * tnumber_distance.h - * Distance functions for temporal numbers. * * This MobilityDB code is provided under The PostgreSQL License. * @@ -27,6 +24,11 @@ * *****************************************************************************/ +/** + * @file tnumber_distance.h + * Distance functions for temporal numbers. + */ + #ifndef __TNUMBER_DISTANCE_H__ #define __TNUMBER_DISTANCE_H__ diff --git a/include/tnumber_gist.h b/include/tnumber_gist.h index e57631243a..58a330b74b 100644 --- a/include/tnumber_gist.h +++ b/include/tnumber_gist.h @@ -1,7 +1,4 @@ /***************************************************************************** - * - * tnumber_gist.c - * R-tree GiST index for temporal integers and temporal floats * * This MobilityDB code is provided under The PostgreSQL License. * @@ -27,6 +24,11 @@ * *****************************************************************************/ +/** + * @file tnumber_gist.c + * R-tree GiST index for temporal integers and temporal floats + */ + #ifndef __TNUMBER_GIST_H__ #define __TNUMBER_GIST_H__ diff --git a/include/tnumber_mathfuncs.h b/include/tnumber_mathfuncs.h index 28a37fca8a..2e57cbd59c 100644 --- a/include/tnumber_mathfuncs.h +++ b/include/tnumber_mathfuncs.h @@ -1,8 +1,4 @@ /***************************************************************************** - * - * tnumber_mathfuncs.c - * Temporal mathematical operators (+, -, *, /) and functions (round, - * degrees). * * This MobilityDB code is provided under The PostgreSQL License. * @@ -28,6 +24,12 @@ * *****************************************************************************/ +/** + * @file tnumber_mathfuncs.c + * Temporal mathematical operators (+, -, *, /) and functions (round, + * degrees). + */ + #ifndef __TEMPORAL_MATHFUNCS_H__ #define __TEMPORAL_MATHFUNCS_H__ diff --git a/include/tnumber_selfuncs.h b/include/tnumber_selfuncs.h index 27eb735776..acd5bbbbe9 100644 --- a/include/tnumber_selfuncs.h +++ b/include/tnumber_selfuncs.h @@ -1,7 +1,4 @@ /***************************************************************************** - * - * tnumber_selfuncs.h - * Functions for selectivity estimation of operators on temporal number types * * This MobilityDB code is provided under The PostgreSQL License. * @@ -27,6 +24,11 @@ * *****************************************************************************/ +/** + * @file tnumber_selfuncs.h + * Functions for selectivity estimation of operators on temporal number types + */ + #ifndef __TNUMBER_SELFUNCS_H__ #define __TNUMBER_SELFUNCS_H__ diff --git a/include/tnumber_spgist.h b/include/tnumber_spgist.h index b9f9189658..164747a9e7 100644 --- a/include/tnumber_spgist.h +++ b/include/tnumber_spgist.h @@ -1,8 +1,4 @@ /***************************************************************************** - * - * tnumber_spgist.c - * SP-GiST implementation of 4-dimensional quad tree over temporal - * integers and floats. * * This MobilityDB code is provided under The PostgreSQL License. * @@ -28,6 +24,12 @@ * *****************************************************************************/ +/** + * @file tnumber_spgist.c + * SP-GiST implementation of 4-dimensional quad tree over temporal + * integers and floats. + */ + #ifndef __TNUMBER_SPGIST_H__ #define __TNUMBER_SPGIST_H__ diff --git a/include/tsequence.h b/include/tsequence.h index 7014856c4f..69b0d28730 100644 --- a/include/tsequence.h +++ b/include/tsequence.h @@ -1,7 +1,4 @@ /***************************************************************************** - * - * tsequence.h - * Basic functions for temporal sequences. * * This MobilityDB code is provided under The PostgreSQL License. * @@ -27,6 +24,11 @@ * *****************************************************************************/ +/** + * @file tsequence.h + * Basic functions for temporal sequences. + */ + #ifndef __TSEQUENCE_H__ #define __TSEQUENCE_H__ @@ -94,7 +96,6 @@ extern Datum tsequence_from_base(PG_FUNCTION_ARGS); /* Append and merge functions */ -extern TSequence *tsequence_join(const TSequence *seq1, const TSequence *seq2, bool last, bool first); extern Temporal *tsequence_append_tinstant(const TSequence *seq, const TInstant *inst); extern Temporal *tsequence_merge(const TSequence *seq1, const TSequence *seq2); extern TSequence **tsequence_merge_array1(TSequence **sequences, int count, int *totalcount); @@ -126,7 +127,7 @@ extern TInstant *tsequence_min_instant(const TSequence *seq); extern Datum tsequence_min_value(const TSequence *seq); extern Datum tsequence_max_value(const TSequence *seq); extern void tsequence_period(Period *p, const TSequence *seq); -extern Datum tsequence_timespan(const TSequence *seq); +extern Datum tsequence_duration(const TSequence *seq); extern TInstant **tsequence_instants(const TSequence *seq); extern ArrayType *tsequence_instants_array(const TSequence *seq); extern TimestampTz tsequence_start_timestamp(const TSequence *seq); diff --git a/include/tsequenceset.h b/include/tsequenceset.h index 5990216b90..913de1cee7 100644 --- a/include/tsequenceset.h +++ b/include/tsequenceset.h @@ -1,7 +1,4 @@ /***************************************************************************** - * - * tsequenceset.h - * Basic functions for temporal sequence sets. * * This MobilityDB code is provided under The PostgreSQL License. * @@ -27,6 +24,11 @@ * *****************************************************************************/ +/** + * @file tsequenceset.h + * Basic functions for temporal sequence sets. + */ + #ifndef __TSEQUENCESET_H__ #define __TSEQUENCESET_H__ @@ -119,6 +121,7 @@ extern Datum tsequenceset_min_value(const TSequenceSet *ts); extern Datum tsequenceset_max_value(const TSequenceSet *ts); extern PeriodSet *tsequenceset_get_time(const TSequenceSet *ts); extern Datum tsequenceset_timespan(const TSequenceSet *ts); +extern Datum tsequenceset_duration(const TSequenceSet *ts); extern void tsequenceset_period(Period *p, const TSequenceSet *ts); extern TSequence **tsequenceset_sequences(const TSequenceSet *ts); extern ArrayType *tsequenceset_sequences_array(const TSequenceSet *ts); diff --git a/include/ttext_textfuncs.h b/include/ttext_textfuncs.h index 3101b178e7..ec3c7477b7 100644 --- a/include/ttext_textfuncs.h +++ b/include/ttext_textfuncs.h @@ -1,7 +1,4 @@ /***************************************************************************** - * - * ttext_textfuncs.h - * Text functions (textcat, lower, upper). * * This MobilityDB code is provided under The PostgreSQL License. * @@ -27,6 +24,11 @@ * *****************************************************************************/ +/** + * @file ttext_textfuncs.h + * Temporal text functions: `textcat`, `lower`, `upper`. + */ + #ifndef __TTEXT_TEXTFUNCS_H__ #define __TTEXT_TEXTFUNCS_H__ diff --git a/point/include/geography_funcs.h b/point/include/geography_funcs.h index 6773b83921..3b159afdce 100644 --- a/point/include/geography_funcs.h +++ b/point/include/geography_funcs.h @@ -1,7 +1,4 @@ /***************************************************************************** - * - * geography_functions.h - * Spatial functions for PostGIS geography. * * This MobilityDB code is provided under The PostgreSQL License. * @@ -27,6 +24,11 @@ * *****************************************************************************/ +/** + * @file geography_funcs.h + * Spatial functions for PostGIS geography. + */ + #ifndef __GEOGRAPHY_FUNCTIONS_H__ #define __GEOGRAPHY_FUNCTIONS_H__ diff --git a/point/include/postgis.h b/point/include/postgis.h index 6e24278c3a..054d9ee8f5 100644 --- a/point/include/postgis.h +++ b/point/include/postgis.h @@ -1,8 +1,4 @@ /***************************************************************************** - * - * postgis.h - * PostGIS definitions that are needed in the extension but are not exported - * in PostGIS headers * * This MobilityDB code is provided under The PostgreSQL License. * @@ -28,6 +24,12 @@ * *****************************************************************************/ +/** + * @file postgis.h + * PostGIS definitions that are needed in MobilityDB but are not exported + * in PostGIS headers + */ + #ifndef __POSTGIS_H__ #define __POSTGIS_H__ diff --git a/point/include/projection_gk.h b/point/include/projection_gk.h index 63aa54b4c5..a1bcb2d507 100644 --- a/point/include/projection_gk.h +++ b/point/include/projection_gk.h @@ -1,7 +1,4 @@ /***************************************************************************** - * - * projection_gk.h - * Implementation of the Gauss Krueger projection that is used in Secondo * * This MobilityDB code is provided under The PostgreSQL License. * @@ -27,6 +24,11 @@ * *****************************************************************************/ +/** + * @file projection_gk.h + * Implementation of the Gauss-Krueger projection that is used in Secondo + */ + #ifndef __PROJECTION_GK_H__ #define __PROJECTION_GK_H__ diff --git a/point/include/stbox.h b/point/include/stbox.h index 0557ea25f5..cc924957ee 100644 --- a/point/include/stbox.h +++ b/point/include/stbox.h @@ -1,7 +1,4 @@ /***************************************************************************** - * - * stbox.h - * Functions for spatiotemporal bounding boxes. * * This MobilityDB code is provided under The PostgreSQL License. * @@ -27,6 +24,11 @@ * *****************************************************************************/ +/** + * @file stbox.h + * Functions for spatiotemporal bounding boxes. + */ + #ifndef __STBOX_H__ #define __STBOX_H__ diff --git a/point/include/tpoint.h b/point/include/tpoint.h index dbd2d8d366..74b1bbb9c2 100644 --- a/point/include/tpoint.h +++ b/point/include/tpoint.h @@ -1,7 +1,4 @@ /***************************************************************************** - * - * tpoint.h - * Functions for temporal points. * * This MobilityDB code is provided under The PostgreSQL License. * @@ -27,6 +24,11 @@ * *****************************************************************************/ +/** + * @file tpoint.h + * Functions for temporal points. + */ + #ifndef __TPOINT_H__ #define __TPOINT_H__ diff --git a/point/include/tpoint_aggfuncs.h b/point/include/tpoint_aggfuncs.h index 14ecb3765e..4141315641 100644 --- a/point/include/tpoint_aggfuncs.h +++ b/point/include/tpoint_aggfuncs.h @@ -1,7 +1,4 @@ /***************************************************************************** - * - * tpoint_aggfuncs.h - * Aggregate functions for temporal points. * * This MobilityDB code is provided under The PostgreSQL License. * @@ -27,6 +24,11 @@ * *****************************************************************************/ +/** + * @file tpoint_aggfuncs.h + * Aggregate functions for temporal points. + */ + #ifndef __TPOINT_AGGFUNCS_H__ #define __TPOINT_AGGFUNCS_H__ diff --git a/point/include/tpoint_analytics.h b/point/include/tpoint_analytics.h index 9a37e291ab..e4709b152e 100644 --- a/point/include/tpoint_analytics.h +++ b/point/include/tpoint_analytics.h @@ -1,7 +1,4 @@ /***************************************************************************** - * - * tpoint_analytics.h - * Analytics functions for temporal points. * * This MobilityDB code is provided under The PostgreSQL License. * @@ -27,6 +24,11 @@ * *****************************************************************************/ +/** + * @file tpoint_analytics.h + * Analytics functions for temporal points. + */ + #ifndef __TPOINT_ANALYTICS_H__ #define __TPOINT_ANALYTICS_H__ diff --git a/point/include/tpoint_analyze.h b/point/include/tpoint_analyze.h index aab93ef33a..b5102d075a 100644 --- a/point/include/tpoint_analyze.h +++ b/point/include/tpoint_analyze.h @@ -1,7 +1,4 @@ /***************************************************************************** - * - * tpoint_analyze.h - * Functions for gathering statistics from temporal point columns * * This MobilityDB code is provided under The PostgreSQL License. * @@ -27,6 +24,11 @@ * *****************************************************************************/ +/** + * @file tpoint_analyze.h + * Functions for gathering statistics from temporal point columns + */ + #ifndef __TPOINT_ANALYZE_H__ #define __TPOINT_ANALYZE_H__ diff --git a/point/include/tpoint_boxops.h b/point/include/tpoint_boxops.h index 627bfd977c..eec076722e 100644 --- a/point/include/tpoint_boxops.h +++ b/point/include/tpoint_boxops.h @@ -1,7 +1,4 @@ /***************************************************************************** - * - * tpoint_boxops.h - * Bounding box operators for temporal points. * * This MobilityDB code is provided under The PostgreSQL License. * @@ -27,6 +24,11 @@ * *****************************************************************************/ +/** + * @file tpoint_boxops.h + * Bounding box operators for temporal points. + */ + #ifndef __TPOINT_BOXOPS_H__ #define __TPOINT_BOXOPS_H__ diff --git a/point/include/tpoint_datagen.h b/point/include/tpoint_datagen.h index 56baf846a9..03415049c4 100644 --- a/point/include/tpoint_datagen.h +++ b/point/include/tpoint_datagen.h @@ -1,7 +1,4 @@ /***************************************************************************** - * - * tpoint_datagen.h - * Data generator for MobilityDB. * * This MobilityDB code is provided under The PostgreSQL License. * @@ -27,6 +24,11 @@ * *****************************************************************************/ +/** + * @file tpoint_datagen.h + * Data generator for MobilityDB. + */ + #ifndef __TPOINT_DATAGEN_H__ #define __TPOINT_DATAGEN_H__ diff --git a/point/include/tpoint_distance.h b/point/include/tpoint_distance.h index b77d535757..61a2c4bb70 100644 --- a/point/include/tpoint_distance.h +++ b/point/include/tpoint_distance.h @@ -1,7 +1,4 @@ /***************************************************************************** - * - * tpoint_distance.h - * Distance functions for temporal points. * * This MobilityDB code is provided under The PostgreSQL License. * @@ -27,6 +24,11 @@ * *****************************************************************************/ +/** + * @file tpoint_distance.h + * Distance functions for temporal points. + */ + #ifndef __TPOINT_DISTANCE_H__ #define __TPOINT_DISTANCE_H__ diff --git a/point/include/tpoint_gist.h b/point/include/tpoint_gist.h index 9dbf2a3908..8971beb07b 100644 --- a/point/include/tpoint_gist.h +++ b/point/include/tpoint_gist.h @@ -1,7 +1,4 @@ /***************************************************************************** - * - * tpoint_gist.c - * R-tree GiST index for temporal points. * * This MobilityDB code is provided under The PostgreSQL License. * @@ -27,6 +24,11 @@ * *****************************************************************************/ +/** + * @file tpoint_gist.c + * R-tree GiST index for temporal points. + */ + #ifndef __TPOINT_GIST_H__ #define __TPOINT_GIST_H__ diff --git a/point/include/tpoint_in.h b/point/include/tpoint_in.h index 25e19e4b0e..ad3fc5f31e 100644 --- a/point/include/tpoint_in.h +++ b/point/include/tpoint_in.h @@ -1,7 +1,4 @@ /***************************************************************************** - * - * tpoint_in.h - * Input of temporal points in WKT, EWKT and MF-JSON format * * This MobilityDB code is provided under The PostgreSQL License. * @@ -27,6 +24,11 @@ * *****************************************************************************/ +/** + * @file tpoint_in.h + * Input of temporal points in WKT, EWKT and MF-JSON format + */ + #ifndef __TPOINT_IN_H__ #define __TPOINT_IN_H__ diff --git a/point/include/tpoint_out.h b/point/include/tpoint_out.h index 79357a2bd9..5c07ccafed 100644 --- a/point/include/tpoint_out.h +++ b/point/include/tpoint_out.h @@ -1,7 +1,4 @@ /***************************************************************************** - * - * tpoint_out.h - * Output of temporal points in WKT, EWKT and MF-JSON format * * This MobilityDB code is provided under The PostgreSQL License. * @@ -27,6 +24,11 @@ * *****************************************************************************/ +/** + * @file tpoint_out.h + * Output of temporal points in WKT, EWKT and MF-JSON format + */ + #ifndef __TPOINT_OUT_H__ #define __TPOINT_OUT_H__ diff --git a/point/include/tpoint_posops.h b/point/include/tpoint_posops.h index 8bc7dc31c2..b7a0788042 100644 --- a/point/include/tpoint_posops.h +++ b/point/include/tpoint_posops.h @@ -1,7 +1,4 @@ /***************************************************************************** - * - * tpoint_posops.h - * Relative position operators for temporal geometry points. * * This MobilityDB code is provided under The PostgreSQL License. * @@ -27,6 +24,11 @@ * *****************************************************************************/ +/** + * @file tpoint_posops.h + * Relative position operators for temporal geometry points. + */ + #ifndef __TPOINT_POSOPS_H__ #define __TPOINT_POSOPS_H__ diff --git a/point/include/tpoint_selfuncs.h b/point/include/tpoint_selfuncs.h index c91ad1bf3a..7b9cd2c657 100644 --- a/point/include/tpoint_selfuncs.h +++ b/point/include/tpoint_selfuncs.h @@ -1,7 +1,4 @@ /***************************************************************************** - * - * tpoint_selfuncs.h - * Selectivity functions for the temporal point types. * * This MobilityDB code is provided under The PostgreSQL License. * @@ -29,9 +26,9 @@ /** * @file tpoint_selfuncs.c - * Selectivity functions for the temporal point types. + * Selectivity functions for temporal point types. * - * Most definitions in this file come from PostGIS file + * Most definitions in this file come from the PostGIS file * `gserialized_estimate.c` */ diff --git a/point/include/tpoint_spatialfuncs.h b/point/include/tpoint_spatialfuncs.h index 20f7f57305..d567e368aa 100644 --- a/point/include/tpoint_spatialfuncs.h +++ b/point/include/tpoint_spatialfuncs.h @@ -1,7 +1,4 @@ /***************************************************************************** - * - * tpoint_spatialfuncs.h - * Spatial functions for temporal points. * * This MobilityDB code is provided under The PostgreSQL License. * @@ -27,6 +24,11 @@ * *****************************************************************************/ +/** + * @file tpoint_spatialfuncs.h + * Spatial functions for temporal points. + */ + #ifndef __TPOINT_SPATIALFUNCS_H__ #define __TPOINT_SPATIALFUNCS_H__ diff --git a/point/include/tpoint_spatialrels.h b/point/include/tpoint_spatialrels.h index cc98a9466e..ec02503858 100644 --- a/point/include/tpoint_spatialrels.h +++ b/point/include/tpoint_spatialrels.h @@ -1,7 +1,4 @@ /***************************************************************************** - * - * tpoint_spatialrels.h - * Spatial relationships for temporal points. * * This MobilityDB code is provided under The PostgreSQL License. * @@ -27,6 +24,11 @@ * *****************************************************************************/ +/** + * @file tpoint_spatialrels.h + * Spatial relationships for temporal points. + */ + #ifndef __TPOINT_SPATIALRELS_H__ #define __TPOINT_SPATIALRELS_H__ diff --git a/point/include/tpoint_spgist.h b/point/include/tpoint_spgist.h index f0415c2ba8..8acb10fe78 100644 --- a/point/include/tpoint_spgist.h +++ b/point/include/tpoint_spgist.h @@ -1,7 +1,4 @@ /***************************************************************************** - * - * tpoint_spgist.h - * SP-GiST implementation of 8-dimensional oct-tree over temporal points * * This MobilityDB code is provided under The PostgreSQL License. * @@ -27,6 +24,11 @@ * *****************************************************************************/ +/** + * @file tpoint_spgist.h + * SP-GiST implementation of 8-dimensional oct-tree over temporal points + */ + #ifndef __TPOINT_SPGIST_H__ #define __TPOINT_SPGIST_H__ diff --git a/point/include/tpoint_tempspatialrels.h b/point/include/tpoint_tempspatialrels.h index 9d684ebfde..c8a9ac14d7 100644 --- a/point/include/tpoint_tempspatialrels.h +++ b/point/include/tpoint_tempspatialrels.h @@ -1,7 +1,4 @@ /***************************************************************************** - * - * tpoint_tempspatialrels.h - * Temporal spatial relationships for temporal points. * * This MobilityDB code is provided under The PostgreSQL License. * @@ -27,6 +24,11 @@ * *****************************************************************************/ +/** + * @file tpoint_tempspatialrels.h + * Temporal spatial relationships for temporal points. + */ + #ifndef __TPOINT_TEMPSPATIALRELS_H__ #define __TPOINT_TEMPSPATIALRELS_H__ diff --git a/point/src/geography_functions.c b/point/src/geography_functions.c index 83c7de91fc..ba3b025a9a 100644 --- a/point/src/geography_functions.c +++ b/point/src/geography_functions.c @@ -1,7 +1,4 @@ /***************************************************************************** - * - * geography_functions.c - * Spatial functions for PostGIS geography. * * This MobilityDB code is provided under The PostgreSQL License. * @@ -26,6 +23,7 @@ * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.  * *****************************************************************************/ + /** * @file geography_functions.c * Spatial functions for PostGIS geography. diff --git a/point/src/projection_gk.c b/point/src/projection_gk.c index 261c3f4755..5ce374bb0c 100644 --- a/point/src/projection_gk.c +++ b/point/src/projection_gk.c @@ -1,7 +1,4 @@ /***************************************************************************** - * - * projection_gk.c - * Implementation of the Gauss Krueger projection that is used in Secondo * * This MobilityDB code is provided under The PostgreSQL License. * @@ -26,9 +23,10 @@ * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.  * *****************************************************************************/ + /** * @file projection_gk.c - * Implementation of the Gauss Krueger projection that is used in Secondo + * Implementation of the Gauss-Krueger projection that is used in Secondo * * This projection does not correspond to any standard projection in * http://www.epsg.org/. This projection is provided to enable the comparison diff --git a/point/src/sql/51_tpoint.in.sql b/point/src/sql/51_tpoint.in.sql index 5a4a370e00..f27b99e574 100644 --- a/point/src/sql/51_tpoint.in.sql +++ b/point/src/sql/51_tpoint.in.sql @@ -398,6 +398,15 @@ CREATE FUNCTION timespan(tgeogpoint) AS 'MODULE_PATHNAME', 'temporal_timespan' LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE; +CREATE FUNCTION duration(tgeompoint) + RETURNS interval + AS 'MODULE_PATHNAME', 'temporal_duration' + LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE; +CREATE FUNCTION duration(tgeogpoint) + RETURNS interval + AS 'MODULE_PATHNAME', 'temporal_duration' + LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE; + CREATE FUNCTION numInstants(tgeompoint) RETURNS integer AS 'MODULE_PATHNAME', 'temporal_num_instants' diff --git a/point/src/stbox.c b/point/src/stbox.c index d622f98735..41382142b2 100644 --- a/point/src/stbox.c +++ b/point/src/stbox.c @@ -1,7 +1,4 @@ /***************************************************************************** - * - * stbox.c - * Functions for spatiotemporal bounding boxes. * * This MobilityDB code is provided under The PostgreSQL License. * @@ -27,6 +24,11 @@ * *****************************************************************************/ +/** + * @file stbox.c + * Functions for spatiotemporal bounding boxes. + */ + #include "stbox.h" #include diff --git a/point/src/tpoint.c b/point/src/tpoint.c index 443c7810fd..638473969d 100644 --- a/point/src/tpoint.c +++ b/point/src/tpoint.c @@ -1,7 +1,4 @@ /***************************************************************************** - * - * tpoint.c - * Basic functions for temporal points. * * This MobilityDB code is provided under The PostgreSQL License. * @@ -27,6 +24,11 @@ * *****************************************************************************/ +/** + * @file tpoint.c + * Basic functions for temporal points. + */ + #include "tpoint.h" #include diff --git a/point/src/tpoint_aggfuncs.c b/point/src/tpoint_aggfuncs.c index c3ab58a6a9..509906c1d7 100644 --- a/point/src/tpoint_aggfuncs.c +++ b/point/src/tpoint_aggfuncs.c @@ -1,7 +1,4 @@ /***************************************************************************** - * - * tpoint_aggfuncs.c - * Aggregate functions for temporal points. * * Copyright (c) 2020, Université libre de Bruxelles and MobilityDB * contributors @@ -24,6 +21,7 @@ * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.  * *****************************************************************************/ + /** * @file tpoint_aggfuncs.c * Aggregate functions for temporal points. @@ -420,7 +418,7 @@ tpointinst_tcentroid_finalfn(TInstant **instants, int count, int srid) newinstants[i] = tinstant_make(value, inst->t, type_oid(T_GEOMETRY)); pfree(DatumGetPointer(value)); } - return tinstantset_make_free(newinstants, count); + return tinstantset_make_free(newinstants, count, MERGE_NO); } /** diff --git a/point/src/tpoint_analytics.c b/point/src/tpoint_analytics.c index 11c06c5d94..4e0d5e784d 100644 --- a/point/src/tpoint_analytics.c +++ b/point/src/tpoint_analytics.c @@ -1,7 +1,4 @@ /*********************************************************************** - * - * tpoint_analytics.c - * Analytic functions for temporal points and temporal floats. * * This MobilityDB code is provided under The PostgreSQL License. * @@ -27,6 +24,11 @@ * *****************************************************************************/ +/** + * @file tpoint_analytics.c + * Analytic functions for temporal points and temporal floats. + */ + #include "tpoint_analytics.h" #include @@ -468,7 +470,7 @@ geo_to_tpointinstset(GSERIALIZED *gs) instants[i] = trajpoint_to_tpointinst((LWPOINT *)lwcoll->geoms[i]); lwgeom_free(lwgeom); - return tinstantset_make_free(instants, npoints); + return tinstantset_make_free(instants, npoints, MERGE_NO); } /** diff --git a/point/src/tpoint_analyze.c b/point/src/tpoint_analyze.c index c7f6d2475d..42f776b5fb 100644 --- a/point/src/tpoint_analyze.c +++ b/point/src/tpoint_analyze.c @@ -1,7 +1,4 @@ /***************************************************************************** - * - * tpoint_analyze.c - * Functions for gathering statistics from temporal point columns * * This MobilityDB code is provided under The PostgreSQL License. * diff --git a/point/src/tpoint_boxops.c b/point/src/tpoint_boxops.c index 142dac4f4c..6e6a1ed633 100644 --- a/point/src/tpoint_boxops.c +++ b/point/src/tpoint_boxops.c @@ -1,7 +1,4 @@ /***************************************************************************** - * - * tpoint_boxops.c - * Bounding box operators for temporal points. * * This MobilityDB code is provided under The PostgreSQL License. * @@ -29,7 +26,7 @@ /** * @file tpoint_boxops.c - * Bounding box operators for temporal points. + * Bounding box operators for temporal points. * * These operators test the bounding boxes of temporal points, which are an * `STBOX`, where the *x*, *y*, and optional *z* coordinates are for the space diff --git a/point/src/tpoint_datagen.c b/point/src/tpoint_datagen.c index 5beac4551a..45bb10b168 100644 --- a/point/src/tpoint_datagen.c +++ b/point/src/tpoint_datagen.c @@ -1,7 +1,4 @@ /***************************************************************************** - * - * tpoint_datagen.c - * Data generator for MobilityDB. * * This MobilityDB code is provided under The PostgreSQL License. * @@ -27,6 +24,14 @@ * *****************************************************************************/ +/** + * @file tpoint_datagen.c + * Data generator for MobilityDB. + * + * These functions are used in particular for the BerlinMOD data generator + * https://github.com/MobilityDB/MobilityDB-BerlinMOD + */ + #include "tpoint_datagen.h" #include diff --git a/point/src/tpoint_distance.c b/point/src/tpoint_distance.c index 0e7f52bb4a..85dc0c91a5 100644 --- a/point/src/tpoint_distance.c +++ b/point/src/tpoint_distance.c @@ -1,7 +1,4 @@ /*********************************************************************** - * - * tpoint_distance.c - * Distance functions for temporal points. * * This MobilityDB code is provided under The PostgreSQL License. * @@ -27,6 +24,11 @@ * *****************************************************************************/ +/** + * @file tpoint_distance.c + * Distance functions for temporal points. + */ + #include "tpoint_distance.h" #include diff --git a/point/src/tpoint_gist.c b/point/src/tpoint_gist.c index b8b2cd00e4..6bba2ed47b 100644 --- a/point/src/tpoint_gist.c +++ b/point/src/tpoint_gist.c @@ -1,7 +1,4 @@ /***************************************************************************** - * - * tpoint_gist.c - * R-tree GiST index for temporal points. * * This MobilityDB code is provided under The PostgreSQL License. * @@ -27,6 +24,11 @@ * *****************************************************************************/ +/** + * @file tpoint_gist.c + * R-tree GiST index for temporal points. + */ + #include "tpoint_gist.h" #include diff --git a/point/src/tpoint_in.c b/point/src/tpoint_in.c index 44de8816e9..e066e80cfa 100644 --- a/point/src/tpoint_in.c +++ b/point/src/tpoint_in.c @@ -1,7 +1,4 @@ /***************************************************************************** - * - * tpoint_in.c - * Input of temporal points in WKT, EWKT and MF-JSON format * * This MobilityDB code is provided under The PostgreSQL License. * @@ -27,6 +24,11 @@ * *****************************************************************************/ +/** + * @file tpoint_in.c + * Input of temporal points in WKT, EWKT and MF-JSON format + */ + #include "tpoint_in.h" #include @@ -294,7 +296,7 @@ tpointinstset_from_mfjson(json_object *mfjson, int srid) { int count; TInstant **instants = tpointinstarr_from_mfjson(mfjson, srid, &count); - return tinstantset_make_free(instants, count); + return tinstantset_make_free(instants, count, MERGE_NO); } /** @@ -727,7 +729,7 @@ tpointinstset_from_wkb_state(wkb_parse_state *s) wkb_parse_state_check(s, size); /* Parse the instants */ TInstant **instants = tpointinstarr_from_wkb_state(s, count); - return tinstantset_make_free(instants, count); + return tinstantset_make_free(instants, count, MERGE_NO); } /** diff --git a/point/src/tpoint_out.c b/point/src/tpoint_out.c index 5aa256f340..817bcbd2b7 100644 --- a/point/src/tpoint_out.c +++ b/point/src/tpoint_out.c @@ -1,7 +1,4 @@ /***************************************************************************** - * - * tpoint_out.c - * Output of temporal points in WKT, EWKT, WKB, EWKB, and MF-JSON format * * This MobilityDB code is provided under The PostgreSQL License. * @@ -27,6 +24,11 @@ * *****************************************************************************/ +/** + * @file tpoint_out.c + * Output of temporal points in WKT, EWKT, WKB, EWKB, and MF-JSON format + */ + #include "tpoint_out.h" #include diff --git a/point/src/tpoint_parser.c b/point/src/tpoint_parser.c index 0bacf043ad..1ecbdafbe7 100644 --- a/point/src/tpoint_parser.c +++ b/point/src/tpoint_parser.c @@ -1,7 +1,4 @@ /***************************************************************************** - * - * tpoint_parser.c - * Functions for parsing temporal points. * * This MobilityDB code is provided under The PostgreSQL License. * @@ -27,6 +24,11 @@ * *****************************************************************************/ +/** + * @file tpoint_parser.c + * Functions for parsing temporal points. + */ + #include "tpoint_parser.h" #include "temporaltypes.h" @@ -292,7 +294,7 @@ tpointinstset_parse(char **str, Oid basetype, int *tpoint_srid) instants[i] = tpointinst_parse(str, basetype, false, true, tpoint_srid); } p_cbrace(str); - return tinstantset_make_free(instants, count); + return tinstantset_make_free(instants, count, MERGE_NO); } /** diff --git a/point/src/tpoint_posops.c b/point/src/tpoint_posops.c index bab4e74227..86eb645259 100644 --- a/point/src/tpoint_posops.c +++ b/point/src/tpoint_posops.c @@ -1,7 +1,4 @@ /***************************************************************************** - * - * tpoint_posops.c - * Relative position operators for temporal geometry points. * * This MobilityDB code is provided under The PostgreSQL License. * @@ -26,6 +23,7 @@ * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.  * *****************************************************************************/ + /** * @file tpoint_posops.c * Relative position operators for temporal geometry points. @@ -39,7 +37,8 @@ * The following operators are defined for for the time dimension: `before`, * `overbefore`, `after`, `overafter`. For both temporal geometry and * geography points the same operators are derived from the basic temporal - * types. In this file they are defined when one of the arguments is a stbox. + * types. In this file they are defined when one of the arguments is an + * `STBOX`. */ #include "tpoint_posops.h" diff --git a/point/src/tpoint_selfuncs.c b/point/src/tpoint_selfuncs.c index a8040ab6d3..659c9ec28f 100644 --- a/point/src/tpoint_selfuncs.c +++ b/point/src/tpoint_selfuncs.c @@ -1,7 +1,4 @@ /***************************************************************************** - * - * tpoint_selfuncs.c - * Functions for selectivity estimation of operators on temporal points * * This MobilityDB code is provided under The PostgreSQL License. * @@ -27,6 +24,11 @@ * *****************************************************************************/ +/** + * @file tpoint_selfuncs.c + * Functions for selectivity estimation of operators on temporal points + */ + #include "tpoint_selfuncs.h" #include diff --git a/point/src/tpoint_spatialfuncs.c b/point/src/tpoint_spatialfuncs.c index a93711a255..17e164bc7f 100644 --- a/point/src/tpoint_spatialfuncs.c +++ b/point/src/tpoint_spatialfuncs.c @@ -1,7 +1,4 @@ /*********************************************************************** - * - * tpoint_spatialfuncs.c - * Spatial functions for temporal points. * * This MobilityDB code is provided under The PostgreSQL License. * @@ -27,6 +24,11 @@ * *****************************************************************************/ +/** + * @file tpoint_spatialfuncs.c + * Spatial functions for temporal points. + */ + #include "tpoint_spatialfuncs.h" #include @@ -1617,7 +1619,7 @@ tpointinstset_transform(const TInstantSet *ti, Datum srid) if (ti->count == 1) { inst = tpointinst_transform(tinstantset_inst_n(ti, 0), srid); - TInstantSet *result = tinstantset_make(&inst, 1); + TInstantSet *result = tinstantset_make(&inst, 1, MERGE_NO); pfree(inst); return result; } @@ -1649,7 +1651,7 @@ tpointinstset_transform(const TInstantSet *ti, Datum srid) POSTGIS_FREE_IF_COPY_P(gs, DatumGetPointer(gs)); lwmpoint_free(lwmpoint); - return tinstantset_make_free(instants, ti->count); + return tinstantset_make_free(instants, ti->count, MERGE_NO); } /** @@ -1855,7 +1857,7 @@ tpointinstset_convert_tgeom_tgeog(const TInstantSet *ti, bool oper) pfree(DatumGetPointer(point)); } lwmpoint_free(lwmpoint); - return tinstantset_make_free(instants, ti->count); + return tinstantset_make_free(instants, ti->count, MERGE_NO); } /** @@ -2102,7 +2104,7 @@ tpointinstset_cumulative_length(const TInstantSet *ti) TInstant *inst = tinstantset_inst_n(ti, i); instants[i] = tinstant_make(length, inst->t, FLOAT8OID); } - return tinstantset_make_free(instants, ti->count); + return tinstantset_make_free(instants, ti->count, MERGE_NO); } /** @@ -2356,11 +2358,11 @@ tgeompointi_twcentroid(const TInstantSet *ti) instantsz[i] = tinstant_make(Float8GetDatum(point.z), inst->t, FLOAT8OID); } - TInstantSet *tix = tinstantset_make_free(instantsx, ti->count); - TInstantSet *tiy = tinstantset_make_free(instantsy, ti->count); + TInstantSet *tix = tinstantset_make_free(instantsx, ti->count, MERGE_NO); + TInstantSet *tiy = tinstantset_make_free(instantsy, ti->count, MERGE_NO); TInstantSet *tiz = NULL; /* keep compiler quiet */ if (hasz) - tiz = tinstantset_make_free(instantsz, ti->count); + tiz = tinstantset_make_free(instantsz, ti->count, MERGE_NO); double avgx = tnumberinstset_twavg(tix); double avgy = tnumberinstset_twavg(tiy); double avgz; @@ -2857,7 +2859,7 @@ tgeompointseq_find_intersections(const TSequence *seq, int *count) /** * Determine whether a temporal point is self-intersecting * - * @param[in] seq Temporal point + * @param[in] ti Temporal point */ static int tgeompointi_is_simple(const TInstantSet *ti) @@ -3033,12 +3035,12 @@ tgeompointi_make_simple1(TInstantSet **result, const TInstantSet *ti) } else { - result[count++] = tinstantset_make(instants, k); + result[count++] = tinstantset_make(instants, k, MERGE_NO); points[0] = p3dz; k = 1; } } - result[count++] = tinstantset_make(instants, k); + result[count++] = tinstantset_make(instants, k, MERGE_NO); pfree(points); return count; } @@ -3236,7 +3238,7 @@ tpointinstset_restrict_geometry(const TInstantSet *ti, Datum geom, bool atfunc) } TInstantSet *result = NULL; if (k != 0) - result = tinstantset_make(instants, k); + result = tinstantset_make(instants, k, MERGE_NO); /* We cannot pfree the instants in the array */ pfree(instants); return result; @@ -3246,7 +3248,7 @@ tpointinstset_restrict_geometry(const TInstantSet *ti, Datum geom, bool atfunc) * Restricts the temporal sequence point with step interpolation to the geometry * * @param[in] seq Temporal point - * @param[in] geom Geometry + * @param[in] gsinter Intersection of the temporal point and the geometry * @param[out] count Number of elements in the resulting array * @pre The temporal point is simple (that is, not self-intersecting) */ @@ -3303,7 +3305,8 @@ tpointseq_step_at_geometry(const TSequence *seq, GSERIALIZED *gsinter, int *coun * Restricts the temporal sequence point with linear interpolation to the geometry * * @param[in] seq Temporal point - * @param[in] geom Geometry + * @param[in] traj Trajectory of the temporal point + * @param[in] gsinter Intersection of the temporal point and the geometry * @param[out] count Number of elements in the resulting array * @pre The temporal point is simple (that is, not self-intersecting) */ diff --git a/point/src/tpoint_spatialrels.c b/point/src/tpoint_spatialrels.c index 598df262a2..0c2da10253 100644 --- a/point/src/tpoint_spatialrels.c +++ b/point/src/tpoint_spatialrels.c @@ -1,7 +1,4 @@ /***************************************************************************** - * - * tpoint_spatialrels.c - * Spatial relationships for temporal points. * * This MobilityDB code is provided under The PostgreSQL License. * @@ -29,6 +26,8 @@ /** * @file tpoint_spatialrels.c + * Spatial relationships for temporal points. + * * These relationships project the time dimension and return a Boolean. * They are thus defined with the "at any instant" semantics, that is, the * traditional spatial function is applied to the union of all values taken diff --git a/point/src/tpoint_spgist.c b/point/src/tpoint_spgist.c index 73ad056332..645f6a285f 100644 --- a/point/src/tpoint_spgist.c +++ b/point/src/tpoint_spgist.c @@ -1,7 +1,4 @@ /***************************************************************************** - * - * tpoint_spgist.c - * SP-GiST implementation of 8-dimensional oct-tree over temporal points * * This MobilityDB code is provided under The PostgreSQL License. * @@ -29,7 +26,9 @@ /** * @file tnumber_spgist.c - * This module provides SP-GiST implementation for boxes using oct tree + * SP-GiST implementation of 8-dimensional oct-tree over temporal points + * + * This module provides SP-GiST implementation for boxes using an oct-tree * analogy in 8-dimensional space. SP-GiST doesn't allow indexing of * overlapping objects. We are making 4D objects never-overlapping in * 8D space. This technique has some benefits compared to traditional diff --git a/point/src/tpoint_tempspatialrels.c b/point/src/tpoint_tempspatialrels.c index bc210c656d..79bdbd2252 100644 --- a/point/src/tpoint_tempspatialrels.c +++ b/point/src/tpoint_tempspatialrels.c @@ -1,7 +1,4 @@ /***************************************************************************** - * - * tpoint_tempspatialrels.c - * Temporal spatial relationships for temporal points. * * This MobilityDB code is provided under The PostgreSQL License. * diff --git a/point/test/expected/50_stbox.test.out b/point/test/expected/50_stbox.test.out index eed5b0ca86..b410fedf24 100644 --- a/point/test/expected/50_stbox.test.out +++ b/point/test/expected/50_stbox.test.out @@ -86,11 +86,11 @@ ERROR: Could not parse STBOX: Missing opening parenthesis LINE 1: SELECT stbox 'stbox(1, 2, 3)'; ^ SELECT stbox 'stbox((AA, 2, 3))'; -ERROR: Could not parse STBOX: Invalid input syntax for type double +ERROR: Invalid input syntax for type double LINE 1: SELECT stbox 'stbox((AA, 2, 3))'; ^ SELECT stbox 'stbox((1, AA, 3))'; -ERROR: Could not parse STBOX: Invalid input syntax for type double +ERROR: Invalid input syntax for type double LINE 1: SELECT stbox 'stbox((1, AA, 3))'; ^ SELECT stbox 'stbox((,),(,))'; @@ -98,7 +98,7 @@ ERROR: Could not parse STBOX LINE 1: SELECT stbox 'stbox((,),(,))'; ^ SELECT stbox 'stbox z((1, 2, AA))'; -ERROR: Could not parse STBOX: Invalid input syntax for type double +ERROR: Invalid input syntax for type double LINE 1: SELECT stbox 'stbox z((1, 2, AA))'; ^ SELECT stbox 'stbox t((1, 2, AA))'; @@ -114,15 +114,15 @@ ERROR: Could not parse STBOX: Missing opening parenthesis LINE 1: SELECT stbox 'stbox t((1, 2, 2001-01-03))'; ^ SELECT stbox 'stbox t((1, 2, 2001-01-03),()'; -ERROR: Could not parse STBOX: Invalid input syntax for type double +ERROR: Invalid input syntax for type double LINE 1: SELECT stbox 'stbox t((1, 2, 2001-01-03),()'; ^ SELECT stbox 'stbox t((1, 2, 2001-01-03),(1)'; -ERROR: Could not parse STBOX: Invalid input syntax for type double +ERROR: Invalid input syntax for type double LINE 1: SELECT stbox 'stbox t((1, 2, 2001-01-03),(1)'; ^ SELECT stbox 'stbox z((1, 2, 3),(1,2)'; -ERROR: Could not parse STBOX: Invalid input syntax for type double +ERROR: Invalid input syntax for type double LINE 1: SELECT stbox 'stbox z((1, 2, 3),(1,2)'; ^ SELECT stbox 'stbox t((1, 2, 2001-01-03),(1,2)'; @@ -326,7 +326,7 @@ SELECT (geometry 'Polygon((1 1 1,1 2 2,2 2 2,2 1 1,1 1 1))'::box3d)::stbox; STBOX Z((1,1,1),(2,2,2)) (1 row) -SELECT MAX(timespan(b::period)) FROM tbl_stbox; +SELECT MAX(duration(b::period)) FROM tbl_stbox; max ---------- 00:10:00 diff --git a/point/test/expected/51_tpoint.test.out b/point/test/expected/51_tpoint.test.out index b6c3a7c01b..61a2bf514c 100644 --- a/point/test/expected/51_tpoint.test.out +++ b/point/test/expected/51_tpoint.test.out @@ -1484,7 +1484,7 @@ ERROR: The temporal points must be of the same dimensionality SELECT asText(appendInstant(tgeompoint '{Point(1 1)@2000-01-01, Point(2 2)@2000-01-02}', tgeompoint 'SRID=5676;Point(3 3)@2000-01-03')); ERROR: The temporal points must be in the same SRID SELECT asText(appendInstant(tgeompoint '[Point(1 1)@2000-01-01, Point(2 2)@2000-01-02]', tgeompoint 'Point(3 3)@2000-01-02')); -ERROR: The temporal values have different value at their overlapping instant 2000-01-02 00:00:00+00 +ERROR: The temporal values have different value at their common instant 2000-01-02 00:00:00+00 SELECT asText(appendInstant(tgeompoint '[Point(1 1)@2000-01-01, Point(2 2)@2000-01-02]', tgeompoint 'Point(3 3 3)@2000-01-03')); ERROR: The temporal points must be of the same dimensionality SELECT asText(appendInstant(tgeompoint '[Point(1 1)@2000-01-01, Point(2 2)@2000-01-02]', tgeompoint 'SRID=5676;Point(3 3)@2000-01-03')); @@ -1613,19 +1613,19 @@ ERROR: The temporal points must be of the same dimensionality SELECT merge(tgeompoint '[Point(1 1)@2000-01-01, Point(2 2)@2000-01-02, Point(1 1)@2000-01-03]', tgeompoint '[Point(2 2)@2000-01-02, Point(2 2)@2000-01-03, Point(1 1)@2000-01-04]'); ERROR: The temporal values cannot overlap on time: 2000-01-03 00:00:00+00, 2000-01-02 00:00:00+00 SELECT merge(tgeompoint '[Point(1 1)@2000-01-01, Point(2 2)@2000-01-02, Point(1 1)@2000-01-03]', tgeompoint '[Point(2 2)@2000-01-03, Point(2 2)@2000-01-04, Point(1 1)@2000-01-05]'); -ERROR: The temporal values have different value at their overlapping instant 2000-01-03 00:00:00+00 +ERROR: The temporal values have different value at their common instant 2000-01-03 00:00:00+00 SELECT merge(tgeompoint 'SRID=5676;[Point(1 1)@2000-01-01, Point(2 2)@2000-01-02, Point(1 1)@2000-01-03]', tgeompoint '[Point(1 1)@2000-01-03, Point(2 2)@2000-01-04, Point(1 1)@2000-01-05]'); -ERROR: The temporal values have different value at their overlapping instant 2000-01-03 00:00:00+00 +ERROR: The temporal values have different value at their common instant 2000-01-03 00:00:00+00 SELECT merge(tgeompoint '[Point(1 1)@2000-01-01, Point(2 2)@2000-01-02, Point(1 1)@2000-01-03]', tgeompoint '[Point(1 1 1)@2000-01-03, Point(2 2 2)@2000-01-04, Point(1 1 1)@2000-01-05]'); -ERROR: The temporal values have different value at their overlapping instant 2000-01-03 00:00:00+00 +ERROR: The temporal values have different value at their common instant 2000-01-03 00:00:00+00 SELECT merge(tgeompoint '{[Point(1 1)@2000-01-01, Point(2 2)@2000-01-02, Point(1 1)@2000-01-03],[Point(1 1)@2000-01-04, Point(1 1)@2000-01-05]}', tgeompoint '{[Point(2 2)@2000-01-04, Point(2 2)@2000-01-05, Point(1 1)@2000-01-06],[Point(1 1)@2000-01-08, Point(1 1)@2000-01-09]}'); ERROR: The temporal values cannot overlap on time: 2000-01-05 00:00:00+00, 2000-01-04 00:00:00+00 SELECT merge(tgeompoint '{[Point(1 1)@2000-01-01, Point(2 2)@2000-01-02, Point(1 1)@2000-01-03],[Point(1 1)@2000-01-04, Point(1 1)@2000-01-05]}', tgeompoint '{[Point(2 2)@2000-01-05, Point(2 2)@2000-01-06, Point(1 1)@2000-01-07],[Point(1 1)@2000-01-08, Point(1 1)@2000-01-09]}'); -ERROR: The temporal values have different value at their overlapping instant 2000-01-05 00:00:00+00 +ERROR: The temporal values have different value at their common instant 2000-01-05 00:00:00+00 SELECT merge(tgeompoint 'SRID=5676;{[Point(1 1)@2000-01-01, Point(2 2)@2000-01-02, Point(1 1)@2000-01-03],[Point(1 1)@2000-01-04, Point(1 1)@2000-01-05]}', tgeompoint '{[Point(1 1)@2000-01-05, Point(1 1)@2000-01-06],[Point(1 1)@2000-01-08, Point(1 1)@2000-01-09]}'); -ERROR: The temporal values have different value at their overlapping instant 2000-01-05 00:00:00+00 +ERROR: The temporal values have different value at their common instant 2000-01-05 00:00:00+00 SELECT merge(tgeompoint '{[Point(1 1)@2000-01-01, Point(2 2)@2000-01-02, Point(1 1)@2000-01-03],[Point(1 1)@2000-01-04, Point(1 1)@2000-01-05]}', tgeompoint '{[Point(1 1 1)@2000-01-05, Point(1 1 1)@2000-01-06],[Point(1 1 1)@2000-01-08, Point(1 1 1)@2000-01-09]}'); -ERROR: The temporal values have different value at their overlapping instant 2000-01-05 00:00:00+00 +ERROR: The temporal values have different value at their common instant 2000-01-05 00:00:00+00 SELECT asText(merge(ARRAY[tgeompoint 'Point(1 1)@2000-01-01', 'Point(1 1)@2000-01-02'])); astext ------------------------------------------------------------------------ @@ -1703,19 +1703,19 @@ ERROR: The temporal points must be of the same dimensionality SELECT merge(ARRAY [tgeompoint '[Point(1 1)@2000-01-01, Point(2 2)@2000-01-02, Point(1 1)@2000-01-03]', '[Point(2 2)@2000-01-02, Point(2 2)@2000-01-03, Point(1 1)@2000-01-04]']); ERROR: The temporal values cannot overlap on time: 2000-01-03 00:00:00+00, 2000-01-02 00:00:00+00 SELECT merge(ARRAY [tgeompoint '[Point(1 1)@2000-01-01, Point(2 2)@2000-01-02, Point(1 1)@2000-01-03]', '[Point(2 2)@2000-01-03, Point(2 2)@2000-01-04, Point(1 1)@2000-01-05]']); -ERROR: The temporal values have different value at their overlapping instant 2000-01-03 00:00:00+00 +ERROR: The temporal values have different value at their common instant 2000-01-03 00:00:00+00 SELECT merge(ARRAY [tgeompoint 'SRID=5676;[Point(1 1)@2000-01-01, Point(2 2)@2000-01-02, Point(1 1)@2000-01-03]', '[Point(1 1)@2000-01-03, Point(2 2)@2000-01-04, Point(1 1)@2000-01-05]']); -ERROR: The temporal values have different value at their overlapping instant 2000-01-03 00:00:00+00 +ERROR: The temporal values have different value at their common instant 2000-01-03 00:00:00+00 SELECT merge(ARRAY [tgeompoint '[Point(1 1)@2000-01-01, Point(2 2)@2000-01-02, Point(1 1)@2000-01-03]', '[Point(1 1 1)@2000-01-03, Point(2 2 2)@2000-01-04, Point(1 1 1)@2000-01-05]']); -ERROR: The temporal values have different value at their overlapping instant 2000-01-03 00:00:00+00 +ERROR: The temporal values have different value at their common instant 2000-01-03 00:00:00+00 SELECT merge(ARRAY [tgeompoint '{[Point(1 1)@2000-01-01, Point(2 2)@2000-01-02, Point(1 1)@2000-01-03],[Point(1 1)@2000-01-04, Point(1 1)@2000-01-05]}', '{[Point(2 2)@2000-01-04, Point(2 2)@2000-01-05, Point(1 1)@2000-01-06],[Point(1 1)@2000-01-08, Point(1 1)@2000-01-09]}']); ERROR: The temporal values cannot overlap on time: 2000-01-05 00:00:00+00, 2000-01-04 00:00:00+00 SELECT merge(ARRAY [tgeompoint '{[Point(1 1)@2000-01-01, Point(2 2)@2000-01-02, Point(1 1)@2000-01-03],[Point(1 1)@2000-01-04, Point(1 1)@2000-01-05]}', '{[Point(2 2)@2000-01-05, Point(2 2)@2000-01-06, Point(1 1)@2000-01-07],[Point(1 1)@2000-01-08, Point(1 1)@2000-01-09]}']); -ERROR: The temporal values have different value at their overlapping instant 2000-01-05 00:00:00+00 +ERROR: The temporal values have different value at their common instant 2000-01-05 00:00:00+00 SELECT merge(ARRAY [tgeompoint 'SRID=5676;{[Point(1 1)@2000-01-01, Point(2 2)@2000-01-02, Point(1 1)@2000-01-03],[Point(1 1)@2000-01-04, Point(1 1)@2000-01-05]}', '{[Point(1 1)@2000-01-05, Point(1 1)@2000-01-06],[Point(1 1)@2000-01-08, Point(1 1)@2000-01-09]}']); -ERROR: The temporal values have different value at their overlapping instant 2000-01-05 00:00:00+00 +ERROR: The temporal values have different value at their common instant 2000-01-05 00:00:00+00 SELECT merge(ARRAY [tgeompoint '{[Point(1 1)@2000-01-01, Point(2 2)@2000-01-02, Point(1 1)@2000-01-03],[Point(1 1)@2000-01-04, Point(1 1)@2000-01-05]}', '{[Point(1 1 1)@2000-01-05, Point(1 1 1)@2000-01-06],[Point(1 1 1)@2000-01-08, Point(1 1 1)@2000-01-09]}']); -ERROR: The temporal values have different value at their overlapping instant 2000-01-05 00:00:00+00 +ERROR: The temporal values have different value at their common instant 2000-01-05 00:00:00+00 SELECT temporalType(tgeompoint 'Point(1 1)@2000-01-01'); temporaltype -------------- @@ -2135,7 +2135,7 @@ SELECT timespan(tgeompoint 'Point(1 1)@2000-01-01'); SELECT timespan(tgeompoint '{Point(1 1)@2000-01-01, Point(2 2)@2000-01-02, Point(1 1)@2000-01-03}'); timespan ---------- - 00:00:00 + 2 days (1 row) SELECT timespan(tgeompoint '[Point(1 1)@2000-01-01, Point(2 2)@2000-01-02, Point(1 1)@2000-01-03]'); @@ -2147,7 +2147,7 @@ SELECT timespan(tgeompoint '[Point(1 1)@2000-01-01, Point(2 2)@2000-01-02, Point SELECT timespan(tgeompoint '{[Point(1 1)@2000-01-01, Point(2 2)@2000-01-02, Point(1 1)@2000-01-03],[Point(3 3)@2000-01-04, Point(3 3)@2000-01-05]}'); timespan ---------- - 3 days + 4 days (1 row) SELECT timespan(tgeogpoint 'Point(1.5 1.5)@2000-01-01'); @@ -2159,7 +2159,7 @@ SELECT timespan(tgeogpoint 'Point(1.5 1.5)@2000-01-01'); SELECT timespan(tgeogpoint '{Point(1.5 1.5)@2000-01-01, Point(2.5 2.5)@2000-01-02, Point(1.5 1.5)@2000-01-03}'); timespan ---------- - 00:00:00 + 2 days (1 row) SELECT timespan(tgeogpoint '[Point(1.5 1.5)@2000-01-01, Point(2.5 2.5)@2000-01-02, Point(1.5 1.5)@2000-01-03]'); @@ -2170,6 +2170,54 @@ SELECT timespan(tgeogpoint '[Point(1.5 1.5)@2000-01-01, Point(2.5 2.5)@2000-01-0 SELECT timespan(tgeogpoint '{[Point(1.5 1.5)@2000-01-01, Point(2.5 2.5)@2000-01-02, Point(1.5 1.5)@2000-01-03],[Point(3.5 3.5)@2000-01-04, Point(3.5 3.5)@2000-01-05]}'); timespan +---------- + 4 days +(1 row) + +SELECT duration(tgeompoint 'Point(1 1)@2000-01-01'); + duration +---------- + 00:00:00 +(1 row) + +SELECT duration(tgeompoint '{Point(1 1)@2000-01-01, Point(2 2)@2000-01-02, Point(1 1)@2000-01-03}'); + duration +---------- + 00:00:00 +(1 row) + +SELECT duration(tgeompoint '[Point(1 1)@2000-01-01, Point(2 2)@2000-01-02, Point(1 1)@2000-01-03]'); + duration +---------- + 2 days +(1 row) + +SELECT duration(tgeompoint '{[Point(1 1)@2000-01-01, Point(2 2)@2000-01-02, Point(1 1)@2000-01-03],[Point(3 3)@2000-01-04, Point(3 3)@2000-01-05]}'); + duration +---------- + 3 days +(1 row) + +SELECT duration(tgeogpoint 'Point(1.5 1.5)@2000-01-01'); + duration +---------- + 00:00:00 +(1 row) + +SELECT duration(tgeogpoint '{Point(1.5 1.5)@2000-01-01, Point(2.5 2.5)@2000-01-02, Point(1.5 1.5)@2000-01-03}'); + duration +---------- + 00:00:00 +(1 row) + +SELECT duration(tgeogpoint '[Point(1.5 1.5)@2000-01-01, Point(2.5 2.5)@2000-01-02, Point(1.5 1.5)@2000-01-03]'); + duration +---------- + 2 days +(1 row) + +SELECT duration(tgeogpoint '{[Point(1.5 1.5)@2000-01-01, Point(2.5 2.5)@2000-01-02, Point(1.5 1.5)@2000-01-03],[Point(3.5 3.5)@2000-01-04, Point(3.5 3.5)@2000-01-05]}'); + duration ---------- 3 days (1 row) diff --git a/point/test/expected/51_tpoint_tbl.test.out b/point/test/expected/51_tpoint_tbl.test.out index eeaa15e677..7ef4eec64a 100644 --- a/point/test/expected/51_tpoint_tbl.test.out +++ b/point/test/expected/51_tpoint_tbl.test.out @@ -624,46 +624,46 @@ SELECT MAX(getTimestamp(inst)) FROM tbl_tgeogpoint3Dinst; SELECT MAX(timespan(getTime(temp))) FROM tbl_tgeompoint; max ---------- - 04:16:00 + 05:35:00 (1 row) SELECT MAX(timespan(getTime(temp))) FROM tbl_tgeogpoint; max ---------- - 03:19:00 + 04:47:00 (1 row) SELECT MAX(timespan(getTime(temp))) FROM tbl_tgeompoint3D; max ---------- - 03:27:00 + 04:34:00 (1 row) SELECT MAX(timespan(getTime(temp))) FROM tbl_tgeogpoint3D; max ---------- - 03:53:00 + 05:16:00 (1 row) -SELECT MAX(timespan(period(temp))) FROM tbl_tgeompoint; +SELECT MAX(duration(period(temp))) FROM tbl_tgeompoint; max ---------- 05:35:00 (1 row) -SELECT MAX(timespan(period(temp))) FROM tbl_tgeogpoint; +SELECT MAX(duration(period(temp))) FROM tbl_tgeogpoint; max ---------- 04:47:00 (1 row) -SELECT MAX(timespan(period(temp))) FROM tbl_tgeompoint3D; +SELECT MAX(duration(period(temp))) FROM tbl_tgeompoint3D; max ---------- 04:34:00 (1 row) -SELECT MAX(timespan(period(temp))) FROM tbl_tgeogpoint3D; +SELECT MAX(duration(period(temp))) FROM tbl_tgeogpoint3D; max ---------- 05:16:00 @@ -672,25 +672,25 @@ SELECT MAX(timespan(period(temp))) FROM tbl_tgeogpoint3D; SELECT MAX(timespan(temp)) FROM tbl_tgeompoint; max ---------- - 04:16:00 + 05:35:00 (1 row) SELECT MAX(timespan(temp)) FROM tbl_tgeogpoint; max ---------- - 03:19:00 + 04:47:00 (1 row) SELECT MAX(timespan(temp)) FROM tbl_tgeompoint3D; max ---------- - 03:27:00 + 04:34:00 (1 row) SELECT MAX(timespan(temp)) FROM tbl_tgeogpoint3D; max ---------- - 03:53:00 + 05:16:00 (1 row) SELECT MAX(numSequences(seq)) FROM tbl_tgeompointseq; diff --git a/point/test/queries/50_stbox.test.sql b/point/test/queries/50_stbox.test.sql index 5fe7e6c945..6402801c41 100644 --- a/point/test/queries/50_stbox.test.sql +++ b/point/test/queries/50_stbox.test.sql @@ -115,7 +115,7 @@ SELECT (geometry 'Polygon((1 1 1,1 2 2,2 2 2,2 1 1,1 1 1))'::box3d)::stbox; ------------------------------------------------------------------------------- -SELECT MAX(timespan(b::period)) FROM tbl_stbox; +SELECT MAX(duration(b::period)) FROM tbl_stbox; SELECT MAX(ST_XMax(b::box2d)) FROM tbl_stbox; SELECT MAX(ST_XMax(b::box3d)) FROM tbl_stbox; diff --git a/point/test/queries/51_tpoint.test.sql b/point/test/queries/51_tpoint.test.sql index 194e4836e1..75e50ef4be 100644 --- a/point/test/queries/51_tpoint.test.sql +++ b/point/test/queries/51_tpoint.test.sql @@ -744,6 +744,15 @@ SELECT timespan(tgeogpoint '{Point(1.5 1.5)@2000-01-01, Point(2.5 2.5)@2000-01-0 SELECT timespan(tgeogpoint '[Point(1.5 1.5)@2000-01-01, Point(2.5 2.5)@2000-01-02, Point(1.5 1.5)@2000-01-03]'); SELECT timespan(tgeogpoint '{[Point(1.5 1.5)@2000-01-01, Point(2.5 2.5)@2000-01-02, Point(1.5 1.5)@2000-01-03],[Point(3.5 3.5)@2000-01-04, Point(3.5 3.5)@2000-01-05]}'); +SELECT duration(tgeompoint 'Point(1 1)@2000-01-01'); +SELECT duration(tgeompoint '{Point(1 1)@2000-01-01, Point(2 2)@2000-01-02, Point(1 1)@2000-01-03}'); +SELECT duration(tgeompoint '[Point(1 1)@2000-01-01, Point(2 2)@2000-01-02, Point(1 1)@2000-01-03]'); +SELECT duration(tgeompoint '{[Point(1 1)@2000-01-01, Point(2 2)@2000-01-02, Point(1 1)@2000-01-03],[Point(3 3)@2000-01-04, Point(3 3)@2000-01-05]}'); +SELECT duration(tgeogpoint 'Point(1.5 1.5)@2000-01-01'); +SELECT duration(tgeogpoint '{Point(1.5 1.5)@2000-01-01, Point(2.5 2.5)@2000-01-02, Point(1.5 1.5)@2000-01-03}'); +SELECT duration(tgeogpoint '[Point(1.5 1.5)@2000-01-01, Point(2.5 2.5)@2000-01-02, Point(1.5 1.5)@2000-01-03]'); +SELECT duration(tgeogpoint '{[Point(1.5 1.5)@2000-01-01, Point(2.5 2.5)@2000-01-02, Point(1.5 1.5)@2000-01-03],[Point(3.5 3.5)@2000-01-04, Point(3.5 3.5)@2000-01-05]}'); + SELECT numSequences(tgeompoint '[Point(1 1)@2000-01-01, Point(2 2)@2000-01-02, Point(1 1)@2000-01-03]'); SELECT numSequences(tgeompoint '{[Point(1 1)@2000-01-01, Point(2 2)@2000-01-02, Point(1 1)@2000-01-03],[Point(3 3)@2000-01-04, Point(3 3)@2000-01-05]}'); SELECT numSequences(tgeogpoint '[Point(1.5 1.5)@2000-01-01, Point(2.5 2.5)@2000-01-02, Point(1.5 1.5)@2000-01-03]'); diff --git a/point/test/queries/51_tpoint_tbl.test.sql b/point/test/queries/51_tpoint_tbl.test.sql index 0912489084..9b3e77f1f6 100644 --- a/point/test/queries/51_tpoint_tbl.test.sql +++ b/point/test/queries/51_tpoint_tbl.test.sql @@ -186,10 +186,10 @@ SELECT MAX(timespan(getTime(temp))) FROM tbl_tgeogpoint; SELECT MAX(timespan(getTime(temp))) FROM tbl_tgeompoint3D; SELECT MAX(timespan(getTime(temp))) FROM tbl_tgeogpoint3D; -SELECT MAX(timespan(period(temp))) FROM tbl_tgeompoint; -SELECT MAX(timespan(period(temp))) FROM tbl_tgeogpoint; -SELECT MAX(timespan(period(temp))) FROM tbl_tgeompoint3D; -SELECT MAX(timespan(period(temp))) FROM tbl_tgeogpoint3D; +SELECT MAX(duration(period(temp))) FROM tbl_tgeompoint; +SELECT MAX(duration(period(temp))) FROM tbl_tgeogpoint; +SELECT MAX(duration(period(temp))) FROM tbl_tgeompoint3D; +SELECT MAX(duration(period(temp))) FROM tbl_tgeogpoint3D; SELECT MAX(timespan(temp)) FROM tbl_tgeompoint; SELECT MAX(timespan(temp)) FROM tbl_tgeogpoint; diff --git a/src/doublen.c b/src/doublen.c index afef409dbb..94f4582dc9 100644 --- a/src/doublen.c +++ b/src/doublen.c @@ -1,8 +1,4 @@ /***************************************************************************** - * - * doublen.c - * Internal types used in particular for the average and centroid temporal - * aggregates. * * This MobilityDB code is provided under The PostgreSQL License. * diff --git a/src/geo_constructors.c b/src/geo_constructors.c index 86da674af6..46893f106b 100644 --- a/src/geo_constructors.c +++ b/src/geo_constructors.c @@ -1,7 +1,4 @@ /***************************************************************************** - * - * geo_constructors.c - * Constructors for the 2D geometric operations * * This MobilityDB code is provided under The PostgreSQL License. * diff --git a/src/lifting.c b/src/lifting.c index 2f7d0b7bc6..ec98c079d6 100644 --- a/src/lifting.c +++ b/src/lifting.c @@ -1,7 +1,4 @@ /***************************************************************************** - * - * lifting.c - * Generic functions for lifting functions and operators on temporal types. * * This MobilityDB code is provided under The PostgreSQL License. * @@ -216,7 +213,7 @@ tfunc_tinstantset(const TInstantSet *ti, Datum param, TInstant *inst = tinstantset_inst_n(ti, i); instants[i] = tfunc_tinstant(inst, param, lfinfo); } - return tinstantset_make_free(instants, ti->count); + return tinstantset_make_free(instants, ti->count, MERGE_NO); } /** @@ -358,7 +355,7 @@ tfunc_tinstantset_base(const TInstantSet *ti, Datum value, Oid valuetypid, TInstant *inst = tinstantset_inst_n(ti, i); instants[i] = tfunc_tinstant_base(inst, value, valuetypid, param, lfinfo); } - return tinstantset_make_free(instants, ti->count); + return tinstantset_make_free(instants, ti->count, MERGE_NO); } /** @@ -840,7 +837,7 @@ sync_tfunc_tinstantset_tinstantset(const TInstantSet *ti1, const TInstantSet *ti else j++; } - return tinstantset_make_free(instants, k); + return tinstantset_make_free(instants, k, MERGE_NO); } /** @@ -873,7 +870,7 @@ sync_tfunc_tsequence_tinstantset(const TSequence *seq, const TInstantSet *ti, if (seq->period.upper < inst->t) break; } - return tinstantset_make_free(instants, k); + return tinstantset_make_free(instants, k, MERGE_NO); } /** @@ -930,7 +927,7 @@ sync_tfunc_tsequenceset_tinstantset(const TSequenceSet *ts, const TInstantSet *t else j++; } - return tinstantset_make_free(instants, k); + return tinstantset_make_free(instants, k, MERGE_NO); } /** diff --git a/src/oidcache.c b/src/oidcache.c index e990dabd51..35606809f8 100644 --- a/src/oidcache.c +++ b/src/oidcache.c @@ -1,7 +1,4 @@ /***************************************************************************** - * - * oidcache.c - * Functions for building a cache of Oids. * * This MobilityDB code is provided under The PostgreSQL License. * diff --git a/src/period.c b/src/period.c index cf00eec3e6..de0acb31be 100644 --- a/src/period.c +++ b/src/period.c @@ -1,8 +1,4 @@ /***************************************************************************** - * - * period.c - * Basic routines for period types composed of two timestamptz values and - * two boolean values stating whether the bounds are inclusive or not * * This MobilityDB code is provided under The PostgreSQL License. * @@ -28,6 +24,12 @@ * *****************************************************************************/ +/** + * @file period.c + * Basic routines for time periods composed of two `TimestampTz` values and + * two Boolean values stating whether the bounds are inclusive or not. + */ + #include "period.h" #include @@ -626,21 +628,21 @@ period_shift_tscale(Period *result, const Interval *start, } /** - * Returns the timespan of the period (internal function) + * Returns the duration of the period (internal function) */ Interval * -period_timespan_internal(const Period *p) +period_duration_internal(const Period *p) { return DatumGetIntervalP(call_function2(timestamp_mi, TimestampTzGetDatum(p->upper), TimestampTzGetDatum(p->lower))); } -PG_FUNCTION_INFO_V1(period_timespan); +PG_FUNCTION_INFO_V1(period_duration); /** - * Returns the timespan of the period + * Returns the duration of the period */ PGDLLEXPORT Datum -period_timespan(PG_FUNCTION_ARGS) +period_duration(PG_FUNCTION_ARGS) { Period *p = PG_GETARG_PERIOD(0); Datum result = call_function2(timestamp_mi, diff --git a/src/periodset.c b/src/periodset.c index eb18b4ec06..9cc55f82e3 100644 --- a/src/periodset.c +++ b/src/periodset.c @@ -1,7 +1,4 @@ /***************************************************************************** - * - * periodset.c - * Basic functions for set of periods. * * This MobilityDB code is provided under The PostgreSQL License. * @@ -27,6 +24,11 @@ * *****************************************************************************/ +/** + * @file periodset.c + * Basic functions for set of disjoint periods. + */ + #include "periodset.h" #include @@ -492,6 +494,22 @@ PG_FUNCTION_INFO_V1(periodset_timespan); */ PGDLLEXPORT Datum periodset_timespan(PG_FUNCTION_ARGS) +{ + PeriodSet *ps = PG_GETARG_PERIODSET(0); + Period *p1 = periodset_per_n(ps, 0); + Period *p2 = periodset_per_n(ps, ps->count - 1); + Datum result = call_function2(timestamp_mi, TimestampTzGetDatum(p2->upper), + TimestampTzGetDatum(p1->lower)); + PG_FREE_IF_COPY(ps, 0); + PG_RETURN_DATUM(result); +} + +PG_FUNCTION_INFO_V1(periodset_duration); +/** + * Returns the timespan of the period set value + */ +PGDLLEXPORT Datum +periodset_duration(PG_FUNCTION_ARGS) { PeriodSet *ps = PG_GETARG_PERIODSET(0); Period *p = periodset_per_n(ps, 0); diff --git a/src/rangetypes_ext.c b/src/rangetypes_ext.c index 5f10768e50..1d1a972efe 100644 --- a/src/rangetypes_ext.c +++ b/src/rangetypes_ext.c @@ -1,7 +1,4 @@ /***************************************************************************** - * - * rangetypes_ext.c - * Extension of operators for range types. * * This MobilityDB code is provided under The PostgreSQL License. * @@ -27,6 +24,13 @@ * *****************************************************************************/ +/** + * @file rangetypes_ext.c + * Extended operators for range types. + * + * These operators have been submitted as a PR to PostgreSQL. + */ + #include "rangetypes_ext.h" #include diff --git a/src/sql/01_period.in.sql b/src/sql/01_period.in.sql index aaa1debbf5..013f747541 100644 --- a/src/sql/01_period.in.sql +++ b/src/sql/01_period.in.sql @@ -120,9 +120,9 @@ CREATE FUNCTION upper_inc(period) AS 'MODULE_PATHNAME', 'period_upper_inc' LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE; -CREATE FUNCTION timespan(period) +CREATE FUNCTION duration(period) RETURNS interval - AS 'MODULE_PATHNAME', 'period_timespan' + AS 'MODULE_PATHNAME', 'period_duration' LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE; CREATE FUNCTION shift(period, interval) diff --git a/src/sql/05_periodset.in.sql b/src/sql/05_periodset.in.sql index 9a217bdca3..e78dfa7e2e 100644 --- a/src/sql/05_periodset.in.sql +++ b/src/sql/05_periodset.in.sql @@ -119,6 +119,11 @@ CREATE FUNCTION timespan(periodset) AS 'MODULE_PATHNAME', 'periodset_timespan' LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE; +CREATE FUNCTION duration(periodset) + RETURNS interval + AS 'MODULE_PATHNAME', 'periodset_duration' + LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE; + CREATE FUNCTION numPeriods(periodset) RETURNS integer AS 'MODULE_PATHNAME', 'periodset_num_periods' diff --git a/src/sql/22_temporal.in.sql b/src/sql/22_temporal.in.sql index 2b0863237d..42b121144a 100644 --- a/src/sql/22_temporal.in.sql +++ b/src/sql/22_temporal.in.sql @@ -732,6 +732,23 @@ CREATE FUNCTION timespan(ttext) AS 'MODULE_PATHNAME', 'temporal_timespan' LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE; +CREATE FUNCTION duration(tbool) + RETURNS interval + AS 'MODULE_PATHNAME', 'temporal_duration' + LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE; +CREATE FUNCTION duration(tint) + RETURNS interval + AS 'MODULE_PATHNAME', 'temporal_duration' + LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE; +CREATE FUNCTION duration(tfloat) + RETURNS interval + AS 'MODULE_PATHNAME', 'temporal_duration' + LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE; +CREATE FUNCTION duration(ttext) + RETURNS interval + AS 'MODULE_PATHNAME', 'temporal_duration' + LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE; + CREATE FUNCTION numSequences(tbool) RETURNS integer AS 'MODULE_PATHNAME', 'temporal_num_sequences' diff --git a/src/tbool_boolops.c b/src/tbool_boolops.c index 32c539a2ff..a01f519985 100644 --- a/src/tbool_boolops.c +++ b/src/tbool_boolops.c @@ -1,7 +1,4 @@ /***************************************************************************** - * - * tbool_boolops.c - * Temporal Boolean operators (and, or, not). * * This MobilityDB code is provided under The PostgreSQL License. * @@ -27,6 +24,11 @@ * *****************************************************************************/ +/** + * @file tbool_boolops.c + * Temporal Boolean operators (and, or, not). + */ + #include "tbool_boolops.h" #include "temporaltypes.h" diff --git a/src/tbox.c b/src/tbox.c index a195721d90..62bae32f1f 100644 --- a/src/tbox.c +++ b/src/tbox.c @@ -1,7 +1,4 @@ /***************************************************************************** - * - * tbox.c - * Functions for temporal bounding boxes. * * This MobilityDB code is provided under The PostgreSQL License. * @@ -29,6 +26,11 @@ * *****************************************************************************/ +/** + * @file tbox.c + * Functions for temporal bounding boxes. + */ + #include "tbox.h" #include diff --git a/src/temporal.c b/src/temporal.c index 647d9454a5..f22d43cd7e 100644 --- a/src/temporal.c +++ b/src/temporal.c @@ -1,7 +1,4 @@ /***************************************************************************** - * - * temporal.c - * Basic functions for temporal types of any subtype. * * This MobilityDB code is provided under The PostgreSQL License. * @@ -27,6 +24,11 @@ * *****************************************************************************/ +/** + * @file temporal.c + * Basic functions for temporal types of any subtype. + */ + #include "temporal.h" #include @@ -781,13 +783,14 @@ ensure_same_interpolation(const Temporal *temp1, const Temporal *temp2) /** * Ensures that the timestamp of the first temporal instant is smaller - * than the one of the second temporal instant + * (or equal if the merge parameter is true) than the one of the second + * temporal instant */ void ensure_increasing_timestamps(const TInstant *inst1, const TInstant *inst2, - bool strict) + bool merge) { - if ((strict && inst1->t > inst2->t) || (!strict && inst1->t >= inst2->t)) + if ((merge && inst1->t > inst2->t) || (!merge && inst1->t >= inst2->t)) { char *t1 = call_output(TIMESTAMPTZOID, TimestampTzGetDatum(inst1->t)); char *t2 = call_output(TIMESTAMPTZOID, TimestampTzGetDatum(inst2->t)); @@ -821,12 +824,12 @@ ensure_same_overlapping_value(const TInstant *inst1, const TInstant *inst2) * same dimensionality */ void -ensure_valid_tinstantarr(TInstant **instants, int count) +ensure_valid_tinstantarr(TInstant **instants, int count, bool merge) { for (int i = 1; i < count; i++) { ensure_same_interpolation((Temporal *) instants[i - 1], (Temporal *) instants[i]); - ensure_increasing_timestamps(instants[i - 1], instants[i], false); /* >= */ + ensure_increasing_timestamps(instants[i - 1], instants[i], merge); ensure_spatial_validity((Temporal *) instants[i - 1], (Temporal *) instants[i]); } return; @@ -1135,7 +1138,7 @@ tinstantset_constructor(PG_FUNCTION_ARGS) int count; TInstant **instants = (TInstant **)temporalarr_extract(array, &count); ensure_tinstantarr(instants, count); - Temporal *result = (Temporal *)tinstantset_make(instants, count); + Temporal *result = (Temporal *)tinstantset_make(instants, count, MERGE_NO); pfree(instants); PG_FREE_IF_COPY(array, 0); PG_RETURN_POINTER(result); @@ -2190,21 +2193,48 @@ temporal_timespan(PG_FUNCTION_ARGS) Temporal *temp = PG_GETARG_TEMPORAL(0); Datum result; ensure_valid_temptype(temp->temptype); - if (temp->temptype == INSTANT || temp->temptype == INSTANTSET) + if (temp->temptype == INSTANT) { Interval *interval = (Interval *) palloc(sizeof(Interval)); interval->month = interval->day = 0; interval->time = (TimeOffset) 0; result = PointerGetDatum(interval); } + else if (temp->temptype == INSTANTSET) + result = tinstantset_timespan((TInstantSet *)temp); else if (temp->temptype == SEQUENCE) - result = tsequence_timespan((TSequence *)temp); + result = tsequence_duration((TSequence *)temp); else /* temp->temptype == SEQUENCESET */ result = tsequenceset_timespan((TSequenceSet *)temp); PG_FREE_IF_COPY(temp, 0); PG_RETURN_DATUM(result); } +PG_FUNCTION_INFO_V1(temporal_duration); +/** + * Returns the duration of the temporal value + */ +PGDLLEXPORT Datum +temporal_duration(PG_FUNCTION_ARGS) +{ + Temporal *temp = PG_GETARG_TEMPORAL(0); + Datum result; + ensure_valid_temptype(temp->temptype); + if (temp->temptype == INSTANT || temp->temptype == INSTANTSET) + { + Interval *interval = (Interval *) palloc(sizeof(Interval)); + interval->month = interval->day = 0; + interval->time = (TimeOffset) 0; + result = PointerGetDatum(interval); + } + else if (temp->temptype == SEQUENCE) + result = tsequence_duration((TSequence *)temp); + else /* temp->temptype == SEQUENCESET */ + result = tsequenceset_duration((TSequenceSet *)temp); + PG_FREE_IF_COPY(temp, 0); + PG_RETURN_DATUM(result); +} + PG_FUNCTION_INFO_V1(temporal_num_sequences); /** * Returns the number of sequences of the temporal sequence (set) value diff --git a/src/temporal_aggfuncs.c b/src/temporal_aggfuncs.c index 02f5668c1d..2e68b57a44 100644 --- a/src/temporal_aggfuncs.c +++ b/src/temporal_aggfuncs.c @@ -1,7 +1,4 @@ /***************************************************************************** - * - * temporal_aggfuncs.c - * Temporal aggregate functions * * This MobilityDB code is provided under The PostgreSQL License. * @@ -27,6 +24,11 @@ * *****************************************************************************/ +/** + * @file temporal_aggfuncs.c + * Temporal aggregate functions + */ + #include "temporal_aggfuncs.h" #include @@ -1268,7 +1270,7 @@ temporal_tagg_finalfn(PG_FUNCTION_ARGS) values[0]->temptype == SEQUENCE); if (values[0]->temptype == INSTANT) result = (Temporal *)tinstantset_make((TInstant **)values, - state->length); + state->length, MERGE_NO); else /* values[0]->temptype == SEQUENCE */ result = (Temporal *)tsequenceset_make((TSequence **)values, state->length, NORMALIZE); @@ -1957,7 +1959,7 @@ tinstant_tavg_finalfn(TInstant **instants, int count) newinstants[i] = tinstant_make(Float8GetDatum(tavg), inst->t, FLOAT8OID); } - return tinstantset_make_free(newinstants, count); + return tinstantset_make_free(newinstants, count, MERGE_NO); } /** diff --git a/src/temporal_analyze.c b/src/temporal_analyze.c index c77bdc3475..18a16b694e 100644 --- a/src/temporal_analyze.c +++ b/src/temporal_analyze.c @@ -1,7 +1,4 @@ /***************************************************************************** - * - * temporal_analyze.c - * Functions for gathering statistics from temporal alphanumeric columns * * This MobilityDB code is provided under The PostgreSQL License. * @@ -29,7 +26,7 @@ /** * @file temporal_analyze.c - * Functions for gathering statistics from temporal alphanumber columns. + * Functions for gathering statistics from temporal alphanumeric columns. * * Various kind of statistics are collected for both the value and the time * dimension of temporal types. Please refer to the PostgreSQL file pg_statistic_d.h diff --git a/src/temporal_boxops.c b/src/temporal_boxops.c index f5c3950aab..ef3cb90080 100644 --- a/src/temporal_boxops.c +++ b/src/temporal_boxops.c @@ -1,7 +1,4 @@ /***************************************************************************** - * - * temporal_boxops.c - * Bounding box operators for temporal types. * * This MobilityDB code is provided under The PostgreSQL License. * @@ -32,7 +29,7 @@ * Bounding box operators for temporal types. * * The bounding box of temporal values are - * - a `period` for temporal Booleans + * - a `Period` for temporal Booleans * - a `TBOX` for temporal integers and floats, where the *x* coordinate is for * the value dimension and the *t* coordinate is for the time dimension. * The following operators are defined: `overlaps`, `contains`, `contained`, diff --git a/src/temporal_compops.c b/src/temporal_compops.c index 87005601ae..e780e06237 100644 --- a/src/temporal_compops.c +++ b/src/temporal_compops.c @@ -1,7 +1,4 @@ /***************************************************************************** - * - * temporal_compops.c - * Temporal comparison operators (=, <>, <, >, <=, >=). * * This MobilityDB code is provided under The PostgreSQL License. * @@ -27,6 +24,11 @@ * *****************************************************************************/ +/** + * @file temporal_compops.c + * Temporal comparison operators (=, <>, <, >, <=, >=). + */ + #include "temporal_compops.h" #include diff --git a/src/temporal_gist.c b/src/temporal_gist.c index 1b4064b023..be96592017 100644 --- a/src/temporal_gist.c +++ b/src/temporal_gist.c @@ -1,8 +1,4 @@ /***************************************************************************** - * - * temporal_gist.c - * R-tree GiST index for temporal types where only the time dimension - * is taken into account for indexing, currently, tbool and ttext. * * This MobilityDB code is provided under The PostgreSQL License. * @@ -28,6 +24,12 @@ * *****************************************************************************/ +/** + * @file temporal_gist.c + * R-tree GiST index for temporal types where only the time dimension + * is taken into account for indexing, currently, tbool and ttext. + */ + #include "temporal_gist.h" #include diff --git a/src/temporal_parser.c b/src/temporal_parser.c index 196c84c7bb..b1b7571105 100644 --- a/src/temporal_parser.c +++ b/src/temporal_parser.c @@ -1,7 +1,4 @@ /***************************************************************************** - * - * temporal_parser.c - * Functions for parsing time types and temporal types. * * This MobilityDB code is provided under The PostgreSQL License. * @@ -498,7 +495,7 @@ tinstantset_parse(char **str, Oid basetype) instants[i] = tinstant_parse(str, basetype, false, true); } p_cbrace(str); - return tinstantset_make_free(instants, count); + return tinstantset_make_free(instants, count, MERGE_NO); } /** diff --git a/src/temporal_posops.c b/src/temporal_posops.c index 1de0abd4bc..ad5155b5f7 100644 --- a/src/temporal_posops.c +++ b/src/temporal_posops.c @@ -1,7 +1,4 @@ /***************************************************************************** - * - * temporal_posops.c - * Relative position operators for temporal types. * * This MobilityDB code is provided under The PostgreSQL License. * diff --git a/src/temporal_selfuncs.c b/src/temporal_selfuncs.c index 93e2ebb977..2294bd2e19 100644 --- a/src/temporal_selfuncs.c +++ b/src/temporal_selfuncs.c @@ -1,8 +1,4 @@ /***************************************************************************** - * - * temporal_selfuncs.c - * Functions for selectivity estimation of operators on temporal types whose - * bounding box is a period, that is, tbool and ttext. * * This MobilityDB code is provided under The PostgreSQL License. * @@ -31,7 +27,7 @@ /** * @file temporal_selfuncs.c * Functions for selectivity estimation of operators on temporal types whose - * bounding box is a period, that is, `tbool` and `ttext`. + * bounding box is a `Period`, that is, `tbool` and `ttext`. * * The operators currently supported are as follows * - B-tree comparison operators: `<`, `<=`, `>`, `>=` diff --git a/src/temporal_spgist.c b/src/temporal_spgist.c index f753b3ebd6..c86db299b4 100644 --- a/src/temporal_spgist.c +++ b/src/temporal_spgist.c @@ -1,12 +1,7 @@ /***************************************************************************** - * - * temporal_spgist.c - * Quad-tree SP-GiST index for temporal boolean and temporal text types. * * This MobilityDB code is provided under The PostgreSQL License. * - * These functions are based on those in the file rangetypes_spgist.c. - * * Copyright (c) 2020, Université libre de Bruxelles and MobilityDB * contributors * @@ -29,6 +24,13 @@ * *****************************************************************************/ +/** + * @file temporal_spgist.c + * Quad-tree SP-GiST index for temporal boolean and temporal text types. + * + * These functions are based on those in the file `rangetypes_spgist.c`. + */ + #if MOBDB_PGSQL_VERSION >= 110000 #include "temporal_spgist.h" diff --git a/src/temporal_util.c b/src/temporal_util.c index 4ce8d35e6f..84c9be5ac0 100644 --- a/src/temporal_util.c +++ b/src/temporal_util.c @@ -1,7 +1,4 @@ /***************************************************************************** - * - * temporal_util.c - * Miscellaneous utility functions for temporal types. * * This MobilityDB code is provided under The PostgreSQL License. * @@ -27,6 +24,11 @@ * *****************************************************************************/ +/** + * @file temporal_util.c + * Miscellaneous utility functions for temporal types. + */ + #include "temporal_util.h" #include diff --git a/src/temporal_waggfuncs.c b/src/temporal_waggfuncs.c index b172cc8327..fd959696ba 100644 --- a/src/temporal_waggfuncs.c +++ b/src/temporal_waggfuncs.c @@ -1,7 +1,4 @@ /***************************************************************************** - * - * temporal_waggfuncs.c - * Window temporal aggregate functions * * This MobilityDB code is provided under The PostgreSQL License. * @@ -27,6 +24,11 @@ * *****************************************************************************/ +/** + * @file temporal_waggfuncs.c + * Window temporal aggregate functions + */ + #include "temporal_waggfuncs.h" #include diff --git a/src/time_analyze.c b/src/time_analyze.c index c46e19ad4c..a92d0900b0 100644 --- a/src/time_analyze.c +++ b/src/time_analyze.c @@ -1,7 +1,4 @@ /***************************************************************************** - * - * time_analyze.c - * Functions for gathering statistics from time type columns * * This MobilityDB code is provided under The PostgreSQL License. * diff --git a/src/time_gist.c b/src/time_gist.c index bef1939128..7355636c7f 100644 --- a/src/time_gist.c +++ b/src/time_gist.c @@ -1,7 +1,4 @@ /***************************************************************************** - * - * time_gist.c - * R-tree GiST index for time types. * * This MobilityDB code is provided under The PostgreSQL License. * @@ -31,7 +28,7 @@ * @file time_gist.c * R-tree GiST index for time types. * - * These functions are based on those in the file rangetypes_gist.c. + * These functions are based on those in the file `rangetypes_gist.c`. */ #include "time_gist.h" diff --git a/src/time_selfuncs.c b/src/time_selfuncs.c index 945ca74604..f12e61cb6f 100644 --- a/src/time_selfuncs.c +++ b/src/time_selfuncs.c @@ -1,7 +1,4 @@ /***************************************************************************** - * - * time_selfuncs.c - * Functions for selectivity estimation of time types operators * * This MobilityDB code is provided under The PostgreSQL License. * diff --git a/src/time_spgist.c b/src/time_spgist.c index 072d4fb20e..c65e74dd2b 100644 --- a/src/time_spgist.c +++ b/src/time_spgist.c @@ -1,7 +1,4 @@ /***************************************************************************** - * - * time_spgist.c - * Quad-tree SP-GiST index for time types. * * This MobilityDB code is provided under The PostgreSQL License. * diff --git a/src/timeops.c b/src/timeops.c index 1d073ce2e8..94b13c4b28 100644 --- a/src/timeops.c +++ b/src/timeops.c @@ -1,7 +1,4 @@ /***************************************************************************** - * - * timeops.c - * Operators for time types. * * This MobilityDB code is provided under The PostgreSQL License. * @@ -27,6 +24,11 @@ * *****************************************************************************/ +/** + * @file timeops.c + * Operators for time types. + */ + #include "timeops.h" #include diff --git a/src/timestampset.c b/src/timestampset.c index f6dac252bf..325918030c 100644 --- a/src/timestampset.c +++ b/src/timestampset.c @@ -1,7 +1,4 @@ /***************************************************************************** - * - * timestampset.c - * Basic functions for set of timestamps. * * This MobilityDB code is provided under The PostgreSQL License. * @@ -27,6 +24,11 @@ * *****************************************************************************/ +/** + * @file timestampset.c + * Basic functions for set of (distinct) timestamps. + */ + #include "timestampset.h" #include diff --git a/src/tinstant.c b/src/tinstant.c index 2bf9743e93..5a06764912 100644 --- a/src/tinstant.c +++ b/src/tinstant.c @@ -1,7 +1,4 @@ /***************************************************************************** - * - * tinstant.c - * Basic functions for temporal instants. * * This MobilityDB code is provided under The PostgreSQL License. * @@ -27,6 +24,11 @@ * *****************************************************************************/ +/** + * @file tinstant.c + * Basic functions for temporal instants. + */ + #include "tinstant.h" #include @@ -188,7 +190,7 @@ tinstant_merge_array(TInstant **instants, int count) tinstantarr_sort(instants, count); int newcount = tinstantarr_remove_duplicates(instants, count); return (newcount == 1) ? (Temporal *) instants[0] : - (Temporal *) tinstantset_make(instants, newcount); + (Temporal *) tinstantset_make(instants, newcount, MERGE_NO); } /** @@ -360,7 +362,7 @@ tfloatinst_to_tintinst(const TInstant *inst) TInstantSet * tinstant_to_tinstantset(const TInstant *inst) { - return tinstantset_make((TInstant **)&inst, 1); + return tinstantset_make((TInstant **)&inst, 1, MERGE_NO); } /** diff --git a/src/tinstantset.c b/src/tinstantset.c index 2e1c984790..7983d5472a 100644 --- a/src/tinstantset.c +++ b/src/tinstantset.c @@ -1,7 +1,4 @@ /***************************************************************************** - * - * tinstantset.c - * Basic functions for temporal instant sets. * * This MobilityDB code is provided under The PostgreSQL License. * @@ -27,6 +24,11 @@ * *****************************************************************************/ +/** + * @file tinstantset.c + * Basic functions for temporal instant sets. + */ + #include "tinstantset.h" #include @@ -89,11 +91,11 @@ tinstantset_bbox(void *box, const TInstantSet *ti) * Ensure the validity of the arguments when creating a temporal value */ static void -tinstantset_make_valid(TInstant **instants, int count) +tinstantset_make_valid(TInstant **instants, int count, bool merge) { /* Test the validity of the instants */ assert(count > 0); - ensure_valid_tinstantarr(instants, count); + ensure_valid_tinstantarr(instants, count, merge); return; } @@ -171,11 +173,13 @@ tinstantset_make1(TInstant **instants, int count) * * @param[in] instants Array of instants * @param[in] count Number of elements in the array + * @param[in] merge True when overlapping instants are allowed as required in + * merge operations */ TInstantSet * -tinstantset_make(TInstant **instants, int count) +tinstantset_make(TInstant **instants, int count, bool merge) { - tinstantset_make_valid(instants, count); + tinstantset_make_valid(instants, count, merge); return tinstantset_make1(instants, count); } @@ -185,16 +189,18 @@ tinstantset_make(TInstant **instants, int count) * * @param[in] instants Array of instants * @param[in] count Number of elements in the array + * @param[in] merge True when overlapping instants are allowed as required in + * merge operations */ TInstantSet * -tinstantset_make_free(TInstant **instants, int count) +tinstantset_make_free(TInstant **instants, int count, bool merge) { if (count == 0) { pfree(instants); return NULL; } - TInstantSet *result = tinstantset_make(instants, count); + TInstantSet *result = tinstantset_make(instants, count, merge); for (int i = 0; i < count; i++) pfree(instants[i]); pfree(instants); @@ -210,7 +216,7 @@ tinstantset_from_base_internal(Datum value, Oid valuetypid, const TimestampSet * TInstant **instants = palloc(sizeof(TInstant *) * ts->count); for (int i = 0; i < ts->count; i++) instants[i] = tinstant_make(value, timestampset_time_n(ts, i), valuetypid); - return tinstantset_make_free(instants, ts->count); + return tinstantset_make_free(instants, ts->count, MERGE_NO); } PG_FUNCTION_INFO_V1(tinstantset_from_base); @@ -236,7 +242,7 @@ tinstantset_append_tinstant(const TInstantSet *ti, const TInstant *inst) /* Ensure validity of the arguments */ assert(ti->valuetypid == inst->valuetypid); TInstant *inst1 = tinstantset_inst_n(ti, ti->count - 1); - ensure_increasing_timestamps(inst1, inst, true); /* > */ + ensure_increasing_timestamps(inst1, inst, MERGE); ensure_same_overlapping_value(inst1, inst); if (inst1->t == inst->t) return tinstantset_copy(ti); @@ -311,7 +317,7 @@ tinstantset_merge_array(TInstantSet **instsets, int count) } /* Create the result */ Temporal *result = (k == 1) ? (Temporal *) instants[0] : - (Temporal *) tinstantset_make(instants, totalcount); + (Temporal *) tinstantset_make(instants, totalcount, MERGE_NO); pfree(instants); return result; } @@ -458,8 +464,8 @@ intersection_tinstantset_tinstantset(const TInstantSet *ti1, const TInstantSet * } if (k != 0) { - *inter1 = tinstantset_make(instants1, k); - *inter2 = tinstantset_make(instants2, k); + *inter1 = tinstantset_make(instants1, k, MERGE_NO); + *inter2 = tinstantset_make(instants2, k, MERGE_NO); } pfree(instants1); pfree(instants2); @@ -528,7 +534,7 @@ tinstantset_read(StringInfo buf, Oid valuetypid) TInstant **instants = palloc(sizeof(TInstant *) * count); for (int i = 0; i < count; i++) instants[i] = tinstant_read(buf, valuetypid); - return tinstantset_make_free(instants, count); + return tinstantset_make_free(instants, count, MERGE_NO); } /***************************************************************************** @@ -615,7 +621,7 @@ tsequenceset_to_tinstantset(const TSequenceSet *ts) TSequence *seq = tsequenceset_seq_n(ts, i); instants[i] = tsequence_inst_n(seq, 0); } - TInstantSet *result = tinstantset_make(instants, ts->count); + TInstantSet *result = tinstantset_make(instants, ts->count, MERGE_NO); pfree(instants); return result; } @@ -767,6 +773,19 @@ tinstantset_period(Period *p, const TInstantSet *ti) return period_set(p, lower, upper, true, true); } +/** + * Returns the timespan of the timestamp set value + */ +Datum +tinstantset_timespan(const TInstantSet *ti) +{ + TimestampTz lower = tinstantset_start_timestamp(ti); + TimestampTz upper = tinstantset_end_timestamp(ti); + Datum result = call_function2(timestamp_mi, TimestampTzGetDatum(upper), + TimestampTzGetDatum(lower)); + return result; +} + /** * Returns the instants of the temporal value as a C array */ @@ -1038,7 +1057,7 @@ tinstantset_restrict_value(const TInstantSet *ti, Datum value, bool atfunc) instants[count++] = inst; } TInstantSet *result = (count == 0) ? NULL : - tinstantset_make(instants, count); + tinstantset_make(instants, count, MERGE_NO); pfree(instants); return result; } @@ -1077,7 +1096,7 @@ tinstantset_restrict_values(const TInstantSet *ti, const Datum *values, instants[newcount++] = inst; } TInstantSet *result = (newcount == 0) ? NULL : - tinstantset_make(instants, newcount); + tinstantset_make(instants, newcount, MERGE_NO); pfree(instants); return result; } @@ -1108,7 +1127,7 @@ tnumberinstset_restrict_range(const TInstantSet *ti, RangeType *range, bool atfu instants[count++] = inst; } TInstantSet *result = (count == 0) ? NULL : - tinstantset_make(instants, count); + tinstantset_make(instants, count, MERGE_NO); pfree(instants); return result; } @@ -1149,7 +1168,7 @@ tnumberinstset_restrict_ranges(const TInstantSet *ti, RangeType **normranges, instants[newcount++] = inst; } TInstantSet *result = (newcount == 0) ? NULL : - tinstantset_make(instants, newcount); + tinstantset_make(instants, newcount, MERGE_NO); pfree(instants); return result; } @@ -1249,7 +1268,7 @@ tinstantset_restrict_timestamp(const TInstantSet *ti, TimestampTz t, bool atfunc instants[count++] = inst; } TInstantSet *result = (count == 0) ? NULL : - tinstantset_make(instants, count); + tinstantset_make(instants, count, MERGE_NO); pfree(instants); return (Temporal *)result; } @@ -1273,7 +1292,7 @@ tinstantset_restrict_timestampset(const TInstantSet *ti, if (temp == NULL || temp->temptype == INSTANTSET) return (TInstantSet *) temp; inst = (TInstant *) temp; - result = tinstantset_make(&inst, 1); + result = tinstantset_make(&inst, 1, MERGE_NO); pfree(inst); return result; } @@ -1324,7 +1343,7 @@ tinstantset_restrict_timestampset(const TInstantSet *ti, while (i < ti->count) instants[k++] = tinstantset_inst_n(ti, i++); } - result = (k == 0) ? NULL : tinstantset_make(instants, k); + result = (k == 0) ? NULL : tinstantset_make(instants, k, MERGE_NO); pfree(instants); return result; } @@ -1357,7 +1376,7 @@ tinstantset_restrict_period(const TInstantSet *ti, const Period *period, instants[count++] = inst; } TInstantSet *result = (count == 0) ? NULL : - tinstantset_make(instants, count); + tinstantset_make(instants, count, MERGE_NO); pfree(instants); return result; } @@ -1402,7 +1421,7 @@ tinstantset_restrict_periodset(const TInstantSet *ti, const PeriodSet *ps, instants[count++] = inst; } TInstantSet *result = (count == 0) ? NULL : - tinstantset_make(instants, count); + tinstantset_make(instants, count, MERGE_NO); pfree(instants); return result; } diff --git a/src/tnumber_distance.c b/src/tnumber_distance.c index e080231f9f..45a79b73d1 100644 --- a/src/tnumber_distance.c +++ b/src/tnumber_distance.c @@ -1,7 +1,4 @@ /*********************************************************************** - * - * tnumber_distance.c - * Distance functions for temporal numbers. * * This MobilityDB code is provided under The PostgreSQL License. * @@ -27,6 +24,11 @@ * *****************************************************************************/ +/** + * @file tnumber_distance.c + * Distance functions for temporal numbers. + */ + #include "tnumber_distance.h" #include @@ -77,6 +79,7 @@ datum_distance(Datum l, Datum r, Oid typel, Oid typer) * @param[in] seq Temporal number * @param[in] value Value * @param[in] valuetypid Type of the base value + * @param[in] restypid Type of the result */ static TSequence * distance_tnumberseq_base(const TSequence *seq, Datum value, Oid valuetypid, @@ -123,7 +126,7 @@ distance_tnumberseq_base(const TSequence *seq, Datum value, Oid valuetypid, * @param[in] ts Temporal number * @param[in] value Value * @param[in] valuetypid Type of the base value - + * @param[in] restypid Type of the result */ static TSequenceSet * distance_tnumberseqset_base(const TSequenceSet *ts, Datum value, Oid valuetypid, @@ -143,6 +146,11 @@ distance_tnumberseqset_base(const TSequenceSet *ts, Datum value, Oid valuetypid, /** * Returns the temporal distance between the temporal number and the * value (distpatch function) + * + * @param[in] temp Temporal number + * @param[in] value Value + * @param[in] valuetypid Type of the base value + * @param[in] restypid Type of the result */ static Temporal * distance_tnumber_base_internal(const Temporal *temp, Datum value, @@ -216,6 +224,9 @@ distance_tnumber_base(PG_FUNCTION_ARGS) /** * Returns the temporal distance between the two temporal points * (dispatch function) + * + * @param[in] temp1,temp2 Temporal numbers + * @param[in] restypid Type of the result */ static Temporal * distance_tnumber_tnumber_internal(const Temporal *temp1, const Temporal *temp2, diff --git a/src/tnumber_gist.c b/src/tnumber_gist.c index 1ff5933203..9057f44d2f 100644 --- a/src/tnumber_gist.c +++ b/src/tnumber_gist.c @@ -1,9 +1,4 @@ /***************************************************************************** - * - * tnumber_gist.c - * R-tree GiST index for temporal integers and temporal floats - * - * These functions are based on those in the file gistproc.c. * * This MobilityDB code is provided under The PostgreSQL License. * @@ -29,6 +24,13 @@ * *****************************************************************************/ +/** + * @file tnumber_gist.c + * R-tree GiST index for temporal integers and temporal floats + * + * These functions are based on those in the file `gistproc.c`. + */ + #include "tnumber_gist.h" #include diff --git a/src/tnumber_mathfuncs.c b/src/tnumber_mathfuncs.c index 1db5e6de2a..1358c0f9e3 100644 --- a/src/tnumber_mathfuncs.c +++ b/src/tnumber_mathfuncs.c @@ -1,8 +1,4 @@ /***************************************************************************** - * - * tnumber_mathfuncs.c - * Temporal mathematical operators (+, -, *, /) and functions (round, - * degrees). * * This MobilityDB code is provided under The PostgreSQL License. * @@ -28,6 +24,11 @@ * *****************************************************************************/ +/** + * @file tnumber_mathfuncs.c + * Temporal mathematical operators (+, -, *, /) and functions (round, degrees). + */ + #include "tnumber_mathfuncs.h" #include diff --git a/src/tnumber_selfuncs.c b/src/tnumber_selfuncs.c index 8c63b5d035..a05f08a35d 100644 --- a/src/tnumber_selfuncs.c +++ b/src/tnumber_selfuncs.c @@ -1,7 +1,4 @@ /***************************************************************************** - * - * tnumber_selfuncs.c - * Functions for selectivity estimation of operators on temporal number types * * This MobilityDB code is provided under The PostgreSQL License. * @@ -27,6 +24,11 @@ * *****************************************************************************/ +/** + * @file tnumber_selfuncs.c + * Functions for selectivity estimation of operators on temporal number types + */ + #include "tnumber_selfuncs.h" #include diff --git a/src/tnumber_spgist.c b/src/tnumber_spgist.c index add598985a..31718e322d 100644 --- a/src/tnumber_spgist.c +++ b/src/tnumber_spgist.c @@ -1,9 +1,5 @@ /***************************************************************************** * - * tnumber_spgist.c - * SP-GiST implementation of 4-dimensional quad tree over temporal integers - * and floats. - * * This MobilityDB code is provided under The PostgreSQL License. * * Copyright (c) 2020, Université libre de Bruxelles and MobilityDB @@ -30,10 +26,10 @@ /** * @file tnumber_spgist.c - * SP-GiST implementation of 4-dimensional quad tree over temporal integers - * and floats. + * SP-GiST implementation of 4-dimensional quad-tree over temporal integers + * and temporal floats. * - * These functions are based on those in the file geo_spgist.c. from + * These functions are based on those in the file ``geo_spgist.c`. from * PostgreSQL. This module provides SP-GiST implementation for temporal * number types using a quad tree analogy in 4-dimensional space. Notice * that SP-GiST doesn't allow indexing of overlapping objects. We are diff --git a/src/tsequence.c b/src/tsequence.c index 7af6be2d8a..f46b807326 100644 --- a/src/tsequence.c +++ b/src/tsequence.c @@ -1,7 +1,4 @@ /***************************************************************************** - * - * tsequence.c - * Basic functions for temporal sequences. * * This MobilityDB code is provided under The PostgreSQL License. * @@ -27,6 +24,11 @@ * *****************************************************************************/ +/** + * @file tsequence.c + * Basic functions for temporal sequences. + */ + #include "tsequence.h" #include @@ -720,120 +722,6 @@ tinstantarr_normalize(TInstant **instants, bool linear, int count, return result; } -/** - * Normalize the array of temporal sequence values - * - * The inpuy sequences may be non-contiguous but must ordered and - * either (1) are non-overlapping, or (2) share the same last/first - * instant in the case we are merging temporal sequences. - * - * @param[in] sequences Array of input sequences - * @param[in] count Number of elements in the input array - * @param[out] newcount Number of elements in the output array - * @result Array of normalized temporal sequences values - * @pre Each sequence in the input array is normalized - * @pre When merging sequences, the test whether the value is the same - * at the common instant should be ensured by the calling function. - * @note The function creates new sequences and does not free the original - * sequences - */ -TSequence ** -tsequencearr_normalize(TSequence **sequences, int count, int *newcount) -{ - TSequence **result = palloc(sizeof(TSequence *) * count); - /* seq1 is the sequence to which we try to join subsequent seq2 */ - TSequence *seq1 = sequences[0]; - Oid valuetypid = seq1->valuetypid; - bool linear = MOBDB_FLAGS_GET_LINEAR(seq1->flags); - bool isnew = false; - int k = 0; - for (int i = 1; i < count; i++) - { - TSequence *seq2 = sequences[i]; - TInstant *last2 = (seq1->count == 1) ? NULL : - tsequence_inst_n(seq1, seq1->count - 2); - Datum last2value = (seq1->count == 1) ? 0 : - tinstant_value(last2); - TInstant *last1 = tsequence_inst_n(seq1, seq1->count - 1); - Datum last1value = tinstant_value(last1); - TInstant *first1 = tsequence_inst_n(seq2, 0); - Datum first1value = tinstant_value(first1); - TInstant *first2 = (seq2->count == 1) ? NULL : - tsequence_inst_n(seq2, 1); - Datum first2value = (seq2->count == 1) ? 0 : - tinstant_value(first2); - bool adjacent = seq1->period.upper == seq2->period.lower && - (seq1->period.upper_inc || seq2->period.lower_inc); - /* If they are adjacent and not instantaneous */ - if (adjacent && last2 != NULL && first2 != NULL && - ( - /* If step and the last segment of the first sequence is constant - ..., 1@t1, 1@t2) [1@t2, 1@t3, ... -> ..., 1@t1, 2@t3, ... - ..., 1@t1, 1@t2) [1@t2, 2@t3, ... -> ..., 1@t1, 2@t3, ... - ..., 1@t1, 1@t2] (1@t2, 2@t3, ... -> ..., 1@t1, 2@t3, ... - */ - (!linear && - datum_eq(last2value, last1value, valuetypid) && - datum_eq(last1value, first1value, valuetypid)) - || - /* If the last/first segments are constant and equal - ..., 1@t1, 1@t2] (1@t2, 1@t3, ... -> ..., 1@t1, 1@t3, ... - */ - (datum_eq(last2value, last1value, valuetypid) && - datum_eq(last1value, first1value, valuetypid) && - datum_eq(first1value, first2value, valuetypid)) - || - /* If float/point sequences and collinear last/first segments having the same duration - ..., 1@t1, 2@t2) [2@t2, 3@t3, ... -> ..., 1@t1, 3@t3, ... - */ - (datum_eq(last1value, first1value, valuetypid) && - datum_collinear(valuetypid, last2value, first1value, first2value, - last2->t, first1->t, first2->t)) - )) - { - /* Remove the last and first instants of the sequences */ - seq1 = tsequence_join(seq1, seq2, true, true); - isnew = true; - } - /* If step sequences and the first one has an exclusive upper bound, - by definition the first sequence has the last segment constant - ..., 1@t1, 1@t2) [2@t2, 3@t3, ... -> ..., 1@t1, 2@t2, 3@t3, ... - ..., 1@t1, 1@t2) [2@t2] -> ..., 1@t1, 2@t2] - */ - else if (adjacent && !linear && !seq1->period.upper_inc) - { - /* Remove the last instant of the first sequence */ - seq1 = tsequence_join(seq1, seq2, true, false); - isnew = true; - } - /* If they are adjacent and have equal last/first value respectively - Stewise - ... 1@t1, 2@t2], (2@t2, 1@t3, ... -> ..., 1@t1, 2@t2, 1@t3, ... - [1@t1], (1@t1, 2@t2, ... -> ..., 1@t1, 2@t2 - Linear - ..., 1@t1, 2@t2), [2@t2, 1@t3, ... -> ..., 1@t1, 2@t2, 1@t3, ... - ..., 1@t1, 2@t2], (2@t2, 1@t3, ... -> ..., 1@t1, 2@t2, 1@t3, ... - ..., 1@t1, 2@t2), [2@t2] -> ..., 1@t1, 2@t2] - [1@t1],(1@t1, 2@t2, ... -> [1@t1, 2@t2, ... - */ - else if (adjacent && datum_eq(last1value, first1value, valuetypid)) - { - /* Remove the first instant of the second sequence */ - seq1 = tsequence_join(seq1, seq2, false, true); - isnew = true; - } - else - { - result[k++] = isnew ? seq1 : tsequence_copy(seq1); - seq1 = seq2; - isnew = false; - } - } - result[k++] = isnew ? seq1 : tsequence_copy(seq1); - *newcount = k; - return result; -} - /*****************************************************************************/ /** @@ -904,7 +792,7 @@ tsequence_make_valid(TInstant **instants, int count, bool lower_inc, bool upper_ tinstant_value(instants[count - 2]), instants[0]->valuetypid)) ereport(ERROR, (errcode(ERRCODE_RESTRICT_VIOLATION), errmsg("Invalid end value for temporal sequence"))); - ensure_valid_tinstantarr(instants, count); + ensure_valid_tinstantarr(instants, count, MERGE_NO); return; } @@ -1063,38 +951,6 @@ tsequence_make_free(TInstant **instants, int count, bool lower_inc, return result; } -/** - * Join the two temporal sequence values - * - * @param[in] seq1,seq2 Temporal sequence values - * @param[in] removelast,removefirst Remove the last and/or the - * first instant of the first/second sequence - * @pre The two input sequences are adjacent and have the same interpolation - * @note The function is called when normalizing an array of sequences - * and thus, all validity tests have been already made - */ -TSequence * -tsequence_join(const TSequence *seq1, const TSequence *seq2, - bool removelast, bool removefirst) -{ - ensure_same_interpolation((Temporal *) seq1, (Temporal *) seq2); - - int count1 = removelast ? seq1->count - 1 : seq1->count; - int start2 = removefirst ? 1 : 0; - int count = count1 + (seq2->count - start2); - TInstant **instants = palloc(sizeof(TSequence *) * count); - int k = 0; - for (int i = 0; i < count1; i++) - instants[k++] = tsequence_inst_n(seq1, i); - for (int i = start2; i < seq2->count; i++) - instants[k++] = tsequence_inst_n(seq2, i); - TSequence *result = tsequence_make1(instants, count, - seq1->period.lower_inc, seq2->period.upper_inc, - MOBDB_FLAGS_GET_LINEAR(seq1->flags), NORMALIZE_NO); - pfree(instants); - return result; -} - /** * Construct a temporal sequence value from a base value and a period * (internal function) @@ -1133,6 +989,150 @@ tsequence_from_base(PG_FUNCTION_ARGS) PG_RETURN_POINTER(result); } +/** + * Join the two temporal sequence values + * + * @param[in] seq1,seq2 Temporal sequence values + * @param[in] removelast,removefirst Remove the last and/or the + * first instant of the first/second sequence + * @pre The two input sequences are adjacent and have the same interpolation + * @note The function is called when normalizing an array of sequences + * and thus, all validity tests have been already made + */ +static TSequence * +tsequence_join(const TSequence *seq1, const TSequence *seq2, + bool removelast, bool removefirst) +{ + int count1 = removelast ? seq1->count - 1 : seq1->count; + int start2 = removefirst ? 1 : 0; + int count = count1 + (seq2->count - start2); + TInstant **instants = palloc(sizeof(TSequence *) * count); + int k = 0; + for (int i = 0; i < count1; i++) + instants[k++] = tsequence_inst_n(seq1, i); + for (int i = start2; i < seq2->count; i++) + instants[k++] = tsequence_inst_n(seq2, i); + TSequence *result = tsequence_make1(instants, count, + seq1->period.lower_inc, seq2->period.upper_inc, + MOBDB_FLAGS_GET_LINEAR(seq1->flags), NORMALIZE_NO); + pfree(instants); + return result; +} + +/** + * Normalize the array of temporal sequence values + * + * The inpuy sequences may be non-contiguous but must ordered and + * either (1) are non-overlapping, or (2) share the same last/first + * instant in the case we are merging temporal sequences. + * + * @param[in] sequences Array of input sequences + * @param[in] count Number of elements in the input array + * @param[out] newcount Number of elements in the output array + * @result Array of normalized temporal sequences values + * @pre Each sequence in the input array is normalized + * @pre When merging sequences, the test whether the value is the same + * at the common instant should be ensured by the calling function. + * @note The function creates new sequences and does not free the original + * sequences + */ +TSequence ** +tsequencearr_normalize(TSequence **sequences, int count, int *newcount) +{ + TSequence **result = palloc(sizeof(TSequence *) * count); + /* seq1 is the sequence to which we try to join subsequent seq2 */ + TSequence *seq1 = sequences[0]; + Oid valuetypid = seq1->valuetypid; + bool linear = MOBDB_FLAGS_GET_LINEAR(seq1->flags); + bool isnew = false; + int k = 0; + for (int i = 1; i < count; i++) + { + TSequence *seq2 = sequences[i]; + TInstant *last2 = (seq1->count == 1) ? NULL : + tsequence_inst_n(seq1, seq1->count - 2); + Datum last2value = (seq1->count == 1) ? 0 : + tinstant_value(last2); + TInstant *last1 = tsequence_inst_n(seq1, seq1->count - 1); + Datum last1value = tinstant_value(last1); + TInstant *first1 = tsequence_inst_n(seq2, 0); + Datum first1value = tinstant_value(first1); + TInstant *first2 = (seq2->count == 1) ? NULL : + tsequence_inst_n(seq2, 1); + Datum first2value = (seq2->count == 1) ? 0 : + tinstant_value(first2); + bool adjacent = seq1->period.upper == seq2->period.lower && + (seq1->period.upper_inc || seq2->period.lower_inc); + /* If they are adjacent and not instantaneous */ + if (adjacent && last2 != NULL && first2 != NULL && + ( + /* If step and the last segment of the first sequence is constant + ..., 1@t1, 1@t2) [1@t2, 1@t3, ... -> ..., 1@t1, 2@t3, ... + ..., 1@t1, 1@t2) [1@t2, 2@t3, ... -> ..., 1@t1, 2@t3, ... + ..., 1@t1, 1@t2] (1@t2, 2@t3, ... -> ..., 1@t1, 2@t3, ... + */ + (!linear && + datum_eq(last2value, last1value, valuetypid) && + datum_eq(last1value, first1value, valuetypid)) + || + /* If the last/first segments are constant and equal + ..., 1@t1, 1@t2] (1@t2, 1@t3, ... -> ..., 1@t1, 1@t3, ... + */ + (datum_eq(last2value, last1value, valuetypid) && + datum_eq(last1value, first1value, valuetypid) && + datum_eq(first1value, first2value, valuetypid)) + || + /* If float/point sequences and collinear last/first segments having the same duration + ..., 1@t1, 2@t2) [2@t2, 3@t3, ... -> ..., 1@t1, 3@t3, ... + */ + (datum_eq(last1value, first1value, valuetypid) && + datum_collinear(valuetypid, last2value, first1value, first2value, + last2->t, first1->t, first2->t)) + )) + { + /* Remove the last and first instants of the sequences */ + seq1 = tsequence_join(seq1, seq2, true, true); + isnew = true; + } + /* If step sequences and the first one has an exclusive upper bound, + by definition the first sequence has the last segment constant + ..., 1@t1, 1@t2) [2@t2, 3@t3, ... -> ..., 1@t1, 2@t2, 3@t3, ... + ..., 1@t1, 1@t2) [2@t2] -> ..., 1@t1, 2@t2] + */ + else if (adjacent && !linear && !seq1->period.upper_inc) + { + /* Remove the last instant of the first sequence */ + seq1 = tsequence_join(seq1, seq2, true, false); + isnew = true; + } + /* If they are adjacent and have equal last/first value respectively + Stewise + ... 1@t1, 2@t2], (2@t2, 1@t3, ... -> ..., 1@t1, 2@t2, 1@t3, ... + [1@t1], (1@t1, 2@t2, ... -> ..., 1@t1, 2@t2 + Linear + ..., 1@t1, 2@t2), [2@t2, 1@t3, ... -> ..., 1@t1, 2@t2, 1@t3, ... + ..., 1@t1, 2@t2], (2@t2, 1@t3, ... -> ..., 1@t1, 2@t2, 1@t3, ... + ..., 1@t1, 2@t2), [2@t2] -> ..., 1@t1, 2@t2] + [1@t1],(1@t1, 2@t2, ... -> [1@t1, 2@t2, ... + */ + else if (adjacent && datum_eq(last1value, first1value, valuetypid)) + { + /* Remove the first instant of the second sequence */ + seq1 = tsequence_join(seq1, seq2, false, true); + isnew = true; + } + else + { + result[k++] = isnew ? seq1 : tsequence_copy(seq1); + seq1 = seq2; + isnew = false; + } + } + result[k++] = isnew ? seq1 : tsequence_copy(seq1); + *newcount = k; + return result; +} + /** * Append an instant to the temporal value */ @@ -1143,7 +1143,7 @@ tsequence_append_tinstant(const TSequence *seq, const TInstant *inst) assert(seq->valuetypid == inst->valuetypid); bool linear = MOBDB_FLAGS_GET_LINEAR(seq->flags); TInstant *inst1 = tsequence_inst_n(seq, seq->count - 1); - ensure_increasing_timestamps(inst1, inst, true); /* > */ + ensure_increasing_timestamps(inst1, inst, MERGE); if (inst1->t == inst->t) { bool seqresult = datum_eq(tinstant_value(inst1), tinstant_value(inst), inst1->valuetypid); @@ -1151,7 +1151,7 @@ tsequence_append_tinstant(const TSequence *seq, const TInstant *inst) { char *t1 = call_output(TIMESTAMPTZOID, TimestampTzGetDatum(inst1->t)); ereport(ERROR, (errcode(ERRCODE_INTERNAL_ERROR), - errmsg("The temporal values have different value at their overlapping instant %s", t1))); + errmsg("The temporal values have different value at their common instant %s", t1))); } /* The result is a sequence set */ if (linear && ! seqresult) @@ -1248,13 +1248,13 @@ tsequence_merge_array1(TSequence **sequences, int count, int *totalcount) ereport(ERROR, (errcode(ERRCODE_INTERNAL_ERROR), errmsg("The temporal values cannot overlap on time: %s, %s", t1, t2))); } - if (inst1->t == inst2->t && seq1->period.upper_inc && seq2->period.lower_inc) + else if (inst1->t == inst2->t && seq1->period.upper_inc && seq2->period.lower_inc) { if (! datum_eq(tinstant_value(inst1), tinstant_value(inst2), inst1->valuetypid)) { t1 = call_output(TIMESTAMPTZOID, TimestampTzGetDatum(inst1->t)); ereport(ERROR, (errcode(ERRCODE_INTERNAL_ERROR), - errmsg("The temporal values have different value at their overlapping instant %s", t1))); + errmsg("The temporal values have different value at their common instant %s", t1))); } } seq1 = seq2; @@ -1443,8 +1443,8 @@ intersection_tsequence_tinstantset(const TSequence *seq, const TInstantSet *ti, return false; } - *inter1 = tinstantset_make_free(instants1, k); - *inter2 = tinstantset_make(instants2, k); + *inter1 = tinstantset_make_free(instants1, k, MERGE_NO); + *inter2 = tinstantset_make(instants2, k, MERGE_NO); pfree(instants2); return true; } @@ -2096,12 +2096,12 @@ tsequence_max_value(const TSequence *seq) } /** - * Returns the timespan of the temporal value + * Returns the duration of the temporal value */ Datum -tsequence_timespan(const TSequence *seq) +tsequence_duration(const TSequence *seq) { - Interval *result = period_timespan_internal(&seq->period); + Interval *result = period_duration_internal(&seq->period); return PointerGetDatum(result); } @@ -3587,7 +3587,7 @@ tsequence_at_timestampset(const TSequence *seq, const TimestampSet *ts) inst = tsequence_at_timestamp(seq, timestampset_time_n(ts, 0)); if (inst == NULL) return (TInstantSet *) NULL; - return tinstantset_make(&inst, 1); + return tinstantset_make(&inst, 1, MERGE_NO); } /* Bounding box test */ @@ -3602,7 +3602,7 @@ tsequence_at_timestampset(const TSequence *seq, const TimestampSet *ts) { if (!contains_timestampset_timestamp_internal(ts, inst->t)) return NULL; - return tinstantset_make(&inst, 1); + return tinstantset_make(&inst, 1, MERGE_NO); } /* General case */ @@ -3618,7 +3618,7 @@ tsequence_at_timestampset(const TSequence *seq, const TimestampSet *ts) if (inst != NULL) instants[k++] = inst; } - return tinstantset_make_free(instants, k); + return tinstantset_make_free(instants, k, MERGE_NO); } /*****************************************************************************/ diff --git a/src/tsequenceset.c b/src/tsequenceset.c index c723219900..383a24729f 100644 --- a/src/tsequenceset.c +++ b/src/tsequenceset.c @@ -1,7 +1,4 @@ /***************************************************************************** - * - * tsequenceset.c - * Basic functions for temporal sequence sets. * * This MobilityDB code is provided under The PostgreSQL License. * @@ -27,6 +24,11 @@ * *****************************************************************************/ +/** + * @file tsequenceset.c + * Basic functions for temporal sequence sets. + */ + #include "tsequenceset.h" #include @@ -460,8 +462,8 @@ intersection_tsequenceset_tinstantset(const TSequenceSet *ts, const TInstantSet return false; } - *inter1 = tinstantset_make_free(instants1, k); - *inter2 = tinstantset_make(instants2, k); + *inter1 = tinstantset_make_free(instants1, k, MERGE_NO); + *inter2 = tinstantset_make(instants2, k, MERGE_NO); pfree(instants2); return true; } @@ -981,6 +983,19 @@ tsequenceset_get_time(const TSequenceSet *ts) */ Datum tsequenceset_timespan(const TSequenceSet *ts) +{ + TSequence *seq1 = tsequenceset_seq_n(ts, 0); + TSequence *seq2 = tsequenceset_seq_n(ts, ts->count - 1); + Datum result = call_function2(timestamp_mi, + TimestampTzGetDatum(seq2->period.upper), TimestampTzGetDatum(seq1->period.lower)); + return result; +} + +/** + * Returns the duration of the temporal value + */ +Datum +tsequenceset_duration(const TSequenceSet *ts) { TSequence *seq = tsequenceset_seq_n(ts, 0); Datum result = call_function2(timestamp_mi, @@ -1730,7 +1745,7 @@ tsequenceset_restrict_timestampset(const TSequenceSet *ts1, if (atfunc && temp != NULL) { TInstant *inst = (TInstant *) temp; - Temporal *result = (Temporal *) tinstantset_make(&inst, 1); + Temporal *result = (Temporal *) tinstantset_make(&inst, 1, MERGE_NO); pfree(inst); return result; } @@ -1774,7 +1789,7 @@ tsequenceset_restrict_timestampset(const TSequenceSet *ts1, j++; } } - return (Temporal *) tinstantset_make_free(instants, count); + return (Temporal *) tinstantset_make_free(instants, count, MERGE_NO); } else { diff --git a/src/ttext_textfuncs.c b/src/ttext_textfuncs.c index 4607539d5c..685ca407e7 100644 --- a/src/ttext_textfuncs.c +++ b/src/ttext_textfuncs.c @@ -1,7 +1,4 @@ /***************************************************************************** - * - * ttext_textfuncs.c - * Temporal text functions (textcat, lower, upper). * * This MobilityDB code is provided under The PostgreSQL License. * @@ -27,6 +24,11 @@ * *****************************************************************************/ +/** + * @file ttext_textfuncs.c + * Temporal text functions: `textcat`, `lower`, `upper`. + */ + #include "ttext_textfuncs.h" #include diff --git a/test/expected/01_period.test.out b/test/expected/01_period.test.out index 7d9f751620..6706b8df7f 100644 --- a/test/expected/01_period.test.out +++ b/test/expected/01_period.test.out @@ -223,32 +223,32 @@ SELECT upper_inc(period '(2000-01-01,2000-01-02)'); f (1 row) -SELECT timespan(period '[2000-01-01,2000-01-01]'); - timespan +SELECT duration(period '[2000-01-01,2000-01-01]'); + duration ---------- 00:00:00 (1 row) -SELECT timespan(period '[2000-01-01,2000-01-02]'); - timespan +SELECT duration(period '[2000-01-01,2000-01-02]'); + duration ---------- 1 day (1 row) -SELECT timespan(period '(2000-01-01,2000-01-02]'); - timespan +SELECT duration(period '(2000-01-01,2000-01-02]'); + duration ---------- 1 day (1 row) -SELECT timespan(period '[2000-01-01,2000-01-02)'); - timespan +SELECT duration(period '[2000-01-01,2000-01-02)'); + duration ---------- 1 day (1 row) -SELECT timespan(period '(2000-01-01,2000-01-02)'); - timespan +SELECT duration(period '(2000-01-01,2000-01-02)'); + duration ---------- 1 day (1 row) diff --git a/test/expected/01_period_tbl.test.out b/test/expected/01_period_tbl.test.out index b37e7820c4..facd51d51e 100644 --- a/test/expected/01_period_tbl.test.out +++ b/test/expected/01_period_tbl.test.out @@ -9,31 +9,31 @@ COPY tbl_period_tmp FROM '/tmp/tbl_period' (FORMAT BINARY); COPY 100 DROP TABLE tbl_period_tmp; DROP TABLE -SELECT max(timespan(period(t, t + i))) FROM tbl_timestamptz, tbl_interval; +SELECT max(duration(period(t, t + i))) FROM tbl_timestamptz, tbl_interval; max ---------- 01:39:00 (1 row) -SELECT max(timespan(period(t, t + i, true, true))) FROM tbl_timestamptz, tbl_interval; +SELECT max(duration(period(t, t + i, true, true))) FROM tbl_timestamptz, tbl_interval; max ---------- 01:39:00 (1 row) -SELECT max(timespan(period(t, t + i, true, false))) FROM tbl_timestamptz, tbl_interval; +SELECT max(duration(period(t, t + i, true, false))) FROM tbl_timestamptz, tbl_interval; max ---------- 01:39:00 (1 row) -SELECT max(timespan(period(t, t + i, false, true))) FROM tbl_timestamptz, tbl_interval; +SELECT max(duration(period(t, t + i, false, true))) FROM tbl_timestamptz, tbl_interval; max ---------- 01:39:00 (1 row) -SELECT max(timespan(period(t, t + i, false, false))) FROM tbl_timestamptz, tbl_interval; +SELECT max(duration(period(t, t + i, false, false))) FROM tbl_timestamptz, tbl_interval; max ---------- 01:39:00 @@ -774,8 +774,8 @@ SELECT upper_inc(p) FROM tbl_period; f (100 rows) -SELECT timespan(p) FROM tbl_period; - timespan +SELECT duration(p) FROM tbl_period; + duration ---------- 00:07:00 00:08:00 diff --git a/test/expected/05_periodset.test.out b/test/expected/05_periodset.test.out index fad4f77f52..6a45923881 100644 --- a/test/expected/05_periodset.test.out +++ b/test/expected/05_periodset.test.out @@ -153,23 +153,59 @@ SELECT timespan(periodset '{(2000-01-01,2000-01-02),(2000-01-02,2000-01-03),(200 SELECT timespan(periodset '{(2000-01-01,2000-01-02),(2000-01-03,2000-01-04),(2000-01-05,2000-01-06)}'); timespan ---------- - 3 days + 5 days (1 row) SELECT timespan(periodset '{[2000-01-01,2000-01-02),(2000-01-03,2000-01-04),(2000-01-05,2000-01-06)}'); timespan ---------- - 3 days + 5 days (1 row) SELECT timespan(periodset '{(2000-01-01,2000-01-02),(2000-01-03,2000-01-04),(2000-01-05,2000-01-06]}'); timespan ---------- - 3 days + 5 days (1 row) SELECT timespan(periodset '{[2000-01-01,2000-01-02),(2000-01-03,2000-01-04),(2000-01-05,2000-01-06]}'); timespan +---------- + 5 days +(1 row) + +SELECT duration(periodset '{[2000-01-01,2000-01-01]}'); + duration +---------- + 00:00:00 +(1 row) + +SELECT duration(periodset '{(2000-01-01,2000-01-02),(2000-01-02,2000-01-03),(2000-01-03,2000-01-04)}'); + duration +---------- + 3 days +(1 row) + +SELECT duration(periodset '{(2000-01-01,2000-01-02),(2000-01-03,2000-01-04),(2000-01-05,2000-01-06)}'); + duration +---------- + 3 days +(1 row) + +SELECT duration(periodset '{[2000-01-01,2000-01-02),(2000-01-03,2000-01-04),(2000-01-05,2000-01-06)}'); + duration +---------- + 3 days +(1 row) + +SELECT duration(periodset '{(2000-01-01,2000-01-02),(2000-01-03,2000-01-04),(2000-01-05,2000-01-06]}'); + duration +---------- + 3 days +(1 row) + +SELECT duration(periodset '{[2000-01-01,2000-01-02),(2000-01-03,2000-01-04),(2000-01-05,2000-01-06]}'); + duration ---------- 3 days (1 row) diff --git a/test/expected/05_periodset_tbl.test.out b/test/expected/05_periodset_tbl.test.out index 89fa4ec945..95654e14de 100644 --- a/test/expected/05_periodset_tbl.test.out +++ b/test/expected/05_periodset_tbl.test.out @@ -223,6 +223,111 @@ SELECT timespan(ps) FROM tbl_periodset; timespan ---------- + 00:04:00 + 01:21:00 + 00:35:00 + 00:02:00 + 00:05:00 + 00:24:00 + 00:52:00 + 00:37:00 + 01:14:00 + 01:45:00 + 00:48:00 + 00:37:00 + 01:19:00 + 00:20:00 + 01:18:00 + 00:14:00 + 00:37:00 + 01:25:00 + 00:38:00 + 00:41:00 + 01:08:00 + 00:49:00 + 00:15:00 + 00:24:00 + 01:04:00 + 01:17:00 + 00:06:00 + 01:19:00 + 00:14:00 + 00:12:00 + 00:59:00 + 00:56:00 + 00:54:00 + 01:43:00 + 01:01:00 + 01:09:00 + 00:11:00 + 01:07:00 + 00:02:00 + 00:34:00 + 00:55:00 + 00:22:00 + 01:16:00 + 00:20:00 + 00:41:00 + 00:31:00 + 00:00:00 + 01:03:00 + 00:07:00 + 00:12:00 + 00:41:00 + 00:20:00 + 00:41:00 + 00:58:00 + 00:14:00 + 00:23:00 + 00:20:00 + 00:49:00 + 00:02:00 + 00:23:00 + 00:52:00 + 00:13:00 + 01:23:00 + 00:14:00 + 01:30:00 + 00:58:00 + 01:11:00 + 00:29:00 + 01:02:00 + 00:03:00 + 01:12:00 + 00:33:00 + 00:21:00 + 01:12:00 + 01:10:00 + 00:31:00 + 01:07:00 + 01:22:00 + 00:54:00 + 01:18:00 + 00:24:00 + 01:08:00 + 00:55:00 + 00:58:00 + 00:01:00 + 01:42:00 + 00:22:00 + 00:31:00 + 00:03:00 + 00:31:00 + 00:46:00 + 00:16:00 + 00:12:00 + 00:41:00 + 00:16:00 + 00:07:00 + 00:39:00 + 00:35:00 + 00:38:00 +(100 rows) + +SELECT duration(ps) FROM tbl_periodset; + duration +---------- + 00:04:00 00:40:00 00:09:00 diff --git a/test/expected/21_tbox.test.out b/test/expected/21_tbox.test.out index 53b5468ca8..333e7cd8d9 100644 --- a/test/expected/21_tbox.test.out +++ b/test/expected/21_tbox.test.out @@ -36,7 +36,7 @@ ERROR: Could not parse TBOX: Both value and time dimensions are empty LINE 1: SELECT tbox 'TBOX((,),(,2000-01-01))'; ^ SELECT tbox 'TBOX((AA, 2000-01-02))'; -ERROR: Could not parse TBOX: Invalid input syntax for type double +ERROR: Invalid input syntax for type double LINE 1: SELECT tbox 'TBOX((AA, 2000-01-02))'; ^ SELECT tbox 'TBOX((1, AA))'; @@ -52,7 +52,7 @@ ERROR: Could not parse TBOX: Missing opening parenthesis LINE 1: SELECT tbox 'TBOX((1, 2000-01-01),2, 2000-01-02))'; ^ SELECT tbox 'TBOX((1, 2000-01-01),(AA, 2000-01-02))'; -ERROR: Could not parse TBOX: Invalid input syntax for type double +ERROR: Invalid input syntax for type double LINE 1: SELECT tbox 'TBOX((1, 2000-01-01),(AA, 2000-01-02))'; ^ SELECT tbox 'TBOX((1, 2000-01-01),(2, AA))'; @@ -141,7 +141,7 @@ SELECT ROUND(MAX(upper(b::floatrange) - lower(b::floatrange))::numeric, 6) FROM 9.798705 (1 row) -SELECT MAX(timespan(b::period)) FROM tbl_tbox; +SELECT MAX(duration(b::period)) FROM tbl_tbox; max ---------- 00:09:00 diff --git a/test/expected/22_temporal.test.out b/test/expected/22_temporal.test.out index 8487cdc86e..18063298af 100644 --- a/test/expected/22_temporal.test.out +++ b/test/expected/22_temporal.test.out @@ -1706,11 +1706,11 @@ SELECT appendInstant(tfloat 'Interp=Stepwise;{[1@2000-01-01, 1@2000-01-02)}', '2 SELECT appendInstant(tfloat '{1@2000-01-01, 2@2000-01-02}', tfloat '2@2000-01-01'); ERROR: Timestamps for temporal value must be increasing: 2000-01-02 00:00:00+00, 2000-01-01 00:00:00+00 SELECT appendInstant(tfloat '[1@2000-01-01, 1@2000-01-02]', '2@2000-01-02'); -ERROR: The temporal values have different value at their overlapping instant 2000-01-02 00:00:00+00 +ERROR: The temporal values have different value at their common instant 2000-01-02 00:00:00+00 SELECT appendInstant(tint '[1@2000-01-01, 2@2000-01-02, 1@2000-01-03]', tint '[1@2000-01-04, 1@2000-01-05]'); ERROR: The second argument must be of instant subtype SELECT appendInstant(tfloat '{[1@2000-01-01, 1@2000-01-02]}', '2@2000-01-02'); -ERROR: The temporal values have different value at their overlapping instant 2000-01-02 00:00:00+00 +ERROR: The temporal values have different value at their common instant 2000-01-02 00:00:00+00 SELECT merge(tbool 't@2000-01-01', tbool 't@2000-01-02'); merge ------------------------------------------------------ @@ -2003,9 +2003,9 @@ SELECT merge(tint '{[2@2000-01-02], [1@2000-01-03, 2@2000-01-04]}', tint '[1@200 SELECT merge(tint '{1@2000-01-01, 2@2000-01-02, 1@2000-01-03}', tint '{2@2000-01-03, 2@2000-01-04, 1@2000-01-05}'); ERROR: The temporal values have different value at their common instant 2000-01-03 00:00:00+00 SELECT merge(tint '[1@2000-01-01, 2@2000-01-02, 1@2000-01-03]', tint '[2@2000-01-03, 2@2000-01-04, 1@2000-01-05]'); -ERROR: The temporal values have different value at their overlapping instant 2000-01-03 00:00:00+00 +ERROR: The temporal values have different value at their common instant 2000-01-03 00:00:00+00 SELECT merge(tint '{[1@2000-01-01, 2@2000-01-02, 1@2000-01-03],[1@2000-01-04, 1@2000-01-05]}', tint '{[2@2000-01-05, 2@2000-01-06, 1@2000-01-07],[1@2000-01-08, 1@2000-01-09]}'); -ERROR: The temporal values have different value at their overlapping instant 2000-01-05 00:00:00+00 +ERROR: The temporal values have different value at their common instant 2000-01-05 00:00:00+00 SELECT merge(tint '{1@2000-01-01, 2@2000-01-02, 1@2000-01-03}', tint '{2@2000-01-02, 2@2000-01-03, 1@2000-01-04}'); ERROR: The temporal values have different value at their common instant 2000-01-03 00:00:00+00 SELECT merge(tint '[1@2000-01-01, 2@2000-01-02, 1@2000-01-03]', tint '[2@2000-01-02, 2@2000-01-03, 1@2000-01-04]'); @@ -2086,9 +2086,9 @@ ERROR: Input values must be of the same interpolation SELECT merge(ARRAY[tint '{1@2000-01-01, 2@2000-01-02, 1@2000-01-03}', '{2@2000-01-03, 2@2000-01-04, 1@2000-01-05}']); ERROR: The temporal values have different value at their common instant 2000-01-03 00:00:00+00 SELECT merge(ARRAY[tint '[1@2000-01-01, 2@2000-01-02, 1@2000-01-03]', '[2@2000-01-03, 2@2000-01-04, 1@2000-01-05]']); -ERROR: The temporal values have different value at their overlapping instant 2000-01-03 00:00:00+00 +ERROR: The temporal values have different value at their common instant 2000-01-03 00:00:00+00 SELECT merge(ARRAY[tint '{[1@2000-01-01, 2@2000-01-02, 1@2000-01-03],[1@2000-01-04, 1@2000-01-05]}', '{[2@2000-01-05, 2@2000-01-06, 1@2000-01-07],[1@2000-01-08, 1@2000-01-09]}']); -ERROR: The temporal values have different value at their overlapping instant 2000-01-05 00:00:00+00 +ERROR: The temporal values have different value at their common instant 2000-01-05 00:00:00+00 SELECT merge(ARRAY[tint '{1@2000-01-01, 2@2000-01-02, 1@2000-01-03}', '{2@2000-01-02, 2@2000-01-03, 1@2000-01-04}']); ERROR: The temporal values have different value at their common instant 2000-01-03 00:00:00+00 SELECT merge(ARRAY[tint '[1@2000-01-01, 2@2000-01-02, 1@2000-01-03]', '[2@2000-01-02, 2@2000-01-03, 1@2000-01-04]']); @@ -3287,7 +3287,7 @@ SELECT timespan(tbool 't@2000-01-01'); SELECT timespan(tbool '{t@2000-01-01, f@2000-01-02, t@2000-01-03}'); timespan ---------- - 00:00:00 + 2 days (1 row) SELECT timespan(tbool '[t@2000-01-01, f@2000-01-02, t@2000-01-03]'); @@ -3299,7 +3299,7 @@ SELECT timespan(tbool '[t@2000-01-01, f@2000-01-02, t@2000-01-03]'); SELECT timespan(tbool '{[t@2000-01-01, f@2000-01-02, t@2000-01-03],[t@2000-01-04, t@2000-01-05]}'); timespan ---------- - 3 days + 4 days (1 row) SELECT timespan(tint '1@2000-01-01'); @@ -3311,7 +3311,7 @@ SELECT timespan(tint '1@2000-01-01'); SELECT timespan(tint '{1@2000-01-01, 2@2000-01-02, 1@2000-01-03}'); timespan ---------- - 00:00:00 + 2 days (1 row) SELECT timespan(tint '[1@2000-01-01, 2@2000-01-02, 1@2000-01-03]'); @@ -3323,7 +3323,7 @@ SELECT timespan(tint '[1@2000-01-01, 2@2000-01-02, 1@2000-01-03]'); SELECT timespan(tint '{[1@2000-01-01, 2@2000-01-02, 1@2000-01-03],[3@2000-01-04, 3@2000-01-05]}'); timespan ---------- - 3 days + 4 days (1 row) SELECT timespan(tfloat '1.5@2000-01-01'); @@ -3335,7 +3335,7 @@ SELECT timespan(tfloat '1.5@2000-01-01'); SELECT timespan(tfloat '{1.5@2000-01-01, 2.5@2000-01-02, 1.5@2000-01-03}'); timespan ---------- - 00:00:00 + 2 days (1 row) SELECT timespan(tfloat '[1.5@2000-01-01, 2.5@2000-01-02, 1.5@2000-01-03]'); @@ -3353,13 +3353,13 @@ SELECT timespan(tfloat 'Interp=Stepwise;[1.5@2000-01-01, 2.5@2000-01-02, 1.5@200 SELECT timespan(tfloat '{[1.5@2000-01-01, 2.5@2000-01-02, 1.5@2000-01-03],[3.5@2000-01-04, 3.5@2000-01-05]}'); timespan ---------- - 3 days + 4 days (1 row) SELECT timespan(tfloat 'Interp=Stepwise;{[1.5@2000-01-01, 2.5@2000-01-02, 1.5@2000-01-03],[3.5@2000-01-04, 3.5@2000-01-05]}'); timespan ---------- - 3 days + 4 days (1 row) SELECT timespan(ttext 'AAA@2000-01-01'); @@ -3371,7 +3371,7 @@ SELECT timespan(ttext 'AAA@2000-01-01'); SELECT timespan(ttext '{AAA@2000-01-01, BBB@2000-01-02, AAA@2000-01-03}'); timespan ---------- - 00:00:00 + 2 days (1 row) SELECT timespan(ttext '[AAA@2000-01-01, BBB@2000-01-02, AAA@2000-01-03]'); @@ -3382,6 +3382,114 @@ SELECT timespan(ttext '[AAA@2000-01-01, BBB@2000-01-02, AAA@2000-01-03]'); SELECT timespan(ttext '{[AAA@2000-01-01, BBB@2000-01-02, AAA@2000-01-03],[CCC@2000-01-04, CCC@2000-01-05]}'); timespan +---------- + 4 days +(1 row) + +SELECT duration(tbool 't@2000-01-01'); + duration +---------- + 00:00:00 +(1 row) + +SELECT duration(tbool '{t@2000-01-01, f@2000-01-02, t@2000-01-03}'); + duration +---------- + 00:00:00 +(1 row) + +SELECT duration(tbool '[t@2000-01-01, f@2000-01-02, t@2000-01-03]'); + duration +---------- + 2 days +(1 row) + +SELECT duration(tbool '{[t@2000-01-01, f@2000-01-02, t@2000-01-03],[t@2000-01-04, t@2000-01-05]}'); + duration +---------- + 3 days +(1 row) + +SELECT duration(tint '1@2000-01-01'); + duration +---------- + 00:00:00 +(1 row) + +SELECT duration(tint '{1@2000-01-01, 2@2000-01-02, 1@2000-01-03}'); + duration +---------- + 00:00:00 +(1 row) + +SELECT duration(tint '[1@2000-01-01, 2@2000-01-02, 1@2000-01-03]'); + duration +---------- + 2 days +(1 row) + +SELECT duration(tint '{[1@2000-01-01, 2@2000-01-02, 1@2000-01-03],[3@2000-01-04, 3@2000-01-05]}'); + duration +---------- + 3 days +(1 row) + +SELECT duration(tfloat '1.5@2000-01-01'); + duration +---------- + 00:00:00 +(1 row) + +SELECT duration(tfloat '{1.5@2000-01-01, 2.5@2000-01-02, 1.5@2000-01-03}'); + duration +---------- + 00:00:00 +(1 row) + +SELECT duration(tfloat '[1.5@2000-01-01, 2.5@2000-01-02, 1.5@2000-01-03]'); + duration +---------- + 2 days +(1 row) + +SELECT duration(tfloat 'Interp=Stepwise;[1.5@2000-01-01, 2.5@2000-01-02, 1.5@2000-01-03]'); + duration +---------- + 2 days +(1 row) + +SELECT duration(tfloat '{[1.5@2000-01-01, 2.5@2000-01-02, 1.5@2000-01-03],[3.5@2000-01-04, 3.5@2000-01-05]}'); + duration +---------- + 3 days +(1 row) + +SELECT duration(tfloat 'Interp=Stepwise;{[1.5@2000-01-01, 2.5@2000-01-02, 1.5@2000-01-03],[3.5@2000-01-04, 3.5@2000-01-05]}'); + duration +---------- + 3 days +(1 row) + +SELECT duration(ttext 'AAA@2000-01-01'); + duration +---------- + 00:00:00 +(1 row) + +SELECT duration(ttext '{AAA@2000-01-01, BBB@2000-01-02, AAA@2000-01-03}'); + duration +---------- + 00:00:00 +(1 row) + +SELECT duration(ttext '[AAA@2000-01-01, BBB@2000-01-02, AAA@2000-01-03]'); + duration +---------- + 2 days +(1 row) + +SELECT duration(ttext '{[AAA@2000-01-01, BBB@2000-01-02, AAA@2000-01-03],[CCC@2000-01-04, CCC@2000-01-05]}'); + duration ---------- 3 days (1 row) diff --git a/test/expected/22_temporal_tbl.test.out b/test/expected/22_temporal_tbl.test.out index fd2ea411bf..080f7775d7 100644 --- a/test/expected/22_temporal_tbl.test.out +++ b/test/expected/22_temporal_tbl.test.out @@ -753,46 +753,46 @@ SELECT MAX(getTimestamp(inst)) FROM tbl_ttextinst; SELECT MAX(timespan(getTime(temp))) FROM tbl_tbool; max ---------- - 04:10:00 + 05:39:00 (1 row) SELECT MAX(timespan(getTime(temp))) FROM tbl_tint; max ---------- - 02:48:00 + 04:01:00 (1 row) SELECT MAX(timespan(getTime(temp))) FROM tbl_tfloat; max ---------- - 03:38:00 + 04:55:00 (1 row) SELECT MAX(timespan(getTime(temp))) FROM tbl_ttext; max ---------- - 04:12:00 + 05:34:00 (1 row) -SELECT MAX(timespan(period(temp))) FROM tbl_tbool; +SELECT MAX(duration(period(temp))) FROM tbl_tbool; max ---------- 05:39:00 (1 row) -SELECT MAX(timespan(period(temp))) FROM tbl_tint; +SELECT MAX(duration(period(temp))) FROM tbl_tint; max ---------- 04:01:00 (1 row) -SELECT MAX(timespan(period(temp))) FROM tbl_tfloat; +SELECT MAX(duration(period(temp))) FROM tbl_tfloat; max ---------- 04:55:00 (1 row) -SELECT MAX(timespan(period(temp))) FROM tbl_ttext; +SELECT MAX(duration(period(temp))) FROM tbl_ttext; max ---------- 05:34:00 @@ -801,25 +801,25 @@ SELECT MAX(timespan(period(temp))) FROM tbl_ttext; SELECT MAX(timespan(temp)) FROM tbl_tbool; max ---------- - 04:10:00 + 05:39:00 (1 row) SELECT MAX(timespan(temp)) FROM tbl_tint; max ---------- - 02:48:00 + 04:01:00 (1 row) SELECT MAX(timespan(temp)) FROM tbl_tfloat; max ---------- - 03:38:00 + 04:55:00 (1 row) SELECT MAX(timespan(temp)) FROM tbl_ttext; max ---------- - 04:12:00 + 05:34:00 (1 row) SELECT MAX(numSequences(seq)) FROM tbl_tboolseq; diff --git a/test/queries/01_period.test.sql b/test/queries/01_period.test.sql index a53688c615..670c27356f 100644 --- a/test/queries/01_period.test.sql +++ b/test/queries/01_period.test.sql @@ -93,11 +93,11 @@ SELECT upper_inc(period '(2000-01-01,2000-01-02]'); SELECT upper_inc(period '[2000-01-01,2000-01-02)'); SELECT upper_inc(period '(2000-01-01,2000-01-02)'); -SELECT timespan(period '[2000-01-01,2000-01-01]'); -SELECT timespan(period '[2000-01-01,2000-01-02]'); -SELECT timespan(period '(2000-01-01,2000-01-02]'); -SELECT timespan(period '[2000-01-01,2000-01-02)'); -SELECT timespan(period '(2000-01-01,2000-01-02)'); +SELECT duration(period '[2000-01-01,2000-01-01]'); +SELECT duration(period '[2000-01-01,2000-01-02]'); +SELECT duration(period '(2000-01-01,2000-01-02]'); +SELECT duration(period '[2000-01-01,2000-01-02)'); +SELECT duration(period '(2000-01-01,2000-01-02)'); SELECT shift(period '[2000-01-01,2000-01-01]', '5 min'); SELECT shift(period '[2000-01-01,2000-01-02]', '5 min'); diff --git a/test/queries/01_period_tbl.test.sql b/test/queries/01_period_tbl.test.sql index 5de2f5bd04..42a75d6f42 100644 --- a/test/queries/01_period_tbl.test.sql +++ b/test/queries/01_period_tbl.test.sql @@ -36,11 +36,11 @@ DROP TABLE tbl_period_tmp; ------------------------------------------------------------------------------- -SELECT max(timespan(period(t, t + i))) FROM tbl_timestamptz, tbl_interval; -SELECT max(timespan(period(t, t + i, true, true))) FROM tbl_timestamptz, tbl_interval; -SELECT max(timespan(period(t, t + i, true, false))) FROM tbl_timestamptz, tbl_interval; -SELECT max(timespan(period(t, t + i, false, true))) FROM tbl_timestamptz, tbl_interval; -SELECT max(timespan(period(t, t + i, false, false))) FROM tbl_timestamptz, tbl_interval; +SELECT max(duration(period(t, t + i))) FROM tbl_timestamptz, tbl_interval; +SELECT max(duration(period(t, t + i, true, true))) FROM tbl_timestamptz, tbl_interval; +SELECT max(duration(period(t, t + i, true, false))) FROM tbl_timestamptz, tbl_interval; +SELECT max(duration(period(t, t + i, false, true))) FROM tbl_timestamptz, tbl_interval; +SELECT max(duration(period(t, t + i, false, false))) FROM tbl_timestamptz, tbl_interval; SELECT tstzrange(p) FROM tbl_period; SELECT period(r) FROM tbl_tstzrange; @@ -50,7 +50,7 @@ SELECT lower(p) FROM tbl_period; SELECT upper(p) FROM tbl_period; SELECT lower_inc(p) FROM tbl_period; SELECT upper_inc(p) FROM tbl_period; -SELECT timespan(p) FROM tbl_period; +SELECT duration(p) FROM tbl_period; SELECT shift(p, '5 min') FROM tbl_period; SELECT count(*) FROM tbl_period t1, tbl_period t2 WHERE period_cmp(t1.p, t2.p) = -1; diff --git a/test/queries/05_periodset.test.sql b/test/queries/05_periodset.test.sql index 629fc10633..ef5134a054 100644 --- a/test/queries/05_periodset.test.sql +++ b/test/queries/05_periodset.test.sql @@ -81,6 +81,13 @@ SELECT timespan(periodset '{[2000-01-01,2000-01-02),(2000-01-03,2000-01-04),(200 SELECT timespan(periodset '{(2000-01-01,2000-01-02),(2000-01-03,2000-01-04),(2000-01-05,2000-01-06]}'); SELECT timespan(periodset '{[2000-01-01,2000-01-02),(2000-01-03,2000-01-04),(2000-01-05,2000-01-06]}'); +SELECT duration(periodset '{[2000-01-01,2000-01-01]}'); +SELECT duration(periodset '{(2000-01-01,2000-01-02),(2000-01-02,2000-01-03),(2000-01-03,2000-01-04)}'); +SELECT duration(periodset '{(2000-01-01,2000-01-02),(2000-01-03,2000-01-04),(2000-01-05,2000-01-06)}'); +SELECT duration(periodset '{[2000-01-01,2000-01-02),(2000-01-03,2000-01-04),(2000-01-05,2000-01-06)}'); +SELECT duration(periodset '{(2000-01-01,2000-01-02),(2000-01-03,2000-01-04),(2000-01-05,2000-01-06]}'); +SELECT duration(periodset '{[2000-01-01,2000-01-02),(2000-01-03,2000-01-04),(2000-01-05,2000-01-06]}'); + SELECT numPeriods(periodset '{[2000-01-01,2000-01-01]}'); SELECT numPeriods(periodset '{(2000-01-01,2000-01-02),(2000-01-02,2000-01-03),(2000-01-03,2000-01-04)}'); SELECT numPeriods(periodset '{(2000-01-01,2000-01-02),(2000-01-03,2000-01-04),(2000-01-05,2000-01-06)}'); diff --git a/test/queries/05_periodset_tbl.test.sql b/test/queries/05_periodset_tbl.test.sql index 8e15fad2fe..33dc41979f 100644 --- a/test/queries/05_periodset_tbl.test.sql +++ b/test/queries/05_periodset_tbl.test.sql @@ -39,6 +39,7 @@ DROP TABLE tbl_periodset_tmp; SELECT memSize(ps) FROM tbl_periodset; SELECT period(ps) FROM tbl_periodset; SELECT timespan(ps) FROM tbl_periodset; +SELECT duration(ps) FROM tbl_periodset; SELECT numPeriods(ps) FROM tbl_periodset; SELECT startPeriod(ps) FROM tbl_periodset; diff --git a/test/queries/21_tbox.test.sql b/test/queries/21_tbox.test.sql index c06d79c7ae..371249fed5 100644 --- a/test/queries/21_tbox.test.sql +++ b/test/queries/21_tbox.test.sql @@ -69,7 +69,7 @@ SELECT tbox 'TBOX((, 2000-01-01), (, 2000-01-02))'::period; ------------------------------------------------------------------------------- SELECT ROUND(MAX(upper(b::floatrange) - lower(b::floatrange))::numeric, 6) FROM tbl_tbox; -SELECT MAX(timespan(b::period)) FROM tbl_tbox; +SELECT MAX(duration(b::period)) FROM tbl_tbox; ------------------------------------------------------------------------------- -- Accessor functions diff --git a/test/queries/22_temporal.test.sql b/test/queries/22_temporal.test.sql index 30cf3bd5c4..b1d9c63091 100644 --- a/test/queries/22_temporal.test.sql +++ b/test/queries/22_temporal.test.sql @@ -915,6 +915,25 @@ SELECT timespan(ttext '{AAA@2000-01-01, BBB@2000-01-02, AAA@2000-01-03}'); SELECT timespan(ttext '[AAA@2000-01-01, BBB@2000-01-02, AAA@2000-01-03]'); SELECT timespan(ttext '{[AAA@2000-01-01, BBB@2000-01-02, AAA@2000-01-03],[CCC@2000-01-04, CCC@2000-01-05]}'); +SELECT duration(tbool 't@2000-01-01'); +SELECT duration(tbool '{t@2000-01-01, f@2000-01-02, t@2000-01-03}'); +SELECT duration(tbool '[t@2000-01-01, f@2000-01-02, t@2000-01-03]'); +SELECT duration(tbool '{[t@2000-01-01, f@2000-01-02, t@2000-01-03],[t@2000-01-04, t@2000-01-05]}'); +SELECT duration(tint '1@2000-01-01'); +SELECT duration(tint '{1@2000-01-01, 2@2000-01-02, 1@2000-01-03}'); +SELECT duration(tint '[1@2000-01-01, 2@2000-01-02, 1@2000-01-03]'); +SELECT duration(tint '{[1@2000-01-01, 2@2000-01-02, 1@2000-01-03],[3@2000-01-04, 3@2000-01-05]}'); +SELECT duration(tfloat '1.5@2000-01-01'); +SELECT duration(tfloat '{1.5@2000-01-01, 2.5@2000-01-02, 1.5@2000-01-03}'); +SELECT duration(tfloat '[1.5@2000-01-01, 2.5@2000-01-02, 1.5@2000-01-03]'); +SELECT duration(tfloat 'Interp=Stepwise;[1.5@2000-01-01, 2.5@2000-01-02, 1.5@2000-01-03]'); +SELECT duration(tfloat '{[1.5@2000-01-01, 2.5@2000-01-02, 1.5@2000-01-03],[3.5@2000-01-04, 3.5@2000-01-05]}'); +SELECT duration(tfloat 'Interp=Stepwise;{[1.5@2000-01-01, 2.5@2000-01-02, 1.5@2000-01-03],[3.5@2000-01-04, 3.5@2000-01-05]}'); +SELECT duration(ttext 'AAA@2000-01-01'); +SELECT duration(ttext '{AAA@2000-01-01, BBB@2000-01-02, AAA@2000-01-03}'); +SELECT duration(ttext '[AAA@2000-01-01, BBB@2000-01-02, AAA@2000-01-03]'); +SELECT duration(ttext '{[AAA@2000-01-01, BBB@2000-01-02, AAA@2000-01-03],[CCC@2000-01-04, CCC@2000-01-05]}'); + SELECT period(tbool 't@2000-01-01'); SELECT period(tbool '{t@2000-01-01, f@2000-01-02, t@2000-01-03}'); SELECT period(tbool '[t@2000-01-01, f@2000-01-02, t@2000-01-03]'); diff --git a/test/queries/22_temporal_tbl.test.sql b/test/queries/22_temporal_tbl.test.sql index 3994a82e9b..b33a0c8c08 100644 --- a/test/queries/22_temporal_tbl.test.sql +++ b/test/queries/22_temporal_tbl.test.sql @@ -219,10 +219,10 @@ SELECT MAX(timespan(getTime(temp))) FROM tbl_tint; SELECT MAX(timespan(getTime(temp))) FROM tbl_tfloat; SELECT MAX(timespan(getTime(temp))) FROM tbl_ttext; -SELECT MAX(timespan(period(temp))) FROM tbl_tbool; -SELECT MAX(timespan(period(temp))) FROM tbl_tint; -SELECT MAX(timespan(period(temp))) FROM tbl_tfloat; -SELECT MAX(timespan(period(temp))) FROM tbl_ttext; +SELECT MAX(duration(period(temp))) FROM tbl_tbool; +SELECT MAX(duration(period(temp))) FROM tbl_tint; +SELECT MAX(duration(period(temp))) FROM tbl_tfloat; +SELECT MAX(duration(period(temp))) FROM tbl_ttext; SELECT MAX(timespan(temp)) FROM tbl_tbool; SELECT MAX(timespan(temp)) FROM tbl_tint;