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

estebanzimanyi / MobilityDB / 7043445544

29 Nov 2023 06:30PM UTC coverage: 94.978% (-0.2%) from 95.145%
7043445544

push

github

web-flow
Add date set/span/spanset types (#399)

268 of 336 new or added lines in 17 files covered. (79.76%)

9 existing lines in 5 files now uncovered.

30695 of 32318 relevant lines covered (94.98%)

861807.14 hits per line

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

98.08
/mobilitydb/src/general/span.c
1
/*****************************************************************************
2
 *
3
 * This MobilityDB code is provided under The PostgreSQL License.
4
 * Copyright (c) 2016-2023, 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-2023, 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 General functions for spans (a.k.a. ranges) composed of two `Datum`
33
 * values and two Boolean values stating whether the bounds are inclusive.
34
 */
35

36
#include "general/span.h"
37

38
/* C */
39
#include <assert.h>
40
/* PostgreSQL */
41
#include <postgres.h>
42
#include <catalog/pg_type_d.h>
43
#include <libpq/pqformat.h>
44
#include <utils/rangetypes.h>
45
#include <utils/timestamp.h>
46
/* MEOS */
47
#include <meos.h>
48
#include <meos_internal.h>
49
#include "general/tnumber_mathfuncs.h"
50
#include "general/type_out.h"
51
#include "general/type_util.h"
52
/* MobilityDB */
53
#include "pg_general/meos_catalog.h"
54
#include "pg_general/type_util.h"
55

56
/*****************************************************************************
57
 * Input/output functions
58
 *****************************************************************************/
59

60
PGDLLEXPORT Datum Span_in(PG_FUNCTION_ARGS);
61
PG_FUNCTION_INFO_V1(Span_in);
68✔
62
/**
63
 * @ingroup mobilitydb_setspan_inout
64
 * @brief Input function for periods
65
 * @sqlfunc span_in()
66
 */
67
Datum
68
Span_in(PG_FUNCTION_ARGS)
34,532✔
69
{
70
  const char *input = PG_GETARG_CSTRING(0);
34,532✔
71
  Oid spantypid = PG_GETARG_OID(1);
34,532✔
72
  Span *result = span_in(input, oid_type(spantypid));
34,532✔
73
  PG_RETURN_POINTER(result);
34,527✔
74
}
75

76
PGDLLEXPORT Datum Span_out(PG_FUNCTION_ARGS);
77
PG_FUNCTION_INFO_V1(Span_out);
43✔
78
/**
79
 * @ingroup mobilitydb_setspan_inout
80
 * @brief Output function for periods
81
 * @sqlfunc span_out()
82
 */
83
Datum
84
Span_out(PG_FUNCTION_ARGS)
229✔
85
{
86
  Span *s = PG_GETARG_SPAN_P(0);
229✔
87
  PG_RETURN_CSTRING(span_out(s, Int32GetDatum(OUT_DEFAULT_DECIMAL_DIGITS)));
229✔
88
}
89

90
PGDLLEXPORT Datum Span_recv(PG_FUNCTION_ARGS);
91
PG_FUNCTION_INFO_V1(Span_recv);
9✔
92
/**
93
 * @ingroup mobilitydb_setspan_inout
94
 * @brief Generic receive function for spans
95
 * @sqlfunc span_recv()
96
 */
97
Datum
98
Span_recv(PG_FUNCTION_ARGS)
396✔
99
{
100
  StringInfo buf = (StringInfo) PG_GETARG_POINTER(0);
396✔
101
  Span *result = span_from_wkb((uint8_t *) buf->data, buf->len);
396✔
102
  /* Set cursor to the end of buffer (so the backend is happy) */
103
  buf->cursor = buf->len;
396✔
104
  PG_RETURN_POINTER(result);
396✔
105
}
106

107
PGDLLEXPORT Datum Span_send(PG_FUNCTION_ARGS);
108
PG_FUNCTION_INFO_V1(Span_send);
9✔
109
/*
110
 * @ingroup mobilitydb_setspan_inout
111
 * @brief Generic send function for spans
112
 * @sqlfunc span_send()
113
 */
114
Datum
115
Span_send(PG_FUNCTION_ARGS)
396✔
116
{
117
  Span *span = PG_GETARG_SPAN_P(0);
396✔
118
  uint8_t variant = 0;
119
  size_t wkb_size = VARSIZE_ANY_EXHDR(span);
396✔
120
  uint8_t *wkb = span_as_wkb(span, variant, &wkb_size);
396✔
121
  bytea *result = bstring2bytea(wkb, wkb_size);
396✔
122
  pfree(wkb);
396✔
123
  PG_FREE_IF_COPY(span, 0);
396✔
124
  PG_RETURN_BYTEA_P(result);
396✔
125
}
126

127
/*****************************************************************************
128
 * Output in WKT format
129
 *****************************************************************************/
130

131
PGDLLEXPORT Datum Span_as_text(PG_FUNCTION_ARGS);
132
PG_FUNCTION_INFO_V1(Span_as_text);
6✔
133
/**
134
 * @ingroup mobilitydb_setspan_inout
135
 * @brief Output function for spans
136
 * @sqlfunc asText()
137
 */
138
Datum
139
Span_as_text(PG_FUNCTION_ARGS)
2✔
140
{
141
  Span *s = PG_GETARG_SPAN_P(0);
2✔
142
  int dbl_dig_for_wkt = OUT_DEFAULT_DECIMAL_DIGITS;
143
  if (PG_NARGS() > 1 && ! PG_ARGISNULL(1))
2✔
144
    dbl_dig_for_wkt = PG_GETARG_INT32(1);
2✔
145
  char *str = span_out(s, Int32GetDatum(dbl_dig_for_wkt));
2✔
146
  text *result = cstring2text(str);
1✔
147
  pfree(str);
1✔
148
  PG_RETURN_TEXT_P(result);
1✔
149
}
150

151
/*****************************************************************************
152
 * Constructor functions
153
 *****************************************************************************/
154

155
PGDLLEXPORT Datum Span_constructor(PG_FUNCTION_ARGS);
156
PG_FUNCTION_INFO_V1(Span_constructor);
8✔
157
/**
158
 * @ingroup mobilitydb_setspan_constructor
159
 * @brief Construct a span from the four arguments
160
 * @sqlfunc intspan(), bigintspan(), floatspan(), period()
161
 */
162
Datum
163
Span_constructor(PG_FUNCTION_ARGS)
49,101✔
164
{
165
  Datum lower = PG_GETARG_DATUM(0);
49,101✔
166
  Datum upper = PG_GETARG_DATUM(1);
49,101✔
167
  bool lower_inc = PG_GETARG_BOOL(2);
49,101✔
168
  bool upper_inc = PG_GETARG_BOOL(3);
49,101✔
169
  meosType spantype = oid_type(get_fn_expr_rettype(fcinfo->flinfo));
49,101✔
170
  meosType basetype = spantype_basetype(spantype);
49,101✔
171
  Span *span;
172
  span = span_make(lower, upper, lower_inc, upper_inc, basetype);
49,101✔
173
  PG_RETURN_SPAN_P(span);
49,099✔
174
}
175

176
/*****************************************************************************
177
 * Conversion functions
178
 *****************************************************************************/
179

180
PGDLLEXPORT Datum Value_to_span(PG_FUNCTION_ARGS);
181
PG_FUNCTION_INFO_V1(Value_to_span);
9✔
182
/**
183
 * @ingroup mobilitydb_setspan_conversion
184
 * @brief Convert a value as a span
185
 * @sqlfunc span()
186
 * @sqlop @p ::
187
 */
188
Datum
189
Value_to_span(PG_FUNCTION_ARGS)
105✔
190
{
191
  Datum d = PG_GETARG_DATUM(0);
105✔
192
  meosType basetype = oid_type(get_fn_expr_argtype(fcinfo->flinfo, 0));
105✔
193
  Span *result = value_to_span(d, basetype);
105✔
194
  PG_RETURN_POINTER(result);
105✔
195
}
196

197
PGDLLEXPORT Datum Datespan_to_tstzspan(PG_FUNCTION_ARGS);
198
PG_FUNCTION_INFO_V1(Datespan_to_tstzspan);
2✔
199
/**
200
 * @ingroup mobilitydb_setspan_conversion
201
 * @brief Convert a date span as a timestamptz span
202
 * @sqlfunc tstzspan()
203
 * @sqlop @p ::
204
 */
205
Datum
206
Datespan_to_tstzspan(PG_FUNCTION_ARGS)
198✔
207
{
208
  Span *s = PG_GETARG_SPAN_P(0);
198✔
209
  Span *result = palloc(sizeof(Span));
198✔
210
  datespan_set_tstzspan(s, result);
198✔
211
  PG_RETURN_POINTER(result);
198✔
212
}
213

214
PGDLLEXPORT Datum Tstzspan_to_datespan(PG_FUNCTION_ARGS);
215
PG_FUNCTION_INFO_V1(Tstzspan_to_datespan);
2✔
216
/**
217
 * @ingroup mobilitydb_setspan_conversion
218
 * @brief Convert a timestamptz span as a date span
219
 * @sqlfunc datespan()
220
 * @sqlop @p ::
221
 */
222
Datum
223
Tstzspan_to_datespan(PG_FUNCTION_ARGS)
198✔
224
{
225
  Span *s = PG_GETARG_SPAN_P(0);
198✔
226
  Span *result = palloc(sizeof(Span));
198✔
227
  tstzspan_set_datespan(s, result);
198✔
228
  PG_RETURN_POINTER(result);
198✔
229
}
230

231
PGDLLEXPORT Datum Span_to_range(PG_FUNCTION_ARGS);
232
PG_FUNCTION_INFO_V1(Span_to_range);
7✔
233
/**
234
 * @ingroup mobilitydb_setspan_conversion
235
 * @brief Convert a span as a range value
236
 * @sqlfunc int4range(), tstzrange()
237
 * @sqlop @p ::
238
 */
239
Datum
240
Span_to_range(PG_FUNCTION_ARGS)
208✔
241
{
242
  Span *span = PG_GETARG_SPAN_P(0);
208✔
243
  assert(span->basetype == T_INT4 || span->basetype == T_DATE ||
244
    span->basetype == T_TIMESTAMPTZ);
245
  RangeType *range;
246
  range = range_make(span->lower, span->upper, span->lower_inc,
208✔
247
    span->upper_inc, span->basetype);
208✔
248
  PG_RETURN_POINTER(range);
208✔
249
}
250

251
/**
252
 * @brief Convert a PostgreSQL range value as a span value
253
 */
254
void
255
range_set_span(RangeType *range, TypeCacheEntry *typcache, Span *result)
2,051✔
256
{
257
  char flags = range_get_flags(range);
2,051✔
258
  if (flags & RANGE_EMPTY)
2,051✔
259
    ereport(ERROR, (errcode(ERRCODE_DATA_EXCEPTION),
1✔
260
      errmsg("Range cannot be empty")));
261
  if ((flags & RANGE_LB_INF) || (flags & RANGE_UB_INF))
2,050✔
262
    ereport(ERROR, (errcode(ERRCODE_DATA_EXCEPTION),
2✔
263
      errmsg("Range bounds cannot be infinite")));
264

265
  RangeBound lower, upper;
266
  bool empty;
267
  range_deserialize(typcache, range, &lower, &upper, &empty);
2,048✔
268
  meosType basetype;
269
  Oid type_id = typcache->rngelemtype->type_id;
2,048✔
270
  assert(type_id == INT4OID || type_id == DATEOID || type_id == TIMESTAMPTZOID);
271
  if (type_id == INT4OID)
2,048✔
272
    basetype = T_INT4;
273
  else if (type_id == DATEOID)
1,335✔
274
    basetype = T_DATE;
275
  else /* type_id == TIMESTAMPTZOID */
276
    basetype = T_TIMESTAMPTZ;
277
  span_set(lower.val, upper.val, lower.inclusive, upper.inclusive, basetype,
2,048✔
278
    result);
279
  return;
2,048✔
280
}
281

282
PGDLLEXPORT Datum Range_to_span(PG_FUNCTION_ARGS);
283
PG_FUNCTION_INFO_V1(Range_to_span);
6✔
284
/**
285
 * @ingroup mobilitydb_setspan_conversion
286
 * @brief Convert a PostgreSQL range value as a span value
287
 * @sqlfunc intspan(), tstzspan()
288
 * @sqlop @p ::
289
 */
290
Datum
291
Range_to_span(PG_FUNCTION_ARGS)
112✔
292
{
293
  RangeType *range = PG_GETARG_RANGE_P(0);
112✔
294
  TypeCacheEntry *typcache = range_get_typcache(fcinfo, RangeTypeGetOid(range));
112✔
295
  assert(typcache->rngelemtype->type_id == INT4OID ||
296
    typcache->rngelemtype->type_id == DATEOID ||
297
    typcache->rngelemtype->type_id == TIMESTAMPTZOID);
298
  Span *result = palloc(sizeof(Span));
112✔
299
  range_set_span(range, typcache, result);
112✔
300
  PG_RETURN_POINTER(result);
109✔
301
}
302

303
/*****************************************************************************
304
 * Accessor functions
305
 *****************************************************************************/
306

307
/* span -> timestamptz functions */
308

309
PGDLLEXPORT Datum Span_lower(PG_FUNCTION_ARGS);
310
PG_FUNCTION_INFO_V1(Span_lower);
21✔
311
/**
312
 * @ingroup mobilitydb_setspan_accessor
313
 * @brief Return the lower bound value
314
 * @sqlfunc lower()
315
 */
316
Datum
317
Span_lower(PG_FUNCTION_ARGS)
3,951,986✔
318
{
319
  Span *s = PG_GETARG_SPAN_P(0);
3,951,986✔
320
  PG_RETURN_DATUM(s->lower);
3,951,986✔
321
}
322

323
PGDLLEXPORT Datum Span_upper(PG_FUNCTION_ARGS);
324
PG_FUNCTION_INFO_V1(Span_upper);
10✔
325
/**
326
 * @ingroup mobilitydb_setspan_accessor
327
 * @brief Return the upper bound value
328
 * @sqlfunc upper()
329
 */
330
Datum
331
Span_upper(PG_FUNCTION_ARGS)
401✔
332
{
333
  Span *s = PG_GETARG_SPAN_P(0);
401✔
334
  PG_RETURN_DATUM(s->upper);
401✔
335
}
336

337
/* span -> bool functions */
338

339
PGDLLEXPORT Datum Span_lower_inc(PG_FUNCTION_ARGS);
340
PG_FUNCTION_INFO_V1(Span_lower_inc);
9✔
341
/**
342
 * @ingroup mobilitydb_setspan_accessor
343
 * @brief Return true if the lower bound value is inclusive
344
 * @sqlfunc lower_inc()
345
 */
346
Datum
347
Span_lower_inc(PG_FUNCTION_ARGS)
302✔
348
{
349
  Span *s = PG_GETARG_SPAN_P(0);
302✔
350
  PG_RETURN_BOOL(s->lower_inc != 0);
302✔
351
}
352

353
PGDLLEXPORT Datum Span_upper_inc(PG_FUNCTION_ARGS);
354
PG_FUNCTION_INFO_V1(Span_upper_inc);
9✔
355
/**
356
 * @ingroup mobilitydb_setspan_accessor
357
 * @brief Return true if the upper bound value is inclusive
358
 * @sqlfunc lower_inc()
359
 */
360
Datum
361
Span_upper_inc(PG_FUNCTION_ARGS)
302✔
362
{
363
  Span *s = PG_GETARG_SPAN_P(0);
302✔
364
  PG_RETURN_BOOL(s->upper_inc != 0);
302✔
365
}
366

367
PGDLLEXPORT Datum Span_width(PG_FUNCTION_ARGS);
368
PG_FUNCTION_INFO_V1(Span_width);
5✔
369
/**
370
 * @ingroup mobilitydb_setspan_accessor
371
 * @brief Return the width of a numeric span
372
 * @sqlfunc width()
373
 */
374
Datum
375
Span_width(PG_FUNCTION_ARGS)
198✔
376
{
377
  Span *s = PG_GETARG_SPAN_P(0);
198✔
378
  double result = span_width(s);
198✔
379
  PG_RETURN_FLOAT8(result);
198✔
380
}
381

382
PGDLLEXPORT Datum Datespan_duration(PG_FUNCTION_ARGS);
383
PG_FUNCTION_INFO_V1(Datespan_duration);
1✔
384
/**
385
 * @ingroup mobilitydb_setspan_accessor
386
 * @brief Return the duration of the date span
387
 * @sqlfunc duration()
388
 */
389
Datum
NEW
390
Datespan_duration(PG_FUNCTION_ARGS)
×
391
{
NEW
392
  Span *s = PG_GETARG_SPAN_P(0);
×
NEW
393
  Interval *result = datespan_duration(s);
×
NEW
394
  PG_RETURN_POINTER(result);
×
395
}
396

397
PGDLLEXPORT Datum Tstzspan_duration(PG_FUNCTION_ARGS);
398
PG_FUNCTION_INFO_V1(Tstzspan_duration);
7✔
399
/**
400
 * @ingroup mobilitydb_setspan_accessor
401
 * @brief Return the duration of the timestamptz duration
402
 * @sqlfunc duration()
403
 */
404
Datum
405
Tstzspan_duration(PG_FUNCTION_ARGS)
50,092✔
406
{
407
  Span *s = PG_GETARG_SPAN_P(0);
50,092✔
408
  Interval *result = tstzspan_duration(s);
50,092✔
409
  PG_RETURN_POINTER(result);
50,092✔
410
}
411

412
/*****************************************************************************
413
 * Transformation functions
414
 *****************************************************************************/
415

416
PGDLLEXPORT Datum Numspan_shift(PG_FUNCTION_ARGS);
417
PG_FUNCTION_INFO_V1(Numspan_shift);
7✔
418
/**
419
 * @ingroup mobilitydb_setspan_transf
420
 * @brief Shift the number span by the value
421
 * @sqlfunc shift()
422
 */
423
Datum
424
Numspan_shift(PG_FUNCTION_ARGS)
29,404✔
425
{
426
  Span *s = PG_GETARG_SPAN_P(0);
29,404✔
427
  Datum shift = PG_GETARG_DATUM(1);
29,404✔
428
  Span *result = numspan_shift_scale(s, shift, 0, true, false);
29,404✔
429
  PG_RETURN_POINTER(result);
29,404✔
430
}
431

432
PGDLLEXPORT Datum Tstzspan_shift(PG_FUNCTION_ARGS);
433
PG_FUNCTION_INFO_V1(Tstzspan_shift);
4✔
434
/**
435
 * @ingroup mobilitydb_setspan_transf
436
 * @brief Shift the period value by the interval
437
 * @sqlfunc shift()
438
 */
439
Datum
440
Tstzspan_shift(PG_FUNCTION_ARGS)
10,004✔
441
{
442
  Span *s = PG_GETARG_SPAN_P(0);
10,004✔
443
  Interval *shift = PG_GETARG_INTERVAL_P(1);
10,004✔
444
  Span *result = tstzspan_shift_scale(s, shift, NULL);
10,004✔
445
  PG_RETURN_POINTER(result);
10,004✔
446
}
447

448
PGDLLEXPORT Datum Numspan_scale(PG_FUNCTION_ARGS);
449
PG_FUNCTION_INFO_V1(Numspan_scale);
6✔
450
/**
451
 * @ingroup mobilitydb_setspan_transf
452
 * @brief Scale the number span by the value
453
 * @sqlfunc scale()
454
 */
455
Datum
456
Numspan_scale(PG_FUNCTION_ARGS)
29,304✔
457
{
458
  Span *s = PG_GETARG_SPAN_P(0);
29,304✔
459
  Datum duration = PG_GETARG_DATUM(1);
29,304✔
460
  Span *result = numspan_shift_scale(s, 0, duration, false, true);
29,304✔
461
  PG_RETURN_POINTER(result);
29,304✔
462
}
463

464
PGDLLEXPORT Datum Tstzspan_scale(PG_FUNCTION_ARGS);
465
PG_FUNCTION_INFO_V1(Tstzspan_scale);
3✔
466
/**
467
 * @ingroup mobilitydb_setspan_transf
468
 * @brief Scale the period value by the interval
469
 * @sqlfunc scale()
470
 */
471
Datum
472
Tstzspan_scale(PG_FUNCTION_ARGS)
9,806✔
473
{
474
  Span *s = PG_GETARG_SPAN_P(0);
9,806✔
475
  Interval *duration = PG_GETARG_INTERVAL_P(1);
9,806✔
476
  Span *result = tstzspan_shift_scale(s, NULL, duration);
9,806✔
477
  PG_RETURN_POINTER(result);
9,806✔
478
}
479

480
PGDLLEXPORT Datum Numspan_shift_scale(PG_FUNCTION_ARGS);
481
PG_FUNCTION_INFO_V1(Numspan_shift_scale);
9✔
482
/**
483
 * @ingroup mobilitydb_setspan_transf
484
 * @brief Shift and scale the number span by the values
485
 * @sqlfunc shiftScale()
486
 */
487
Datum
488
Numspan_shift_scale(PG_FUNCTION_ARGS)
2,901,096✔
489
{
490
  Span *s = PG_GETARG_SPAN_P(0);
2,901,096✔
491
  Datum shift = PG_GETARG_DATUM(1);
2,901,096✔
492
  Datum duration = PG_GETARG_DATUM(2);
2,901,096✔
493
  Span *result = numspan_shift_scale(s, shift, duration, true, true);
2,901,096✔
494
  PG_RETURN_POINTER(result);
2,901,096✔
495
}
496

497
PGDLLEXPORT Datum Tstzspan_shift_scale(PG_FUNCTION_ARGS);
498
PG_FUNCTION_INFO_V1(Tstzspan_shift_scale);
4✔
499
/**
500
 * @ingroup mobilitydb_setspan_transf
501
 * @brief Shift and scale the period value by the intervals
502
 * @sqlfunc shiftScale()
503
 */
504
Datum
505
Tstzspan_shift_scale(PG_FUNCTION_ARGS)
970,304✔
506
{
507
  Span *s = PG_GETARG_SPAN_P(0);
970,304✔
508
  Interval *shift = PG_GETARG_INTERVAL_P(1);
970,304✔
509
  Interval *duration = PG_GETARG_INTERVAL_P(2);
970,304✔
510
  Span *result = tstzspan_shift_scale(s, shift, duration);
970,304✔
511
  PG_RETURN_POINTER(result);
970,304✔
512
}
513

514
PGDLLEXPORT Datum Floatspan_round(PG_FUNCTION_ARGS);
515
PG_FUNCTION_INFO_V1(Floatspan_round);
4✔
516
/**
517
 * @ingroup mobilitydb_setspan_transf
518
 * @brief Set the precision of the float span to the number of decimal places
519
 * @sqlfunc round()
520
 */
521
Datum
522
Floatspan_round(PG_FUNCTION_ARGS)
5✔
523
{
524
  Span *span = PG_GETARG_SPAN_P(0);
5✔
525
  int maxdd = PG_GETARG_INT32(1);
5✔
526
  Span *result = floatspan_round(span, maxdd);
5✔
527
  PG_RETURN_POINTER(result);
5✔
528
}
529

530
/*****************************************************************************
531
 * Btree support
532
 *****************************************************************************/
533

534
PGDLLEXPORT Datum Span_eq(PG_FUNCTION_ARGS);
535
PG_FUNCTION_INFO_V1(Span_eq);
13✔
536
/**
537
 * @ingroup mobilitydb_setspan_comp
538
 * @brief Return true if the first span is equal to the second one
539
 * @sqlfunc span_eq()
540
 * @sqlop @p =
541
 */
542
Datum
543
Span_eq(PG_FUNCTION_ARGS)
489✔
544
{
545
  Span *s1 = PG_GETARG_SPAN_P(0);
489✔
546
  Span *s2 = PG_GETARG_SPAN_P(1);
489✔
547
  PG_RETURN_BOOL(span_eq(s1, s2));
489✔
548
}
549

550
PGDLLEXPORT Datum Span_ne(PG_FUNCTION_ARGS);
551
PG_FUNCTION_INFO_V1(Span_ne);
12✔
552
/**
553
 * @ingroup mobilitydb_setspan_comp
554
 * @brief Return true if the first span is different from the second one
555
 * @sqlfunc span_ne()
556
 * @sqlop @p <>
557
 */
558
Datum
559
Span_ne(PG_FUNCTION_ARGS)
1,486✔
560
{
561
  Span *s1 = PG_GETARG_SPAN_P(0);
1,486✔
562
  Span *s2 = PG_GETARG_SPAN_P(1);
1,486✔
563
  PG_RETURN_BOOL(span_ne(s1, s2));
1,486✔
564
}
565

566
PGDLLEXPORT Datum Span_cmp(PG_FUNCTION_ARGS);
567
PG_FUNCTION_INFO_V1(Span_cmp);
19✔
568
/**
569
 * @ingroup mobilitydb_setspan_comp
570
 * @brief Return -1, 0, or 1 depending on whether the first span
571
 * is less than, equal, or greater than the second one
572
 * @sqlfunc span_cmp()
573
 */
574
Datum
575
Span_cmp(PG_FUNCTION_ARGS)
9,911✔
576
{
577
  Span *s1 = PG_GETARG_SPAN_P(0);
9,911✔
578
  Span *s2 = PG_GETARG_SPAN_P(1);
9,911✔
579
  PG_RETURN_INT32(span_cmp(s1, s2));
9,911✔
580
}
581

582
PGDLLEXPORT Datum Span_lt(PG_FUNCTION_ARGS);
583
PG_FUNCTION_INFO_V1(Span_lt);
9✔
584
/**
585
 * @ingroup mobilitydb_setspan_comp
586
 * @brief Return true if the first span is less than the second one
587
 * @sqlfunc span_lt()
588
 * @sqlop @p <
589
 */
590
Datum
591
Span_lt(PG_FUNCTION_ARGS)
19,801✔
592
{
593
  Span *s1 = PG_GETARG_SPAN_P(0);
19,801✔
594
  Span *s2 = PG_GETARG_SPAN_P(1);
19,801✔
595
  PG_RETURN_BOOL(span_lt(s1, s2));
19,801✔
596
}
597

598
PGDLLEXPORT Datum Span_le(PG_FUNCTION_ARGS);
599
PG_FUNCTION_INFO_V1(Span_le);
9✔
600
/**
601
 * @ingroup mobilitydb_setspan_comp
602
 * @brief Return true if the first span is less than or equal to the second one
603
 * @sqlfunc span_le()
604
 * @sqlop @p <=
605
 */
606
Datum
607
Span_le(PG_FUNCTION_ARGS)
19,801✔
608
{
609
  Span *s1 = PG_GETARG_SPAN_P(0);
19,801✔
610
  Span *s2 = PG_GETARG_SPAN_P(1);
19,801✔
611
  PG_RETURN_BOOL(span_le(s1, s2));
19,801✔
612
}
613

614
PGDLLEXPORT Datum Span_ge(PG_FUNCTION_ARGS);
615
PG_FUNCTION_INFO_V1(Span_ge);
9✔
616
/**
617
 * @ingroup mobilitydb_setspan_comp
618
 * @brief Return true if the first span is greater than or equal to the second one
619
 * @sqlfunc span_ge()
620
 * @sqlop @p >=
621
 */
622
Datum
623
Span_ge(PG_FUNCTION_ARGS)
19,801✔
624
{
625
  Span *s1 = PG_GETARG_SPAN_P(0);
19,801✔
626
  Span *s2 = PG_GETARG_SPAN_P(1);
19,801✔
627
  PG_RETURN_BOOL(span_ge(s1, s2));
19,801✔
628
}
629

630
PGDLLEXPORT Datum Span_gt(PG_FUNCTION_ARGS);
631
PG_FUNCTION_INFO_V1(Span_gt);
9✔
632
/**
633
 * @ingroup mobilitydb_setspan_comp
634
 * @brief Return true if the first span is greater than the second one
635
 * @sqlfunc span_gt()
636
 * @sqlop @p >
637
 */
638
Datum
639
Span_gt(PG_FUNCTION_ARGS)
19,801✔
640
{
641
  Span *s1 = PG_GETARG_SPAN_P(0);
19,801✔
642
  Span *s2 = PG_GETARG_SPAN_P(1);
19,801✔
643
  PG_RETURN_BOOL(span_gt(s1, s2));
19,801✔
644
}
645

646
/*****************************************************************************
647
 * Hash support
648
 *****************************************************************************/
649

650
PGDLLEXPORT Datum Span_hash(PG_FUNCTION_ARGS);
651
PG_FUNCTION_INFO_V1(Span_hash);
18✔
652
/**
653
 * @ingroup mobilitydb_setspan_accessor
654
 * @brief Return the 32-bit hash value of a span.
655
 * @sqlfunc span_hash()
656
 */
657
Datum
658
Span_hash(PG_FUNCTION_ARGS)
697✔
659
{
660
  Span *s = PG_GETARG_SPAN_P(0);
697✔
661
  uint32 result = span_hash(s);
697✔
662
  PG_RETURN_UINT32(result);
697✔
663
}
664

665
PGDLLEXPORT Datum Span_hash_extended(PG_FUNCTION_ARGS);
666
PG_FUNCTION_INFO_V1(Span_hash_extended);
7✔
667
/**
668
 * @ingroup mobilitydb_setspan_accessor
669
 * @brief Return the 64-bit hash value of a span obtained with a seed.
670
 * @sqlfunc hash_extended()
671
 */
672
Datum
673
Span_hash_extended(PG_FUNCTION_ARGS)
103✔
674
{
675
  Span *s = PG_GETARG_SPAN_P(0);
103✔
676
  uint64 seed = PG_GETARG_INT64(1);
103✔
677
  uint64 result = span_hash_extended(s, seed);
103✔
678
  PG_RETURN_UINT64(result);
103✔
679
}
680

681
/******************************************************************************/
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