• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

estebanzimanyi / MobilityDB / 13100369341

02 Feb 2025 01:18PM UTC coverage: 95.084% (-0.01%) from 95.097%
13100369341

push

github

web-flow
Add interpolation parameter to appendInstant (#648)

23 of 27 new or added lines in 4 files covered. (85.19%)

2 existing lines in 1 file now uncovered.

32511 of 34192 relevant lines covered (95.08%)

736293.08 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

95.81
/mobilitydb/src/general/temporal_aggfuncs.c
1
/*****************************************************************************
2
 *
3
 * This MobilityDB code is provided under The PostgreSQL License.
4
 * Copyright (c) 2016-2024, Université libre de Bruxelles and MobilityDB
5
 * contributors
6
 *
7
 * MobilityDB includes portions of PostGIS version 3 source code released
8
 * under the GNU General Public License (GPLv2 or later).
9
 * Copyright (c) 2001-2024, PostGIS contributors
10
 *
11
 * Permission to use, copy, modify, and distribute this software and its
12
 * documentation for any purpose, without fee, and without a written
13
 * agreement is hereby granted, provided that the above copyright notice and
14
 * this paragraph and the following two paragraphs appear in all copies.
15
 *
16
 * IN NO EVENT SHALL UNIVERSITE LIBRE DE BRUXELLES BE LIABLE TO ANY PARTY FOR
17
 * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING
18
 * LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION,
19
 * EVEN IF UNIVERSITE LIBRE DE BRUXELLES HAS BEEN ADVISED OF THE POSSIBILITY
20
 * OF SUCH DAMAGE.
21
 *
22
 * UNIVERSITE LIBRE DE BRUXELLES SPECIFICALLY DISCLAIMS ANY WARRANTIES,
23
 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
24
 * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON
25
 * AN "AS IS" BASIS, AND UNIVERSITE LIBRE DE BRUXELLES HAS NO OBLIGATIONS TO
26
 * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
27
 *
28
 *****************************************************************************/
29

30
/**
31
 * @file
32
 * @brief Aggregate functions for temporal types
33
 */
34

35
#include "general/temporal_aggfuncs.h"
36

37
/* C */
38
#include <assert.h>
39
/* PostgreSQL */
40
#include <postgres.h>
41
#include <utils/timestamp.h>
42
/* MEOS */
43
#include <meos.h>
44
#include <meos_internal.h>
45
#include "general/set.h"
46
#include "general/skiplist.h"
47
#include "general/span.h"
48
#include "general/tbool_boolops.h"
49
#include "general/tbox.h"
50
/* MobilityDB */
51
#include "pg_general/meos_catalog.h"
52
#include "pg_general/skiplist.h"
53

54
/*****************************************************************************
55
 * Generic aggregate functions for TInstant and TSequence
56
 *****************************************************************************/
57

58
/**
59
 * @brief Generic transition function for aggregating temporal values
60
 * @param[in] fcinfo Catalog information about the external function
61
 * @param[in] func Aggregate function
62
 * @param[in] crossings True if turning points are added in the segments
63
 */
64
static Datum
65
Temporal_tagg_transfn(FunctionCallInfo fcinfo, datum_func2 func,
16,248✔
66
  bool crossings)
67
{
68
  SkipList *state;
69
  INPUT_AGG_TRANS_STATE(fcinfo, state);
16,248✔
70
  Temporal *temp = PG_GETARG_TEMPORAL_P(1);
16,138✔
71
  store_fcinfo(fcinfo);
16,138✔
72
  SkipList *result = temporal_tagg_transfn(state, temp, func, crossings);
16,138✔
73
  PG_FREE_IF_COPY(temp, 1);
16,130✔
74
  PG_RETURN_TEMPORAL_P(result);
16,130✔
75
}
76

77
/**
78
 * @brief Generic combine function for aggregating temporal values
79
 * @param[in] fcinfo Catalog information about the external function
80
 * @param[in] func Function
81
 * @param[in] crossings True if turning points are added in the segments
82
 */
83
static Datum
84
Temporal_tagg_combinefn(FunctionCallInfo fcinfo, datum_func2 func,
76✔
85
  bool crossings)
86
{
87
  SkipList *state1, *state2;
88
  INPUT_AGG_COMB_STATE(fcinfo, state1, state2);
76✔
89
  store_fcinfo(fcinfo);
76✔
90
  PG_RETURN_SKIPLIST_P(temporal_tagg_combinefn(state1, state2, func,
76✔
91
    crossings));
92
}
93

94
PGDLLEXPORT Datum Temporal_tagg_finalfn(PG_FUNCTION_ARGS);
95
PG_FUNCTION_INFO_V1(Temporal_tagg_finalfn);
25✔
96
/**
97
 * @ingroup mobilitydb_temporal_agg
98
 * @brief Generic final function for temporal aggregation
99
 * @sqlfn tCount(), merge(), ...
100
 */
101
Datum
102
Temporal_tagg_finalfn(PG_FUNCTION_ARGS)
1,398✔
103
{
104
  MemoryContext ctx = set_aggregation_context(fcinfo);
1,398✔
105
  SkipList *state = (SkipList *) PG_GETARG_POINTER(0);
1,398✔
106
  unset_aggregation_context(ctx);
1,398✔
107
  Temporal *result = temporal_tagg_finalfn(state);
1,398✔
108
  if (! result)
1,398✔
109
    PG_RETURN_NULL();
×
110
  PG_RETURN_TEMPORAL_P(result);
1,398✔
111
}
112

113
/*****************************************************************************/
114

115
/**
116
 * @brief Transition function for aggregating temporal values that require a
117
 * transformation of each composing instant/sequence
118
 * @param[in] fcinfo Catalog information about the external function
119
 * @param[in] func Aggregate function
120
 * @param[in] crossings True if turning points are added in the segments
121
 * @param[in] transform Transform function
122
 */
123
Datum
124
Temporal_tagg_transform_transfn(FunctionCallInfo fcinfo, datum_func2 func,
1,614✔
125
  bool crossings, TInstant *(*transform)(const TInstant *))
126
{
127
  SkipList *state;
128
  INPUT_AGG_TRANS_STATE(fcinfo, state);
1,614✔
129
  Temporal *temp = PG_GETARG_TEMPORAL_P(1);
1,592✔
130
  store_fcinfo(fcinfo);
1,592✔
131
  state = temporal_tagg_transform_transfn(state, temp, func, crossings,
1,592✔
132
    transform);
133
  PG_FREE_IF_COPY(temp, 1);
1,592✔
134
  PG_RETURN_SKIPLIST_P(state);
1,592✔
135
}
136

137
/*****************************************************************************
138
 * Temporal count
139
 *****************************************************************************/
140

141
PGDLLEXPORT Datum Timestamptz_tcount_transfn(PG_FUNCTION_ARGS);
142
PG_FUNCTION_INFO_V1(Timestamptz_tcount_transfn);
2✔
143
/**
144
 * @ingroup mobilitydb_temporal_agg
145
 * @brief Transition function for temporal count aggregate of timestamptz values
146
 * @sqlfn tCount()
147
 */
148
Datum
149
Timestamptz_tcount_transfn(PG_FUNCTION_ARGS)
100✔
150
{
151
  SkipList *state;
152
  INPUT_AGG_TRANS_STATE(fcinfo, state);
100✔
153
  TimestampTz t = PG_GETARG_TIMESTAMPTZ(1);
99✔
154
  store_fcinfo(fcinfo);
99✔
155
  PG_RETURN_SKIPLIST_P(timestamptz_tcount_transfn(state, t));
99✔
156
}
157

158
PGDLLEXPORT Datum Tstzset_tcount_transfn(PG_FUNCTION_ARGS);
159
PG_FUNCTION_INFO_V1(Tstzset_tcount_transfn);
2✔
160
/**
161
 * @ingroup mobilitydb_temporal_agg
162
 * @brief Transition function for temporal count aggregate of timestamptz sets
163
 * @sqlfn tCount()
164
 */
165
Datum
166
Tstzset_tcount_transfn(PG_FUNCTION_ARGS)
106✔
167
{
168
  SkipList *state;
169
  INPUT_AGG_TRANS_STATE(fcinfo, state);
106✔
170
  Set *s = PG_GETARG_SET_P(1);
101✔
171
  store_fcinfo(fcinfo);
101✔
172
  state = tstzset_tcount_transfn(state, s);
101✔
173
  PG_FREE_IF_COPY(s, 1);
101✔
174
  PG_RETURN_SKIPLIST_P(state);
101✔
175
}
176

177
PGDLLEXPORT Datum Tstzspan_tcount_transfn(PG_FUNCTION_ARGS);
178
PG_FUNCTION_INFO_V1(Tstzspan_tcount_transfn);
2✔
179
/**
180
 * @ingroup mobilitydb_temporal_agg
181
 * @brief Transition function for temporal count aggregate of timestamptz spans
182
 * @sqlfn tCount()
183
 */
184
Datum
185
Tstzspan_tcount_transfn(PG_FUNCTION_ARGS)
106✔
186
{
187
  SkipList *state;
188
  INPUT_AGG_TRANS_STATE(fcinfo, state);
106✔
189
  Span *s = PG_GETARG_SPAN_P(1);
101✔
190
  store_fcinfo(fcinfo);
101✔
191
  PG_RETURN_SKIPLIST_P(tstzspan_tcount_transfn(state, s));
101✔
192
}
193

194
PGDLLEXPORT Datum Tstzspanset_tcount_transfn(PG_FUNCTION_ARGS);
195
PG_FUNCTION_INFO_V1(Tstzspanset_tcount_transfn);
2✔
196
/**
197
 * @ingroup mobilitydb_temporal_agg
198
 * @brief Transition function for temporal count aggregate of timestamptz span
199
 * sets
200
 * @sqlfn tCount()
201
 */
202
Datum
203
Tstzspanset_tcount_transfn(PG_FUNCTION_ARGS)
106✔
204
{
205
  SkipList *state;
206
  INPUT_AGG_TRANS_STATE(fcinfo, state);
106✔
207
  SpanSet *ss = PG_GETARG_SPANSET_P(1);
101✔
208
  store_fcinfo(fcinfo);
101✔
209
  state = tstzspanset_tcount_transfn(state, ss);
101✔
210
  PG_FREE_IF_COPY(ss, 1);
101✔
211
  PG_RETURN_SKIPLIST_P(state);
101✔
212
}
213

214
/*****************************************************************************/
215

216
PGDLLEXPORT Datum Temporal_tcount_transfn(PG_FUNCTION_ARGS);
217
PG_FUNCTION_INFO_V1(Temporal_tcount_transfn);
67✔
218
/**
219
 * @ingroup mobilitydb_temporal_agg
220
 * @brief Transition function for temporal count aggregation of temporal values
221
 * @sqlfn tCount()
222
 */
223
Datum
224
Temporal_tcount_transfn(PG_FUNCTION_ARGS)
6,524✔
225
{
226
  SkipList *state;
227
  INPUT_AGG_TRANS_STATE(fcinfo, state);
6,524✔
228
  Temporal *temp = PG_GETARG_TEMPORAL_P(1);
6,480✔
229
  store_fcinfo(fcinfo);
6,480✔
230
  state = temporal_tcount_transfn(state, temp);
6,480✔
231
  PG_FREE_IF_COPY(temp, 1);
6,480✔
232
  PG_RETURN_SKIPLIST_P(state);
6,480✔
233
}
234

235
PGDLLEXPORT Datum Temporal_tcount_combinefn(PG_FUNCTION_ARGS);
236
PG_FUNCTION_INFO_V1(Temporal_tcount_combinefn);
3✔
237
/**
238
 * @ingroup mobilitydb_temporal_agg
239
 * @brief Combine function for temporal count aggregation of temporal values
240
 * @sqlfn tCount()
241
 */
242
Datum
243
Temporal_tcount_combinefn(PG_FUNCTION_ARGS)
28✔
244
{
245
  return Temporal_tagg_combinefn(fcinfo, &datum_sum_int32, false);
28✔
246
}
247

248
/*****************************************************************************
249
 * Temporal extent
250
 *****************************************************************************/
251

252
PGDLLEXPORT Datum Temporal_extent_transfn(PG_FUNCTION_ARGS);
253
PG_FUNCTION_INFO_V1(Temporal_extent_transfn);
23✔
254
/**
255
 * @ingroup mobilitydb_temporal_agg
256
 * @brief Transition function for extent aggregation of temporal booleans and
257
 * temporal texts
258
 * @sqlfn extent()
259
 */
260
Datum
261
Temporal_extent_transfn(PG_FUNCTION_ARGS)
1,002✔
262
{
263
  Span *s = PG_ARGISNULL(0) ? NULL : PG_GETARG_SPAN_P(0);
1,002✔
264
  Temporal *temp = PG_ARGISNULL(1) ? NULL : PG_GETARG_TEMPORAL_P(1);
1,002✔
265
  Span *result = temporal_extent_transfn(s, temp);
1,002✔
266
  PG_FREE_IF_COPY(temp, 1);
1,002✔
267
  if (! result)
1,002✔
268
    PG_RETURN_NULL();
9✔
269
  PG_RETURN_SPAN_P(result);
993✔
270
}
271

272
/*****************************************************************************/
273

274
PGDLLEXPORT Datum Tnumber_extent_transfn(PG_FUNCTION_ARGS);
275
PG_FUNCTION_INFO_V1(Tnumber_extent_transfn);
24✔
276
/**
277
 * @ingroup mobilitydb_temporal_agg
278
 * @brief Transition function for extent aggregation for temporal numbers
279
 * @sqlfn extent()
280
 */
281
Datum
282
Tnumber_extent_transfn(PG_FUNCTION_ARGS)
1,006✔
283
{
284
  TBox *box = PG_ARGISNULL(0) ? NULL : PG_GETARG_TBOX_P(0);
1,006✔
285
  Temporal *temp = PG_ARGISNULL(1) ? NULL : PG_GETARG_TEMPORAL_P(1);
1,006✔
286
  TBox *result = tnumber_extent_transfn(box, temp);
1,006✔
287
  PG_FREE_IF_COPY(temp, 1);
1,006✔
288
  if (! result)
1,006✔
289
    PG_RETURN_NULL();
10✔
290
  PG_RETURN_TBOX_P(result);
996✔
291
}
292

293
/*****************************************************************************
294
 * Temporal boolean functions
295
 *****************************************************************************/
296

297
PGDLLEXPORT Datum Tbool_tand_transfn(PG_FUNCTION_ARGS);
298
PG_FUNCTION_INFO_V1(Tbool_tand_transfn);
10✔
299
/**
300
 * @ingroup mobilitydb_temporal_agg
301
 * @brief Transition function for temporal and aggregation of temporal booleans
302
 * @sqlfn tAnd()
303
 */
304
Datum
305
Tbool_tand_transfn(PG_FUNCTION_ARGS)
806✔
306
{
307
  return Temporal_tagg_transfn(fcinfo, &datum_and, CROSSINGS_NO);
806✔
308
}
309

310
PGDLLEXPORT Datum Tbool_tand_combinefn(PG_FUNCTION_ARGS);
311
PG_FUNCTION_INFO_V1(Tbool_tand_combinefn);
2✔
312
/**
313
 * @ingroup mobilitydb_temporal_agg
314
 * @brief Combine function for temporal and aggregation of temporal booleans
315
 * @sqlfn tAnd()
316
 */
317
Datum
318
Tbool_tand_combinefn(PG_FUNCTION_ARGS)
4✔
319
{
320
  return Temporal_tagg_combinefn(fcinfo, &datum_and, CROSSINGS_NO);
4✔
321
}
322

323
PGDLLEXPORT Datum Tbool_tor_transfn(PG_FUNCTION_ARGS);
324
PG_FUNCTION_INFO_V1(Tbool_tor_transfn);
10✔
325
/**
326
 * @ingroup mobilitydb_temporal_agg
327
 * @brief Transition function for temporal or aggregation of temporal booleans
328
 * @sqlfn tOr()
329
 */
330
Datum
331
Tbool_tor_transfn(PG_FUNCTION_ARGS)
806✔
332
{
333
  return Temporal_tagg_transfn(fcinfo, &datum_or, CROSSINGS_NO);
806✔
334
}
335

336
PGDLLEXPORT Datum Tbool_tor_combinefn(PG_FUNCTION_ARGS);
337
PG_FUNCTION_INFO_V1(Tbool_tor_combinefn);
2✔
338
/**
339
 * @ingroup mobilitydb_temporal_agg
340
 * @brief Combine function for temporal or aggregation of temporal booleans
341
 * @sqlfn tOr()
342
 */
343
Datum
344
Tbool_tor_combinefn(PG_FUNCTION_ARGS)
4✔
345
{
346
  return Temporal_tagg_combinefn(fcinfo, &datum_or, CROSSINGS_NO);
4✔
347
}
348

349
/*****************************************************************************/
350

351
PGDLLEXPORT Datum Tint_tmin_transfn(PG_FUNCTION_ARGS);
352
PG_FUNCTION_INFO_V1(Tint_tmin_transfn);
10✔
353
/**
354
 * @ingroup mobilitydb_temporal_agg
355
 * @brief Transition function for temporal minimum aggregation of temporal
356
 * integers
357
 * @sqlfn tMin()
358
 */
359
Datum
360
Tint_tmin_transfn(PG_FUNCTION_ARGS)
806✔
361
{
362
  return Temporal_tagg_transfn(fcinfo, &datum_min_int32, CROSSINGS_NO);
806✔
363
}
364

365
PGDLLEXPORT Datum Tint_tmin_combinefn(PG_FUNCTION_ARGS);
366
PG_FUNCTION_INFO_V1(Tint_tmin_combinefn);
2✔
367
/**
368
 * @ingroup mobilitydb_temporal_agg
369
 * @brief Combine function for temporal minimum aggregation of temporal
370
 * integers
371
 * @sqlfn tMin()
372
 */
373
Datum
374
Tint_tmin_combinefn(PG_FUNCTION_ARGS)
4✔
375
{
376
  return Temporal_tagg_combinefn(fcinfo, &datum_min_int32, CROSSINGS_NO);
4✔
377
}
378

379
PGDLLEXPORT Datum Tfloat_tmin_transfn(PG_FUNCTION_ARGS);
380
PG_FUNCTION_INFO_V1(Tfloat_tmin_transfn);
10✔
381
/**
382
 * @ingroup mobilitydb_temporal_agg
383
 * @brief Transition function for temporal minimum aggregation of temporal
384
 * floats
385
 * @sqlfn tMin()
386
 */
387
Datum
388
Tfloat_tmin_transfn(PG_FUNCTION_ARGS)
808✔
389
{
390
  return Temporal_tagg_transfn(fcinfo, &datum_min_float8, CROSSINGS);
808✔
391
}
392

393
PGDLLEXPORT Datum Tfloat_tmin_combinefn(PG_FUNCTION_ARGS);
394
PG_FUNCTION_INFO_V1(Tfloat_tmin_combinefn);
2✔
395
/**
396
 * @ingroup mobilitydb_temporal_agg
397
 * @brief Combine function for temporal minimum aggregation of temporal floats
398
 * @sqlfn tMin()
399
 */
400
Datum
401
Tfloat_tmin_combinefn(PG_FUNCTION_ARGS)
4✔
402
{
403
  return Temporal_tagg_combinefn(fcinfo, &datum_min_float8, CROSSINGS);
4✔
404
}
405

406
PGDLLEXPORT Datum Tint_tmax_transfn(PG_FUNCTION_ARGS);
407
PG_FUNCTION_INFO_V1(Tint_tmax_transfn);
10✔
408
/**
409
 * @ingroup mobilitydb_temporal_agg
410
 * @brief Transition function for temporal maximum aggregation of temporal
411
 * integers
412
 * @sqlfn tMax()
413
 */
414
Datum
415
Tint_tmax_transfn(PG_FUNCTION_ARGS)
806✔
416
{
417
  return Temporal_tagg_transfn(fcinfo, &datum_max_int32, CROSSINGS_NO);
806✔
418
}
419

420
PGDLLEXPORT Datum Tint_tmax_combinefn(PG_FUNCTION_ARGS);
421
PG_FUNCTION_INFO_V1(Tint_tmax_combinefn);
2✔
422
/**
423
 * @ingroup mobilitydb_temporal_agg
424
 * @brief Combine function for temporal maximum aggregation of temporal
425
 * integers
426
 * @sqlfn tMax()
427
 */
428
Datum
429
Tint_tmax_combinefn(PG_FUNCTION_ARGS)
4✔
430
{
431
  return Temporal_tagg_combinefn(fcinfo, &datum_max_int32, CROSSINGS_NO);
4✔
432
}
433

434
PGDLLEXPORT Datum Tfloat_tmax_transfn(PG_FUNCTION_ARGS);
435
PG_FUNCTION_INFO_V1(Tfloat_tmax_transfn);
10✔
436
/**
437
 * @ingroup mobilitydb_temporal_agg
438
 * @brief Transition function for temporal maximum aggregation of temporal
439
 * floats
440
 * @sqlfn tMax()
441
 */
442
Datum
443
Tfloat_tmax_transfn(PG_FUNCTION_ARGS)
808✔
444
{
445
  return Temporal_tagg_transfn(fcinfo, &datum_max_float8, CROSSINGS);
808✔
446
}
447

448
PGDLLEXPORT Datum Tfloat_tmax_combinefn(PG_FUNCTION_ARGS);
449
PG_FUNCTION_INFO_V1(Tfloat_tmax_combinefn);
2✔
450
/**
451
 * @ingroup mobilitydb_temporal_agg
452
 * @brief Combine function for temporal maximum aggregation of temporal floats
453
 * values
454
 * @sqlfn tMax()
455
 */
456
Datum
457
Tfloat_tmax_combinefn(PG_FUNCTION_ARGS)
4✔
458
{
459
  return Temporal_tagg_combinefn(fcinfo, &datum_max_float8, CROSSINGS);
4✔
460
}
461

462
PGDLLEXPORT Datum Tint_tsum_transfn(PG_FUNCTION_ARGS);
463
PG_FUNCTION_INFO_V1(Tint_tsum_transfn);
10✔
464
/**
465
 * @ingroup mobilitydb_temporal_agg
466
 * @brief Transition function for temporal sum aggregation of temporal integers
467
 * @sqlfn tSum()
468
 */
469
Datum
470
Tint_tsum_transfn(PG_FUNCTION_ARGS)
806✔
471
{
472
  return Temporal_tagg_transfn(fcinfo, &datum_sum_int32, CROSSINGS_NO);
806✔
473
}
474

475
PGDLLEXPORT Datum Tint_tsum_combinefn(PG_FUNCTION_ARGS);
476
PG_FUNCTION_INFO_V1(Tint_tsum_combinefn);
2✔
477
/**
478
 * @ingroup mobilitydb_temporal_agg
479
 * @brief Combine function for temporal sum aggregation of temporal integers
480
 * @sqlfn tSum()
481
 */
482
Datum
483
Tint_tsum_combinefn(PG_FUNCTION_ARGS)
4✔
484
{
485
  return Temporal_tagg_combinefn(fcinfo, &datum_sum_int32, CROSSINGS_NO);
4✔
486
}
487

488
PGDLLEXPORT Datum Tfloat_tsum_transfn(PG_FUNCTION_ARGS);
489
PG_FUNCTION_INFO_V1(Tfloat_tsum_transfn);
10✔
490
/**
491
 * @ingroup mobilitydb_temporal_agg
492
 * @brief Transition function for temporal sum aggregation of temporal floats
493
 * @sqlfn tSum()
494
 */
495
Datum
496
Tfloat_tsum_transfn(PG_FUNCTION_ARGS)
820✔
497
{
498
  return Temporal_tagg_transfn(fcinfo, &datum_sum_float8, CROSSINGS_NO);
820✔
499
}
500

501
PGDLLEXPORT Datum Tfloat_tsum_combinefn(PG_FUNCTION_ARGS);
502
PG_FUNCTION_INFO_V1(Tfloat_tsum_combinefn);
2✔
503
/**
504
 * @ingroup mobilitydb_temporal_agg
505
 * @brief Combine function for temporal sum aggregation of temporal floats
506
 * @sqlfn tSum()
507
 */
508
Datum
509
Tfloat_tsum_combinefn(PG_FUNCTION_ARGS)
4✔
510
{
511
  return Temporal_tagg_combinefn(fcinfo, &datum_sum_float8, CROSSINGS_NO);
4✔
512
}
513

514
/*****************************************************************************/
515

516
PGDLLEXPORT Datum Ttext_tmin_transfn(PG_FUNCTION_ARGS);
517
PG_FUNCTION_INFO_V1(Ttext_tmin_transfn);
10✔
518
/**
519
 * @ingroup mobilitydb_temporal_agg
520
 * @brief Transition function for temporal minimum aggregation of temporal texts
521
 * @sqlfn tMin()
522
 */
523
Datum
524
Ttext_tmin_transfn(PG_FUNCTION_ARGS)
804✔
525
{
526
  return Temporal_tagg_transfn(fcinfo, &datum_min_text, CROSSINGS_NO);
804✔
527
}
528

529
PGDLLEXPORT Datum Ttext_tmin_combinefn(PG_FUNCTION_ARGS);
530
PG_FUNCTION_INFO_V1(Ttext_tmin_combinefn);
2✔
531
/**
532
 * @ingroup mobilitydb_temporal_agg
533
 * @brief Combine function for temporal minimum aggregation of temporal texts
534
 * @sqlfn tMin()
535
 */
536
Datum
537
Ttext_tmin_combinefn(PG_FUNCTION_ARGS)
4✔
538
{
539
  return Temporal_tagg_combinefn(fcinfo, &datum_min_text, CROSSINGS_NO);
4✔
540
}
541

542
PGDLLEXPORT Datum Ttext_tmax_transfn(PG_FUNCTION_ARGS);
543
PG_FUNCTION_INFO_V1(Ttext_tmax_transfn);
10✔
544
/**
545
 * @ingroup mobilitydb_temporal_agg
546
 * @brief Transition function for temporal maximum aggregation of temporal texts
547
 * @sqlfn tMax()
548
 */
549
Datum
550
Ttext_tmax_transfn(PG_FUNCTION_ARGS)
804✔
551
{
552
  return Temporal_tagg_transfn(fcinfo, &datum_max_text, CROSSINGS_NO);
804✔
553
}
554

555
PGDLLEXPORT Datum Ttext_tmax_combinefn(PG_FUNCTION_ARGS);
556
PG_FUNCTION_INFO_V1(Ttext_tmax_combinefn);
2✔
557
/**
558
 * @ingroup mobilitydb_temporal_agg
559
 * @brief Combine function for temporal maximum aggregation of temporal texts
560
 * @sqlfn tMax()
561
 */
562
Datum
563
Ttext_tmax_combinefn(PG_FUNCTION_ARGS)
4✔
564
{
565
  return Temporal_tagg_combinefn(fcinfo, &datum_max_text, CROSSINGS_NO);
4✔
566
}
567

568
/*****************************************************************************
569
 * Temporal average
570
 *****************************************************************************/
571

572
PGDLLEXPORT Datum Tnumber_tavg_transfn(PG_FUNCTION_ARGS);
573
PG_FUNCTION_INFO_V1(Tnumber_tavg_transfn);
20✔
574
/**
575
 * @ingroup mobilitydb_temporal_agg
576
 * @brief Transition function for temporal average aggregation of temporal
577
 * numbers
578
 * @sqlfn tAvg()
579
 */
580
Datum
581
Tnumber_tavg_transfn(PG_FUNCTION_ARGS)
1,614✔
582
{
583
  return Temporal_tagg_transform_transfn(fcinfo, &datum_sum_double2,
1,614✔
584
    CROSSINGS_NO, &tnumberinst_transform_tavg);
585
}
586

587
PGDLLEXPORT Datum Tnumber_tavg_combinefn(PG_FUNCTION_ARGS);
588
PG_FUNCTION_INFO_V1(Tnumber_tavg_combinefn);
2✔
589
/**
590
 * @ingroup mobilitydb_temporal_agg
591
 * @brief Combine function for temporal average aggregation of temporal
592
 * numbers
593
 * @sqlfn tAvg()
594
 */
595
Datum
596
Tnumber_tavg_combinefn(PG_FUNCTION_ARGS)
8✔
597
{
598
  return Temporal_tagg_combinefn(fcinfo, &datum_sum_double2, false);
8✔
599
}
600

601
PGDLLEXPORT Datum Tnumber_tavg_finalfn(PG_FUNCTION_ARGS);
602
PG_FUNCTION_INFO_V1(Tnumber_tavg_finalfn);
5✔
603
/**
604
 * @ingroup mobilitydb_temporal_agg
605
 * @brief Final function for temporal average aggregation of temporal
606
 * numbers
607
 * @sqlfn tAvg()
608
 */
609
Datum
610
Tnumber_tavg_finalfn(PG_FUNCTION_ARGS)
101✔
611
{
612
  SkipList *state = (SkipList *) PG_GETARG_POINTER(0);
101✔
613
  Temporal *result = tnumber_tavg_finalfn(state);
101✔
614
  if (! result)
101✔
615
    PG_RETURN_NULL();
×
616
  PG_RETURN_TEMPORAL_P(result);
101✔
617
}
618

619
/*****************************************************************************/
620

621
PGDLLEXPORT Datum Temporal_merge_transfn(PG_FUNCTION_ARGS);
622
PG_FUNCTION_INFO_V1(Temporal_merge_transfn);
12✔
623
/**
624
 * @ingroup mobilitydb_temporal_agg
625
 * @brief Transition function for merge aggregate of temporal values
626
 * @sqlfn merge()
627
 */
628
Datum
629
Temporal_merge_transfn(PG_FUNCTION_ARGS)
8,174✔
630
{
631
  return Temporal_tagg_transfn(fcinfo, NULL, CROSSINGS_NO);
8,174✔
632
}
633

634
PGDLLEXPORT Datum Temporal_merge_combinefn(PG_FUNCTION_ARGS);
635
PG_FUNCTION_INFO_V1(Temporal_merge_combinefn);
1✔
636
/**
637
 * @ingroup mobilitydb_temporal_agg
638
 * @brief Combine function for merge aggregate of temporal values
639
 * @sqlfn merge()
640
 */
641
Datum
642
Temporal_merge_combinefn(PG_FUNCTION_ARGS)
×
643
{
644
  return Temporal_tagg_combinefn(fcinfo, NULL, CROSSINGS_NO);
×
645
}
646

647
/*****************************************************************************
648
 * Append aggregate functions
649
 *****************************************************************************/
650

651
PGDLLEXPORT Datum Temporal_app_tinst_transfn(PG_FUNCTION_ARGS);
652
PG_FUNCTION_INFO_V1(Temporal_app_tinst_transfn);
37✔
653
/**
654
 * @ingroup mobilitydb_temporal_agg
655
 * @brief Transition function for append temporal instant aggregate
656
 * @sqlfn appendInstant()
657
 */
658
Datum
659
Temporal_app_tinst_transfn(PG_FUNCTION_ARGS)
241,455✔
660
{
661
  MemoryContext ctx = set_aggregation_context(fcinfo);
241,455✔
662
  Temporal *state = PG_ARGISNULL(0) ? NULL : PG_GETARG_TEMPORAL_P(0);
241,455✔
663
  if (PG_ARGISNULL(1))
241,455✔
664
  {
UNCOV
665
    if (state)
×
UNCOV
666
      PG_RETURN_TEMPORAL_P(state);
×
667
    else
668
      PG_RETURN_NULL();
×
669
  }
670
  Temporal *inst = PG_GETARG_TEMPORAL_P(1);
241,455✔
671
  unset_aggregation_context(ctx);
241,455✔
672
  /* Store fcinfo into a global variable */
673
  store_fcinfo(fcinfo);
241,455✔
674

675
  /* Get interpolation */
676
  interpType interp;
677
  if (PG_NARGS() == 2 || PG_ARGISNULL(2))
241,455✔
678
  {
679
    /* Set default interpolation according to the base type */
680
    meosType temptype = oid_type(get_fn_expr_argtype(fcinfo->flinfo, 1));
204,901✔
681
    interp = temptype_continuous(temptype) ? LINEAR : STEP;
204,901✔
682
  }
683
  else
684
  {
685
    /* Input interpolation */
686
    text *interp_txt = PG_GETARG_TEXT_P(2);
36,554✔
687
    char *interp_str = text2cstring(interp_txt);    
36,554✔
688
    interp = interptype_from_string(interp_str);
36,554✔
689
    pfree(interp_str);
36,554✔
690
  }
691

692
  /* Take into account the arguments for the gaps */
693
  double maxdist = -1.0;
694
  Interval *maxt = NULL;
695
  if (PG_NARGS() > 3)
241,455✔
696
  {
697
    /* Get the maxt and maxdist for the gaps if they are given */
698
    if (PG_NARGS() == 4)
50✔
699
    {
700
      if (! PG_ARGISNULL(3))
5✔
701
        maxt = PG_GETARG_INTERVAL_P(3);
5✔
702
    }
703
    else /* PG_NARGS() == 5 */
704
    {
705
      if (! PG_ARGISNULL(3))
45✔
706
        maxdist = PG_GETARG_FLOAT8(3);
35✔
707
      if (! PG_ARGISNULL(4))
45✔
708
        maxt = PG_GETARG_INTERVAL_P(4);
15✔
709
    }
710
  }
711

712
  state = temporal_app_tinst_transfn(state, (TInstant *) inst, interp, 
241,455✔
713
    maxdist, maxt);
714
  PG_FREE_IF_COPY(inst, 1);
241,452✔
715
  PG_RETURN_TEMPORAL_P(state);
241,452✔
716
}
717

718
PGDLLEXPORT Datum Temporal_app_tseq_transfn(PG_FUNCTION_ARGS);
719
PG_FUNCTION_INFO_V1(Temporal_app_tseq_transfn);
13✔
720
/**
721
 * @ingroup mobilitydb_temporal_agg
722
 * @brief Transition function for append temporal sequence aggregate
723
 * @sqlfn appendSequence()
724
 */
725
Datum
726
Temporal_app_tseq_transfn(PG_FUNCTION_ARGS)
73,102✔
727
{
728
  MemoryContext ctx = set_aggregation_context(fcinfo);
73,102✔
729
  Temporal *state = PG_ARGISNULL(0) ? NULL : PG_GETARG_TEMPORAL_P(0);
73,102✔
730
  if (PG_ARGISNULL(1))
73,102✔
731
  {
732
    if (state)
1✔
733
      PG_RETURN_TEMPORAL_P(state);
1✔
734
    else
735
      PG_RETURN_NULL();
×
736
  }
737
  unset_aggregation_context(ctx);
73,101✔
738
  Temporal *seq = PG_GETARG_TEMPORAL_P(1);
73,101✔
739
  /* Store fcinfo into a global variable */
740
  store_fcinfo(fcinfo);
73,101✔
741
  state = temporal_app_tseq_transfn(state, (TSequence *) seq);
73,101✔
742
  PG_FREE_IF_COPY(seq, 1);
73,101✔
743
  PG_RETURN_TEMPORAL_P(state);
73,101✔
744
}
745

746
PGDLLEXPORT Datum Temporal_append_finalfn(PG_FUNCTION_ARGS);
747
PG_FUNCTION_INFO_V1(Temporal_append_finalfn);
15✔
748
/**
749
 * @ingroup mobilitydb_temporal_agg
750
 * @brief Final function for append temporal instant/sequence aggregate
751
 * @sqlfn appendInstant(), appendSequence()
752
 */
753
Datum
754
Temporal_append_finalfn(PG_FUNCTION_ARGS)
65✔
755
{
756
  MemoryContext ctx = set_aggregation_context(fcinfo);
65✔
757
  Temporal *state = PG_GETARG_TEMPORAL_P(0);
65✔
758
  unset_aggregation_context(ctx);
65✔
759
  Temporal *result = temporal_compact(state);
65✔
760
  if (! result)
65✔
761
    PG_RETURN_NULL();
×
762
  PG_RETURN_TEMPORAL_P(result);
65✔
763
}
764

765
/*****************************************************************************/
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc