-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdatum_comparator.c
122 lines (83 loc) · 2.35 KB
/
datum_comparator.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#include <postgres.h>
#include <utils/datum.h>
#include <string.h>
#include <utils/timestamp.h>
#include "datum_comparator.h"
int cmp_dimension_id_int16(const void *left, const void *right) {
const Datum datuml = *(Datum *) left;
const Datum datumr = *(Datum *) right;
int16 vall = DatumGetInt16(datuml);
int16 valr = DatumGetInt16(datumr);
if (vall < valr)
return -1;
if (vall > valr)
return 1;
return 0;
}
int cmp_dimension_id_int32(const void *left, const void *right) {
const Datum datuml = *(Datum *) left;
const Datum datumr = *(Datum *) right;
int32 vall = DatumGetInt32(datuml);
int32 valr = DatumGetInt32(datumr);
if (vall < valr)
return -1;
if (vall > valr)
return 1;
return 0;
}
int cmp_dimension_id_int64(const void *left, const void *right) {
const Datum datuml = *(Datum *) left;
const Datum datumr = *(Datum *) right;
int64 vall = DatumGetInt64(datuml);
int64 valr = DatumGetInt64(datumr);
if (vall < valr)
return -1;
if (vall > valr)
return 1;
return 0;
}
int cmp_dimension_id_float4(const void *left, const void *right) {
const Datum datuml = *(Datum *) left;
const Datum datumr = *(Datum *) right;
float4 vall = DatumGetFloat4(datuml);
float4 valr = DatumGetFloat4(datumr);
if (vall < valr)
return -1;
if (vall > valr)
return 1;
return 0;
}
int cmp_dimension_id_float8(const void *left, const void *right) {
const Datum datuml = *(Datum *) left;
const Datum datumr = *(Datum *) right;
float8 vall = DatumGetFloat8(datuml);
float8 valr = DatumGetFloat8(datumr);
if (vall < valr)
return -1;
if (vall > valr)
return 1;
return 0;
}
int cmp_dimension_id_timestamptz(const void *left, const void *right) {
const Datum datuml = *(Datum *) left;
const Datum datumr = *(Datum *) right;
TimestampTz ts1 = DatumGetTimestampTz(datuml);
TimestampTz ts2 = DatumGetTimestampTz(datumr);
if (ts1 < ts2)
return -1;
if (ts1 > ts2)
return 1;
return 0;
}
int cmp_dimension_id_varchar(const void *left, const void *right) {
const Datum datuml = *(Datum *) left;
const Datum datumr = *(Datum *) right;
bytea *vall = (bytea *) DatumGetPointer(datuml);
bytea *valr = (bytea *) DatumGetPointer(datumr);
char *str1 = VARDATA_ANY(vall);
char *str2 = VARDATA_ANY(valr);
/*Null terminate C strings*/
str1[VARSIZE_ANY_EXHDR(vall)] = '\0';
str2[VARSIZE_ANY_EXHDR(valr)] = '\0';
return strcmp(str1, str2);
}