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

taosdata / TDengine / #4473

08 Jul 2025 09:38AM UTC coverage: 62.922% (+0.7%) from 62.22%
#4473

push

travis-ci

web-flow
Merge pull request #31712 from taosdata/merge/mainto3.0

merge: from main to 3.0 branch

158525 of 321496 branches covered (49.31%)

Branch coverage included in aggregate %.

56 of 60 new or added lines in 13 files covered. (93.33%)

1333 existing lines in 67 files now uncovered.

245526 of 320647 relevant lines covered (76.57%)

17689640.25 hits per line

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

59.39
/source/util/src/tcompare.c
1
/*
2
 * Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
3
 *
4
 * This program is free software: you can use, redistribute, and/or modify
5
 * it under the terms of the GNU Affero General Public License, version 3
6
 * or later ("AGPL"), as published by the Free Software Foundation.
7
 *
8
 * This program is distributed in the hope that it will be useful, but WITHOUT
9
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10
 * FITNESS FOR A PARTICULAR PURPOSE.
11
 *
12
 * You should have received a copy of the GNU Affero General Public License
13
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
14
 */
15
#define _BSD_SOURCE
16
#define _GNU_SOURCE
17
#define _XOPEN_SOURCE
18
#define _DEFAULT_SOURCE
19
#include "tcompare.h"
20
#include "regex.h"
21
#include "tdef.h"
22
#include "thash.h"
23
#include "tlog.h"
24
#include "tutil.h"
25
#include "types.h"
26
#include "osString.h"
27
#include "ttimer.h"
28
#include "decimal.h"
29

30
int32_t setChkInBytes1(const void *pLeft, const void *pRight) {
40,498,380✔
31
  return NULL != taosHashGet((SHashObj *)pRight, pLeft, 1) ? 1 : 0;
40,498,380✔
32
}
33

34
int32_t setChkInBytes2(const void *pLeft, const void *pRight) {
6✔
35
  return NULL != taosHashGet((SHashObj *)pRight, pLeft, 2) ? 1 : 0;
6✔
36
}
37

38
int32_t setChkInBytes4(const void *pLeft, const void *pRight) {
10,306✔
39
  return NULL != taosHashGet((SHashObj *)pRight, pLeft, 4) ? 1 : 0;
10,306✔
40
}
41

42
int32_t setChkInBytes8(const void *pLeft, const void *pRight) {
170,999,705✔
43
  return NULL != taosHashGet((SHashObj *)pRight, pLeft, 8) ? 1 : 0;
170,999,705✔
44
}
45

46
int32_t setChkNotInBytes1(const void *pLeft, const void *pRight) {
330✔
47
  return NULL == taosHashGet((SHashObj *)pRight, pLeft, 1) ? 1 : 0;
330✔
48
}
49

50
int32_t setChkNotInBytes2(const void *pLeft, const void *pRight) {
6✔
51
  return NULL == taosHashGet((SHashObj *)pRight, pLeft, 2) ? 1 : 0;
6✔
52
}
53

54
int32_t setChkNotInBytes4(const void *pLeft, const void *pRight) {
10,036✔
55
  return NULL == taosHashGet((SHashObj *)pRight, pLeft, 4) ? 1 : 0;
10,036✔
56
}
57

58
int32_t setChkNotInBytes8(const void *pLeft, const void *pRight) {
1,746,089✔
59
  return NULL == taosHashGet((SHashObj *)pRight, pLeft, 8) ? 1 : 0;
1,746,089✔
60
}
61

62
int32_t setChkInDecimalHash(const void* pLeft, const void* pRight) {
496,210✔
63
  const SDecimalCompareCtx *pCtxL = pLeft, *pCtxR = pRight;
496,210✔
64
  return NULL != taosHashGet((SHashObj *)(pCtxR->pData), pCtxL->pData, tDataTypes[pCtxL->type].bytes) ? 1 : 0;
496,210✔
65
}
66

67
int32_t setChkNotInDecimalHash(const void* pLeft, const void* pRight) {
499,508✔
68
  const SDecimalCompareCtx *pCtxL = pLeft, *pCtxR = pRight;
499,508✔
69
  return NULL == taosHashGet((SHashObj *)(pCtxR->pData), pCtxL->pData, tDataTypes[pCtxL->type].bytes) ? 1 : 0;
499,508✔
70
}
71

72
int32_t compareChkInString(const void *pLeft, const void *pRight) {
890,242✔
73
  return NULL != taosHashGet((SHashObj *)pRight, pLeft, varDataTLen(pLeft)) ? 1 : 0;
890,242✔
74
}
75

76
int32_t compareChkNotInString(const void *pLeft, const void *pRight) {
41,353✔
77
  return NULL == taosHashGet((SHashObj *)pRight, pLeft, varDataTLen(pLeft)) ? 1 : 0;
41,353✔
78
}
79

80
int32_t compareInt8Val(const void *pLeft, const void *pRight) {
2,147,483,647✔
81
  int8_t left = GET_INT8_VAL(pLeft), right = GET_INT8_VAL(pRight);
2,147,483,647✔
82
  if (left > right) return 1;
2,147,483,647✔
83
  if (left < right) return -1;
2,147,483,647✔
84
  return 0;
2,147,483,647✔
85
}
86

87
int32_t compareInt8ValDesc(const void *pLeft, const void *pRight) { return compareInt8Val(pRight, pLeft); }
4,904✔
88

89
int32_t compareInt16Val(const void *pLeft, const void *pRight) {
2,147,483,647✔
90
  int16_t left = GET_INT16_VAL(pLeft), right = GET_INT16_VAL(pRight);
2,147,483,647✔
91
  if (left > right) return 1;
2,147,483,647✔
92
  if (left < right) return -1;
2,147,483,647✔
93
  return 0;
2,147,483,647✔
94
}
95

96
int32_t compareInt16ValDesc(const void *pLeft, const void *pRight) { return compareInt16Val(pRight, pLeft); }
4,914✔
97

98
int32_t compareInt32Val(const void *pLeft, const void *pRight) {
498,596,851✔
99
  int32_t left = GET_INT32_VAL(pLeft), right = GET_INT32_VAL(pRight);
498,596,851✔
100
  if (left > right) return 1;
498,596,851✔
101
  if (left < right) return -1;
415,861,606✔
102
  return 0;
300,616,728✔
103
}
104

105
int32_t compareInt32ValDesc(const void *pLeft, const void *pRight) { return compareInt32Val(pRight, pLeft); }
4,462,562✔
106

107
int32_t compareInt64Val(const void *pLeft, const void *pRight) {
2,147,483,647✔
108
  int64_t left = GET_INT64_VAL(pLeft), right = GET_INT64_VAL(pRight);
2,147,483,647✔
109
  if (left > right) return 1;
2,147,483,647✔
110
  if (left < right) return -1;
1,831,864,349✔
111
  return 0;
235,202,247✔
112
}
113

114
int32_t compareInt64ValDesc(const void *pLeft, const void *pRight) { return compareInt64Val(pRight, pLeft); }
845,357,097✔
115

116
int32_t compareUint32Val(const void *pLeft, const void *pRight) {
2,096,707✔
117
  uint32_t left = GET_UINT32_VAL(pLeft), right = GET_UINT32_VAL(pRight);
2,096,707✔
118
  if (left > right) return 1;
2,096,707✔
119
  if (left < right) return -1;
1,156,099✔
120
  return 0;
544,267✔
121
}
122

123
int32_t compareUint32ValDesc(const void *pLeft, const void *pRight) { return compareUint32Val(pRight, pLeft); }
1,093,338✔
124

125
int32_t compareUint64Val(const void *pLeft, const void *pRight) {
2,511,554✔
126
  uint64_t left = GET_UINT64_VAL(pLeft), right = GET_UINT64_VAL(pRight);
2,511,554✔
127
  if (left > right) return 1;
2,511,554✔
128
  if (left < right) return -1;
1,314,298✔
129
  return 0;
586,206✔
130
}
131

132
int32_t compareUint64ValDesc(const void *pLeft, const void *pRight) { return compareUint64Val(pRight, pLeft); }
1,150,992✔
133

134
int32_t compareUint16Val(const void *pLeft, const void *pRight) {
1,281,694✔
135
  uint16_t left = GET_UINT16_VAL(pLeft), right = GET_UINT16_VAL(pRight);
1,281,694✔
136
  if (left > right) return 1;
1,281,694✔
137
  if (left < right) return -1;
1,278,407✔
138
  return 0;
1,726✔
139
}
140

141
int32_t compareUint16ValDesc(const void *pLeft, const void *pRight) { return compareUint16Val(pRight, pLeft); }
×
142

143
int32_t compareUint8Val(const void *pLeft, const void *pRight) {
8,986✔
144
  uint8_t left = GET_UINT8_VAL(pLeft), right = GET_UINT8_VAL(pRight);
8,986✔
145
  if (left > right) return 1;
8,986✔
146
  if (left < right) return -1;
6,155✔
147
  return 0;
3,028✔
148
}
149

150
int32_t compareUint8ValDesc(const void *pLeft, const void *pRight) { return compareUint8Val(pRight, pLeft); }
×
151

152
int32_t compareFloatVal(const void *pLeft, const void *pRight) {
115,048,060✔
153
  float p1 = GET_FLOAT_VAL(pLeft);
115,048,060✔
154
  float p2 = GET_FLOAT_VAL(pRight);
115,048,060✔
155

156
  if (isnan(p1) && isnan(p2)) {
115,048,060!
157
    return 0;
×
158
  }
159

160
  if (isnan(p1)) {
115,048,060!
161
    return -1;
×
162
  }
163

164
  if (isnan(p2)) {
115,048,060!
165
    return 1;
×
166
  }
167
  if (FLT_EQUAL(p1, p2)) {
115,048,060✔
168
    return 0;
66,283,536✔
169
  }
170
  return FLT_GREATER(p1, p2) ? 1 : -1;
48,764,524!
171
}
172

173
int32_t compareFloatValDesc(const void *pLeft, const void *pRight) { return compareFloatVal(pRight, pLeft); }
5,209✔
174

175
int32_t compareDoubleVal(const void *pLeft, const void *pRight) {
193,017,924✔
176
  double p1 = GET_DOUBLE_VAL(pLeft);
193,017,924✔
177
  double p2 = GET_DOUBLE_VAL(pRight);
193,017,924✔
178

179
  if (isnan(p1) && isnan(p2)) {
193,017,924!
180
    return 0;
×
181
  }
182

183
  if (isnan(p1)) {
193,017,924!
184
    return -1;
×
185
  }
186

187
  if (isnan(p2)) {
193,017,924✔
188
    return 1;
677✔
189
  }
190

191
  if (DBL_EQUAL(p1, p2)) {
193,017,247✔
192
    return 0;
7,248,165✔
193
  }
194
  return DBL_GREATER(p1, p2) ? 1 : -1;
185,769,082!
195
}
196

197
int32_t compareDoubleValDesc(const void *pLeft, const void *pRight) { return compareDoubleVal(pRight, pLeft); }
7,263✔
198

199
int32_t compareLenPrefixedStr(const void *pLeft, const void *pRight) {
639,774,174✔
200
  int32_t len1 = varDataLen(pLeft);
639,774,174✔
201
  int32_t len2 = varDataLen(pRight);
639,774,174✔
202

203
  int32_t minLen = TMIN(len1, len2);
639,774,174✔
204
  int32_t ret = strncmp(varDataVal(pLeft), varDataVal(pRight), minLen);
639,774,174✔
205
  if (ret == 0) {
639,774,174✔
206
    if (len1 == len2) {
428,342,547✔
207
      return 0;
428,231,797✔
208
    } else {
209
      return len1 > len2 ? 1 : -1;
110,750!
210
    }
211
  } else {
212
    return ret > 0 ? 1 : -1;
211,431,627✔
213
  }
214
}
215

216
int32_t compareLenPrefixedStrDesc(const void *pLeft, const void *pRight) {
2,936,588✔
217
  return compareLenPrefixedStr(pRight, pLeft);
2,936,588✔
218
}
219

220
int32_t compareLenPrefixedWStr(const void *pLeft, const void *pRight) {
177,220,648✔
221
  int32_t len1 = varDataLen(pLeft);
177,220,648✔
222
  int32_t len2 = varDataLen(pRight);
177,220,648✔
223

224
  int32_t ret = taosUcs4Compare((TdUcs4 *)varDataVal(pLeft), (TdUcs4 *)varDataVal(pRight), len1>len2 ? len2:len1);
177,220,648✔
225
  if (ret == 0) {
179,649,481✔
226
    if (len1 > len2)
63,432,485✔
227
      return 1;
43,822✔
228
    else if(len1 < len2)
63,388,663✔
229
      return -1;
11,880✔
230
    else
231
      return 0;
63,376,783✔
232
  }
233
  return (ret < 0) ? -1 : 1;
116,216,996✔
234
}
235

236
int32_t compareLenPrefixedWStrDesc(const void *pLeft, const void *pRight) {
82,323✔
237
  return compareLenPrefixedWStr(pRight, pLeft);
82,323✔
238
}
239

240
int32_t compareLenBinaryVal(const void *pLeft, const void *pRight) {
276,034✔
241
  int32_t len1 = varDataLen(pLeft);
276,034✔
242
  int32_t len2 = varDataLen(pRight);
276,034✔
243

244
  int32_t minLen = TMIN(len1, len2);
276,034✔
245
  int32_t ret = memcmp(varDataVal(pLeft), varDataVal(pRight), minLen);
276,034✔
246
  if (ret == 0) {
276,034✔
247
    if (len1 == len2) {
148,107✔
248
      return 0;
147,985✔
249
    } else {
250
      return len1 > len2 ? 1 : -1;
122✔
251
    }
252
  } else {
253
    return ret > 0 ? 1 : -1;
127,927✔
254
  }
255
}
256

257
int32_t compareLenBinaryValDesc(const void *pLeft, const void *pRight) {
×
258
  return compareLenBinaryVal(pRight, pLeft);
×
259
}
260

261
// string > number > bool > null
262
// ref: https://dev.mysql.com/doc/refman/8.0/en/json.html#json-comparison
263
int32_t compareJsonVal(const void *pLeft, const void *pRight) {
1,056✔
264
  char leftType = *(char *)pLeft;
1,056✔
265
  char rightType = *(char *)pRight;
1,056✔
266
  if (leftType != rightType) {
1,056✔
267
    return leftType > rightType ? 1 : -1;
684✔
268
  }
269

270
  char *realDataLeft = POINTER_SHIFT(pLeft, CHAR_BYTES);
372✔
271
  char *realDataRight = POINTER_SHIFT(pRight, CHAR_BYTES);
372✔
272
  if (leftType == TSDB_DATA_TYPE_BOOL) {
372!
273
    DEFAULT_COMP(GET_INT8_VAL(realDataLeft), GET_INT8_VAL(realDataRight));
×
274
  } else if (leftType == TSDB_DATA_TYPE_DOUBLE) {
372✔
275
    DEFAULT_DOUBLE_COMP(GET_DOUBLE_VAL(realDataLeft), GET_DOUBLE_VAL(realDataRight));
176!
276
  } else if (leftType == TSDB_DATA_TYPE_NCHAR) {
196✔
277
    return compareLenPrefixedWStr(realDataLeft, realDataRight);
140✔
278
  } else if (leftType == TSDB_DATA_TYPE_NULL) {
56!
279
    return 0;
56✔
280
  } else {
281
    uError("data type unexpected leftType:%d rightType:%d", leftType, rightType);
×
282
    return 0;
×
283
  }
284
}
285

286
int32_t compareInt8Int16(const void *pLeft, const void *pRight) {
15,842,062✔
287
  int8_t  left = GET_INT8_VAL(pLeft);
15,842,062✔
288
  int16_t right = GET_INT16_VAL(pRight);
15,842,062✔
289
  if (left > right) return 1;
15,842,062!
290
  if (left < right) return -1;
15,842,062✔
291
  return 0;
71✔
292
}
293

294
int32_t compareInt8Int32(const void *pLeft, const void *pRight) {
1,536✔
295
  int8_t  left = GET_INT8_VAL(pLeft);
1,536✔
296
  int32_t right = GET_INT32_VAL(pRight);
1,536✔
297
  if (left > right) return 1;
1,536!
298
  if (left < right) return -1;
1,536!
299
  return 0;
×
300
}
301

302
int32_t compareInt8Int64(const void *pLeft, const void *pRight) {
742✔
303
  int8_t  left = GET_INT8_VAL(pLeft);
742✔
304
  int64_t right = GET_INT64_VAL(pRight);
742✔
305
  if (left > right) return 1;
742✔
306
  if (left < right) return -1;
393✔
307
  return 0;
10✔
308
}
309

310
int32_t compareInt8Float(const void *pLeft, const void *pRight) {
184✔
311
  int8_t left = GET_INT8_VAL(pLeft);
184✔
312
  float  right = GET_FLOAT_VAL(pRight);
184✔
313
  if (left > right) return 1;
184✔
314
  if (left < right) return -1;
23✔
315
  return 0;
8✔
316
}
317

318
int32_t compareInt8Double(const void *pLeft, const void *pRight) {
110✔
319
  int8_t left = GET_INT8_VAL(pLeft);
110✔
320
  double right = GET_DOUBLE_VAL(pRight);
110✔
321
  if (left > right) return 1;
110✔
322
  if (left < right) return -1;
45!
323
  return 0;
×
324
}
325

326
int32_t compareInt8Uint8(const void *pLeft, const void *pRight) {
×
327
  int8_t  left = GET_INT8_VAL(pLeft);
×
328
  uint8_t right = GET_UINT8_VAL(pRight);
×
329
  if (left > right) return 1;
×
330
  if (left < right) return -1;
×
331
  return 0;
×
332
}
333

334
int32_t compareInt8Uint16(const void *pLeft, const void *pRight) {
×
335
  int8_t   left = GET_INT8_VAL(pLeft);
×
336
  uint16_t right = GET_UINT16_VAL(pRight);
×
337
  if (left > right) return 1;
×
338
  if (left < right) return -1;
×
339
  return 0;
×
340
}
341

342
int32_t compareInt8Uint32(const void *pLeft, const void *pRight) {
×
343
  int8_t   left = GET_INT8_VAL(pLeft);
×
344
  if (left < 0) return -1;
×
345
  uint32_t right = GET_UINT32_VAL(pRight);
×
346
  if ((uint32_t)left > right) return 1;
×
347
  if ((uint32_t)left < right) return -1;
×
348
  return 0;
×
349
}
350

351
int32_t compareInt8Uint64(const void *pLeft, const void *pRight) {
1✔
352
  int8_t   left = GET_INT8_VAL(pLeft);
1✔
353
  if (left < 0) return -1;
1!
354
  uint64_t right = GET_UINT64_VAL(pRight);
1✔
355
  if ((uint64_t)left > right) return 1;
1!
356
  if ((uint64_t)left < right) return -1;
×
357
  return 0;
×
358
}
359

360
int32_t compareInt16Int8(const void *pLeft, const void *pRight) {
5,812,667✔
361
  int16_t left = GET_INT16_VAL(pLeft);
5,812,667✔
362
  int8_t  right = GET_INT8_VAL(pRight);
5,812,667✔
363
  if (left > right) return 1;
5,812,667✔
364
  if (left < right) return -1;
2,918,186✔
365
  return 0;
22,954✔
366
}
367

368
int32_t compareInt16Int32(const void *pLeft, const void *pRight) {
34,152,737✔
369
  int16_t left = GET_INT16_VAL(pLeft);
34,152,737✔
370
  int32_t right = GET_INT32_VAL(pRight);
34,152,737✔
371
  if (left > right) return 1;
34,152,737✔
372
  if (left < right) return -1;
34,152,004!
373
  return 0;
×
374
}
375

376
int32_t compareInt16Int64(const void *pLeft, const void *pRight) {
1,404✔
377
  int16_t left = GET_INT16_VAL(pLeft);
1,404✔
378
  int64_t right = GET_INT64_VAL(pRight);
1,404✔
379
  if (left > right) return 1;
1,404✔
380
  if (left < right) return -1;
420!
381
  return 0;
×
382
}
383

384
int32_t compareInt16Float(const void *pLeft, const void *pRight) {
192✔
385
  int16_t left = GET_INT16_VAL(pLeft);
192✔
386
  float   right = GET_FLOAT_VAL(pRight);
192✔
387
  if (left > right) return 1;
192✔
388
  if (left < right) return -1;
28✔
389
  return 0;
10✔
390
}
391

392
int32_t compareInt16Double(const void *pLeft, const void *pRight) {
121✔
393
  int16_t left = GET_INT16_VAL(pLeft);
121✔
394
  double  right = GET_DOUBLE_VAL(pRight);
121✔
395
  if (left > right) return 1;
121✔
396
  if (left < right) return -1;
53!
397
  return 0;
×
398
}
399

400
int32_t compareInt16Uint8(const void *pLeft, const void *pRight) {
×
401
  int16_t left = GET_INT16_VAL(pLeft);
×
402
  uint8_t right = GET_UINT8_VAL(pRight);
×
403
  if (left > right) return 1;
×
404
  if (left < right) return -1;
×
405
  return 0;
×
406
}
407

408
int32_t compareInt16Uint16(const void *pLeft, const void *pRight) {
×
409
  int16_t  left = GET_INT16_VAL(pLeft);
×
410
  uint16_t right = GET_UINT16_VAL(pRight);
×
411
  if (left > right) return 1;
×
412
  if (left < right) return -1;
×
413
  return 0;
×
414
}
415

416
int32_t compareInt16Uint32(const void *pLeft, const void *pRight) {
×
417
  int16_t  left = GET_INT16_VAL(pLeft);
×
418
  if (left < 0) return -1;
×
419
  uint32_t right = GET_UINT32_VAL(pRight);
×
420
  if ((uint32_t)left > right) return 1;
×
421
  if ((uint32_t)left < right) return -1;
×
422
  return 0;
×
423
}
424

425
int32_t compareInt16Uint64(const void *pLeft, const void *pRight) {
×
426
  int16_t  left = GET_INT16_VAL(pLeft);
×
427
  if (left < 0) return -1;
×
428
  uint64_t right = GET_UINT64_VAL(pRight);
×
429
  if ((uint64_t)left > right) return 1;
×
430
  if ((uint64_t)left < right) return -1;
×
431
  return 0;
×
432
}
433

434
int32_t compareInt32Int8(const void *pLeft, const void *pRight) {
4,736,131✔
435
  int32_t left = GET_INT32_VAL(pLeft);
4,736,131✔
436
  int8_t  right = GET_INT8_VAL(pRight);
4,736,131✔
437
  if (left > right) return 1;
4,736,131✔
438
  if (left < right) return -1;
2,396,074✔
439
  return 0;
27,791✔
440
}
441

442
int32_t compareInt32Int16(const void *pLeft, const void *pRight) {
745,149✔
443
  int32_t left = GET_INT32_VAL(pLeft);
745,149✔
444
  int16_t right = GET_INT16_VAL(pRight);
745,149✔
445
  if (left > right) return 1;
745,149✔
446
  if (left < right) return -1;
307,408!
447
  return 0;
×
448
}
449

450
int32_t compareInt32Int64(const void *pLeft, const void *pRight) {
203,444,662✔
451
  int32_t left = GET_INT32_VAL(pLeft);
203,444,662✔
452
  int64_t right = GET_INT64_VAL(pRight);
203,444,662✔
453
  if (left > right) return 1;
203,444,662✔
454
  if (left < right) return -1;
113,173,072!
455
  return 0;
×
456
}
457

458
int32_t compareInt32Float(const void *pLeft, const void *pRight) {
100✔
459
  int32_t left = GET_INT32_VAL(pLeft);
100✔
460
  float   right = GET_FLOAT_VAL(pRight);
100✔
461
  if (left > right) return 1;
100!
462
  if (left < right) return -1;
100!
463
  return 0;
×
464
}
465

466
int32_t compareInt32Double(const void *pLeft, const void *pRight) {
1,689✔
467
  int32_t left = GET_INT32_VAL(pLeft);
1,689✔
468
  double  right = GET_DOUBLE_VAL(pRight);
1,689✔
469
  if (left > right) return 1;
1,689✔
470
  if (left < right) return -1;
595✔
471
  return 0;
196✔
472
}
473

474
int32_t compareInt32Uint8(const void *pLeft, const void *pRight) {
×
475
  int32_t left = GET_INT32_VAL(pLeft);
×
476
  uint8_t right = GET_UINT8_VAL(pRight);
×
477
  if (left > right) return 1;
×
478
  if (left < right) return -1;
×
479
  return 0;
×
480
}
481

482
int32_t compareInt32Uint16(const void *pLeft, const void *pRight) {
×
483
  int32_t  left = GET_INT32_VAL(pLeft);
×
484
  uint16_t right = GET_UINT16_VAL(pRight);
×
485
  if (left > right) return 1;
×
486
  if (left < right) return -1;
×
487
  return 0;
×
488
}
489

490
int32_t compareInt32Uint32(const void *pLeft, const void *pRight) {
96✔
491
  int32_t  left = GET_INT32_VAL(pLeft);
96✔
492
  if (left < 0) return -1;
96!
493
  uint32_t right = GET_UINT32_VAL(pRight);
96✔
494
  if ((uint32_t)left > right) return 1;
96✔
495
  if ((uint32_t)left < right) return -1;
54!
496
  return 0;
54✔
497
}
498

499
int32_t compareInt32Uint64(const void *pLeft, const void *pRight) {
×
500
  int32_t  left = GET_INT32_VAL(pLeft);
×
501
  if (left < 0) return -1;
×
502
  uint64_t right = GET_UINT64_VAL(pRight);
×
503
  if ((uint64_t)left > right) return 1;
×
504
  if ((uint64_t)left < right) return -1;
×
505
  return 0;
×
506
}
507

508
int32_t compareInt64Int8(const void *pLeft, const void *pRight) {
1,340,745,961✔
509
  int64_t left = GET_INT64_VAL(pLeft);
1,340,745,961✔
510
  int8_t  right = GET_INT8_VAL(pRight);
1,340,745,961✔
511
  if (left > right) return 1;
1,340,745,961✔
512
  if (left < right) return -1;
1,338,816,724✔
513
  return 0;
1,336,915,944✔
514
}
515

516
int32_t compareInt64Int16(const void *pLeft, const void *pRight) {
185,118✔
517
  int64_t left = GET_INT64_VAL(pLeft);
185,118✔
518
  int16_t right = GET_INT16_VAL(pRight);
185,118✔
519
  if (left > right) return 1;
185,118✔
520
  if (left < right) return -1;
173,912✔
521
  return 0;
150,520✔
522
}
523

524
int32_t compareInt64Int32(const void *pLeft, const void *pRight) {
34,525,862✔
525
  int64_t left = GET_INT64_VAL(pLeft);
34,525,862✔
526
  int32_t right = GET_INT32_VAL(pRight);
34,525,862✔
527
  if (left > right) return 1;
34,525,862✔
528
  if (left < right) return -1;
17,015,772!
529
  return 0;
×
530
}
531

532
int32_t compareInt64Float(const void *pLeft, const void *pRight) {
192✔
533
  int64_t left = GET_INT64_VAL(pLeft);
192✔
534
  float   right = GET_FLOAT_VAL(pRight);
192✔
535
  if (left > right) return 1;
192✔
536
  if (left < right) return -1;
28✔
537
  return 0;
10✔
538
}
539

540
int32_t compareInt64Double(const void *pLeft, const void *pRight) {
81✔
541
  int64_t left = GET_INT64_VAL(pLeft);
81✔
542
  double  right = GET_DOUBLE_VAL(pRight);
81✔
543
  if (left > right) return 1;
81!
544
  if (left < right) return -1;
81!
545
  return 0;
×
546
}
547

548
int32_t compareInt64Uint8(const void *pLeft, const void *pRight) {
×
549
  int64_t left = GET_INT64_VAL(pLeft);
×
550
  uint8_t right = GET_UINT8_VAL(pRight);
×
551
  if (left > right) return 1;
×
552
  if (left < right) return -1;
×
553
  return 0;
×
554
}
555

556
int32_t compareInt64Uint16(const void *pLeft, const void *pRight) {
×
557
  int64_t  left = GET_INT64_VAL(pLeft);
×
558
  uint16_t right = GET_UINT16_VAL(pRight);
×
559
  if (left > right) return 1;
×
560
  if (left < right) return -1;
×
561
  return 0;
×
562
}
563

564
int32_t compareInt64Uint32(const void *pLeft, const void *pRight) {
×
565
  int64_t  left = GET_INT64_VAL(pLeft);
×
566
  uint32_t right = GET_UINT32_VAL(pRight);
×
567
  if (left > right) return 1;
×
568
  if (left < right) return -1;
×
569
  return 0;
×
570
}
571

572
int32_t compareInt64Uint64(const void *pLeft, const void *pRight) {
35,753,347✔
573
  int64_t  left = GET_INT64_VAL(pLeft);
35,753,347✔
574
  if (left < 0) return -1;
35,753,347✔
575
  uint64_t right = GET_UINT64_VAL(pRight);
18,147,863✔
576
  if ((uint64_t)left > right) return 1;
18,147,863!
577
  if ((uint64_t)left < right) return -1;
18,147,863!
578
  return 0;
×
579
}
580

581
int32_t compareFloatInt8(const void *pLeft, const void *pRight) {
673,022✔
582
  float  left = GET_FLOAT_VAL(pLeft);
673,022✔
583
  int8_t right = GET_INT8_VAL(pRight);
673,022✔
584
  if (left > right) return 1;
673,022✔
585
  if (left < right) return -1;
635,481✔
586
  return 0;
610,185✔
587
}
588

589
int32_t compareFloatInt16(const void *pLeft, const void *pRight) {
91,676✔
590
  float   left = GET_FLOAT_VAL(pLeft);
91,676✔
591
  int16_t right = GET_INT16_VAL(pRight);
91,676✔
592
  if (left > right) return 1;
91,676✔
593
  if (left < right) return -1;
3,340!
594
  return 0;
×
595
}
596

597
int32_t compareFloatInt32(const void *pLeft, const void *pRight) {
1,576✔
598
  float   left = GET_FLOAT_VAL(pLeft);
1,576✔
599
  int32_t right = GET_INT32_VAL(pRight);
1,576✔
600
  if (left > right) return 1;
1,576✔
601
  if (left < right) return -1;
1,344!
602
  return 0;
×
603
}
604

605
int32_t compareFloatInt64(const void *pLeft, const void *pRight) {
610✔
606
  float   left = GET_FLOAT_VAL(pLeft);
610✔
607
  int64_t right = GET_INT64_VAL(pRight);
610✔
608
  if (left > right) return 1;
610✔
609
  if (left < right) return -1;
235!
610
  return 0;
×
611
}
612

613
int32_t compareFloatDouble(const void *pLeft, const void *pRight) {
148,544,694✔
614
  float  left = GET_FLOAT_VAL(pLeft);
148,544,694✔
615
  double right = GET_DOUBLE_VAL(pRight);
148,544,694✔
616

617
  if (isnan(left) && isnan(right)) {
148,544,694!
618
    return 0;
×
619
  }
620

621
  if (isnan(left)) {
148,544,694!
622
    return -1;
×
623
  }
624

625
  if (isnan(right)) {
148,544,694!
626
    return 1;
×
627
  }
628

629
  if (FLT_EQUAL(left, right)) {
148,544,694✔
630
    return 0;
3,499✔
631
  }
632
  return FLT_GREATER(left, right) ? 1 : -1;
148,541,195✔
633
}
634

635
int32_t compareFloatUint8(const void *pLeft, const void *pRight) {
×
636
  float   left = GET_FLOAT_VAL(pLeft);
×
637
  uint8_t right = GET_UINT8_VAL(pRight);
×
638
  if (left > right) return 1;
×
639
  if (left < right) return -1;
×
640
  return 0;
×
641
}
642

643
int32_t compareFloatUint16(const void *pLeft, const void *pRight) {
×
644
  float    left = GET_FLOAT_VAL(pLeft);
×
645
  uint16_t right = GET_UINT16_VAL(pRight);
×
646
  if (left > right) return 1;
×
647
  if (left < right) return -1;
×
648
  return 0;
×
649
}
650

651
int32_t compareFloatUint32(const void *pLeft, const void *pRight) {
×
652
  float    left = GET_FLOAT_VAL(pLeft);
×
653
  uint32_t right = GET_UINT32_VAL(pRight);
×
654
  if (left > right) return 1;
×
655
  if (left < right) return -1;
×
656
  return 0;
×
657
}
658

659
int32_t compareFloatUint64(const void *pLeft, const void *pRight) {
×
660
  float    left = GET_FLOAT_VAL(pLeft);
×
661
  uint64_t right = GET_UINT64_VAL(pRight);
×
662
  if (left > right) return 1;
×
663
  if (left < right) return -1;
×
664
  return 0;
×
665
}
666

667
int32_t compareDoubleInt8(const void *pLeft, const void *pRight) {
8,072,437✔
668
  double left = GET_DOUBLE_VAL(pLeft);
8,072,437✔
669
  int8_t right = GET_INT8_VAL(pRight);
8,072,437✔
670
  if (left > right) return 1;
8,072,437✔
671
  if (left < right) return -1;
4,447,682✔
672
  return 0;
901,956✔
673
}
674

675
int32_t compareDoubleInt16(const void *pLeft, const void *pRight) {
600,000✔
676
  double  left = GET_DOUBLE_VAL(pLeft);
600,000✔
677
  int16_t right = GET_INT16_VAL(pRight);
600,000✔
678
  if (left > right) return 1;
600,000!
679
  if (left < right) return -1;
600,000!
680
  return 0;
600,000✔
681
}
682

683
int32_t compareDoubleInt32(const void *pLeft, const void *pRight) {
44,936✔
684
  double  left = GET_DOUBLE_VAL(pLeft);
44,936✔
685
  int32_t right = GET_INT32_VAL(pRight);
44,936✔
686
  if (left > right) return 1;
44,936✔
687
  if (left < right) return -1;
39,273✔
688
  return 0;
179✔
689
}
690

691
int32_t compareDoubleInt64(const void *pLeft, const void *pRight) {
9,927,183✔
692
  double  left = GET_DOUBLE_VAL(pLeft);
9,927,183✔
693
  int64_t right = GET_INT64_VAL(pRight);
9,927,183✔
694
  if (left > right) return 1;
9,927,183✔
695
  if (left < right) return -1;
5,287,303✔
696
  return 0;
1,187,460✔
697
}
698

699
int32_t compareDoubleFloat(const void *pLeft, const void *pRight) {
13,477✔
700
  double left = GET_DOUBLE_VAL(pLeft);
13,477✔
701
  float  right = GET_FLOAT_VAL(pRight);
13,477✔
702

703
  if (isnan(left) && isnan(right)) {
13,477!
704
    return 0;
×
705
  }
706

707
  if (isnan(left)) {
13,477!
708
    return -1;
×
709
  }
710

711
  if (isnan(right)) {
13,477!
712
    return 1;
×
713
  }
714

715
  if (FLT_EQUAL(left, right)) {
13,477✔
716
    return 0;
13✔
717
  }
718
  return FLT_GREATER(left, right) ? 1 : -1;
13,464!
719
}
720

721
int32_t compareDoubleUint8(const void *pLeft, const void *pRight) {
×
722
  double  left = GET_DOUBLE_VAL(pLeft);
×
723
  uint8_t right = GET_UINT8_VAL(pRight);
×
724
  if (left > right) return 1;
×
725
  if (left < right) return -1;
×
726
  return 0;
×
727
}
728

729
int32_t compareDoubleUint16(const void *pLeft, const void *pRight) {
×
730
  double   left = GET_DOUBLE_VAL(pLeft);
×
731
  uint16_t right = GET_UINT16_VAL(pRight);
×
732
  if (left > right) return 1;
×
733
  if (left < right) return -1;
×
734
  return 0;
×
735
}
736

737
int32_t compareDoubleUint32(const void *pLeft, const void *pRight) {
×
738
  double   left = GET_DOUBLE_VAL(pLeft);
×
739
  uint32_t right = GET_UINT32_VAL(pRight);
×
740
  if (left > right) return 1;
×
741
  if (left < right) return -1;
×
742
  return 0;
×
743
}
744

745
int32_t compareDoubleUint64(const void *pLeft, const void *pRight) {
×
746
  double   left = GET_DOUBLE_VAL(pLeft);
×
747
  uint64_t right = GET_UINT64_VAL(pRight);
×
748
  if (left > right) return 1;
×
749
  if (left < right) return -1;
×
750
  return 0;
×
751
}
752

753
int32_t compareUint8Int8(const void *pLeft, const void *pRight) {
17,917✔
754
  uint8_t left = GET_UINT8_VAL(pLeft);
17,917✔
755
  int8_t  right = GET_INT8_VAL(pRight);
17,917✔
756
  if (left > right) return 1;
17,917✔
757
  if (left < right) return -1;
4,405✔
758
  return 0;
2,091✔
759
}
760

761
int32_t compareUint8Int16(const void *pLeft, const void *pRight) {
×
762
  uint8_t left = GET_UINT8_VAL(pLeft);
×
763
  int16_t right = GET_INT16_VAL(pRight);
×
764
  if (left > right) return 1;
×
765
  if (left < right) return -1;
×
766
  return 0;
×
767
}
768

769
int32_t compareUint8Int32(const void *pLeft, const void *pRight) {
×
770
  uint8_t left = GET_UINT8_VAL(pLeft);
×
771
  int32_t right = GET_INT32_VAL(pRight);
×
772
  if (left > right) return 1;
×
773
  if (left < right) return -1;
×
774
  return 0;
×
775
}
776

777
int32_t compareUint8Int64(const void *pLeft, const void *pRight) {
×
778
  uint8_t left = GET_UINT8_VAL(pLeft);
×
779
  int64_t right = GET_INT64_VAL(pRight);
×
780
  if (left > right) return 1;
×
781
  if (left < right) return -1;
×
782
  return 0;
×
783
}
784

785
int32_t compareUint8Float(const void *pLeft, const void *pRight) {
×
786
  uint8_t left = GET_UINT8_VAL(pLeft);
×
787
  float   right = GET_FLOAT_VAL(pRight);
×
788
  if (left > right) return 1;
×
789
  if (left < right) return -1;
×
790
  return 0;
×
791
}
792

793
int32_t compareUint8Double(const void *pLeft, const void *pRight) {
×
794
  uint8_t left = GET_UINT8_VAL(pLeft);
×
795
  double  right = GET_DOUBLE_VAL(pRight);
×
796
  if (left > right) return 1;
×
797
  if (left < right) return -1;
×
798
  return 0;
×
799
}
800

801
int32_t compareUint8Uint16(const void *pLeft, const void *pRight) {
175✔
802
  uint8_t  left = GET_UINT8_VAL(pLeft);
175✔
803
  uint16_t right = GET_UINT16_VAL(pRight);
175✔
804
  if (left > right) return 1;
175!
805
  if (left < right) return -1;
175!
806
  return 0;
175✔
807
}
808

809
int32_t compareUint8Uint32(const void *pLeft, const void *pRight) {
×
810
  uint8_t  left = GET_UINT8_VAL(pLeft);
×
811
  uint32_t right = GET_UINT32_VAL(pRight);
×
812
  if (left > right) return 1;
×
813
  if (left < right) return -1;
×
814
  return 0;
×
815
}
816

817
int32_t compareUint8Uint64(const void *pLeft, const void *pRight) {
×
818
  uint8_t  left = GET_UINT8_VAL(pLeft);
×
819
  uint64_t right = GET_UINT64_VAL(pRight);
×
820
  if (left > right) return 1;
×
821
  if (left < right) return -1;
×
822
  return 0;
×
823
}
824

825
int32_t compareUint16Int8(const void *pLeft, const void *pRight) {
50,112✔
826
  uint16_t left = GET_UINT16_VAL(pLeft);
50,112✔
827
  int8_t   right = GET_INT8_VAL(pRight);
50,112✔
828
  if (left > right) return 1;
50,112✔
829
  if (left < right) return -1;
3,043✔
830
  return 0;
1,650✔
831
}
832

833
int32_t compareUint16Int16(const void *pLeft, const void *pRight) {
×
834
  uint16_t left = GET_UINT16_VAL(pLeft);
×
835
  int16_t  right = GET_INT16_VAL(pRight);
×
836
  if (left > right) return 1;
×
837
  if (left < right) return -1;
×
838
  return 0;
×
839
}
840

841
int32_t compareUint16Int32(const void *pLeft, const void *pRight) {
×
842
  uint16_t left = GET_UINT16_VAL(pLeft);
×
843
  int32_t  right = GET_INT32_VAL(pRight);
×
844
  if (left > right) return 1;
×
845
  if (left < right) return -1;
×
846
  return 0;
×
847
}
848

849
int32_t compareUint16Int64(const void *pLeft, const void *pRight) {
609✔
850
  uint16_t left = GET_UINT16_VAL(pLeft);
609✔
851
  int64_t  right = GET_INT64_VAL(pRight);
609✔
852
  if (left > right) return 1;
609!
853
  if (left < right) return -1;
×
854
  return 0;
×
855
}
856

857
int32_t compareUint16Float(const void *pLeft, const void *pRight) {
×
858
  uint16_t left = GET_UINT16_VAL(pLeft);
×
859
  float    right = GET_FLOAT_VAL(pRight);
×
860
  if (left > right) return 1;
×
861
  if (left < right) return -1;
×
862
  return 0;
×
863
}
864

865
int32_t compareUint16Double(const void *pLeft, const void *pRight) {
×
866
  uint16_t left = GET_UINT16_VAL(pLeft);
×
867
  double   right = GET_DOUBLE_VAL(pRight);
×
868
  if (left > right) return 1;
×
869
  if (left < right) return -1;
×
870
  return 0;
×
871
}
872

873
int32_t compareUint16Uint8(const void *pLeft, const void *pRight) {
×
874
  uint16_t left = GET_UINT16_VAL(pLeft);
×
875
  uint8_t  right = GET_UINT8_VAL(pRight);
×
876
  if (left > right) return 1;
×
877
  if (left < right) return -1;
×
878
  return 0;
×
879
}
880

881
int32_t compareUint16Uint32(const void *pLeft, const void *pRight) {
×
882
  uint16_t left = GET_UINT16_VAL(pLeft);
×
883
  uint32_t right = GET_UINT32_VAL(pRight);
×
884
  if (left > right) return 1;
×
885
  if (left < right) return -1;
×
886
  return 0;
×
887
}
888

889
int32_t compareUint16Uint64(const void *pLeft, const void *pRight) {
1✔
890
  uint16_t left = GET_UINT16_VAL(pLeft);
1✔
891
  uint64_t right = GET_UINT64_VAL(pRight);
1✔
892
  if (left > right) return 1;
1!
893
  if (left < right) return -1;
1!
894
  return 0;
1✔
895
}
896

897
int32_t compareUint32Int8(const void *pLeft, const void *pRight) {
17,122✔
898
  uint32_t left = GET_UINT32_VAL(pLeft);
17,122✔
899
  int8_t   right = GET_INT8_VAL(pRight);
17,122✔
900
  if (right < 0) return 1;
17,122!
901
  if (left > (uint32_t)right) return 1;
17,122✔
902
  if (left < (uint32_t)right) return -1;
3,324✔
903
  return 0;
1,616✔
904
}
905

906
int32_t compareUint32Int16(const void *pLeft, const void *pRight) {
8✔
907
  uint32_t left = GET_UINT32_VAL(pLeft);
8✔
908
  int16_t  right = GET_INT16_VAL(pRight);
8✔
909
  if (right < 0) return 1;
8!
910
  if (left > (uint32_t)right) return 1;
8✔
911
  if (left < (uint32_t)right) return -1;
5✔
912
  return 0;
2✔
913
}
914

915
int32_t compareUint32Int32(const void *pLeft, const void *pRight) {
×
916
  uint32_t left = GET_UINT32_VAL(pLeft);
×
917
  int32_t  right = GET_INT32_VAL(pRight);
×
918
  if (right < 0) return 1;
×
919
  if (left > (uint32_t)right) return 1;
×
920
  if (left < (uint32_t)right) return -1;
×
921
  return 0;
×
922
}
923

924
int32_t compareUint32Int64(const void *pLeft, const void *pRight) {
×
925
  uint32_t left = GET_UINT32_VAL(pLeft);
×
926
  int64_t  right = GET_INT64_VAL(pRight);
×
927
  if (left > right) return 1;
×
928
  if (left < right) return -1;
×
929
  return 0;
×
930
}
931

932
int32_t compareUint32Float(const void *pLeft, const void *pRight) {
×
933
  uint32_t left = GET_UINT32_VAL(pLeft);
×
934
  float    right = GET_FLOAT_VAL(pRight);
×
935
  if (left > right) return 1;
×
936
  if (left < right) return -1;
×
937
  return 0;
×
938
}
939

940
int32_t compareUint32Double(const void *pLeft, const void *pRight) {
6✔
941
  uint32_t left = GET_UINT32_VAL(pLeft);
6✔
942
  double   right = GET_DOUBLE_VAL(pRight);
6✔
943
  if (left > right) return 1;
6!
944
  if (left < right) return -1;
6!
945
  return 0;
×
946
}
947

948
int32_t compareUint32Uint8(const void *pLeft, const void *pRight) {
×
949
  uint32_t left = GET_UINT32_VAL(pLeft);
×
950
  uint8_t  right = GET_UINT8_VAL(pRight);
×
951
  if (left > right) return 1;
×
952
  if (left < right) return -1;
×
953
  return 0;
×
954
}
955

956
int32_t compareUint32Uint16(const void *pLeft, const void *pRight) {
×
957
  uint32_t left = GET_UINT32_VAL(pLeft);
×
958
  uint16_t right = GET_UINT16_VAL(pRight);
×
959
  if (left > right) return 1;
×
960
  if (left < right) return -1;
×
961
  return 0;
×
962
}
963

964
int32_t compareUint32Uint64(const void *pLeft, const void *pRight) {
×
965
  uint32_t left = GET_UINT32_VAL(pLeft);
×
966
  uint64_t right = GET_UINT64_VAL(pRight);
×
967
  if (left > right) return 1;
×
968
  if (left < right) return -1;
×
969
  return 0;
×
970
}
971

972
int32_t compareUint64Int8(const void *pLeft, const void *pRight) {
55,063✔
973
  uint64_t left = GET_UINT64_VAL(pLeft);
55,063✔
974
  int8_t   right = GET_INT8_VAL(pRight);
55,063✔
975
  if (right < 0) return 1;
55,063!
976
  if (left > (uint64_t)right) return 1;
55,063✔
977
  if (left < (uint64_t)right) return -1;
5,802✔
978
  return 0;
3,545✔
979
}
980

981
int32_t compareUint64Int16(const void *pLeft, const void *pRight) {
×
982
  uint64_t left = GET_UINT64_VAL(pLeft);
×
983
  int16_t  right = GET_INT16_VAL(pRight);
×
984
  if (right < 0) return 1;
×
985
  if (left > (uint64_t)right) return 1;
×
986
  if (left < (uint64_t)right) return -1;
×
987
  return 0;
×
988
}
989

990
int32_t compareUint64Int32(const void *pLeft, const void *pRight) {
8✔
991
  uint64_t left = GET_UINT64_VAL(pLeft);
8✔
992
  int32_t  right = GET_INT32_VAL(pRight);
8✔
993
  if (right < 0) return 1;
8!
994
  if (left > (uint64_t)right) return 1;
8!
995
  if (left < (uint64_t)right) return -1;
8✔
996
  return 0;
2✔
997
}
998

999
int32_t compareUint64Int64(const void *pLeft, const void *pRight) {
14,292✔
1000
  uint64_t left = GET_UINT64_VAL(pLeft);
14,292✔
1001
  int64_t  right = GET_INT64_VAL(pRight);
14,292✔
1002
  if (right < 0) return 1;
14,292✔
1003
  if (left > (uint64_t)right) return 1;
601!
1004
  if (left < (uint64_t)right) return -1;
×
1005
  return 0;
×
1006
}
1007

1008
int32_t compareUint64Float(const void *pLeft, const void *pRight) {
×
1009
  uint64_t left = GET_UINT64_VAL(pLeft);
×
1010
  float    right = GET_FLOAT_VAL(pRight);
×
1011
  if (left > right) return 1;
×
1012
  if (left < right) return -1;
×
1013
  return 0;
×
1014
}
1015

1016
int32_t compareUint64Double(const void *pLeft, const void *pRight) {
×
1017
  uint64_t left = GET_UINT64_VAL(pLeft);
×
1018
  double   right = GET_DOUBLE_VAL(pRight);
×
1019
  if (left > right) return 1;
×
1020
  if (left < right) return -1;
×
1021
  return 0;
×
1022
}
1023

1024
int32_t compareUint64Uint8(const void *pLeft, const void *pRight) {
×
1025
  uint64_t left = GET_UINT64_VAL(pLeft);
×
1026
  uint8_t  right = GET_UINT8_VAL(pRight);
×
1027
  if (left > right) return 1;
×
1028
  if (left < right) return -1;
×
1029
  return 0;
×
1030
}
1031

1032
int32_t compareUint64Uint16(const void *pLeft, const void *pRight) {
×
1033
  uint64_t left = GET_UINT64_VAL(pLeft);
×
1034
  uint16_t right = GET_UINT16_VAL(pRight);
×
1035
  if (left > right) return 1;
×
1036
  if (left < right) return -1;
×
1037
  return 0;
×
1038
}
1039

1040
int32_t compareUint64Uint32(const void *pLeft, const void *pRight) {
×
1041
  uint64_t left = GET_UINT64_VAL(pLeft);
×
1042
  uint32_t right = GET_UINT32_VAL(pRight);
×
1043
  if (left > right) return 1;
×
1044
  if (left < right) return -1;
×
1045
  return 0;
×
1046
}
1047

1048
int32_t compareDecimal64(const void* pleft, const void* pright) {
88,530✔
1049
  if (decimal64Compare(OP_TYPE_GREATER_THAN, pleft, pright)) return 1;
88,530!
1050
  if (decimal64Compare(OP_TYPE_LOWER_THAN, pleft, pright)) return -1;
88,530!
1051
  return 0;
88,530✔
1052
}
1053

1054
int32_t compareDecimal128(const void* pleft, const void* pright) {
3,927,448✔
1055
  if (decimalCompare(OP_TYPE_GREATER_THAN, pleft, pright)) return 1;
3,927,448✔
1056
  if (decimalCompare(OP_TYPE_LOWER_THAN, pleft, pright)) return -1;
2,097,713✔
1057
  return 0;
287,887✔
1058
}
1059

1060
int32_t compareDecimal64SameScale(const void* pleft, const void* pright) {
785,550✔
1061
  const SDecimalOps* pOps = getDecimalOps(TSDB_DATA_TYPE_DECIMAL64);
785,550✔
1062
  if (pOps->gt(pleft, pright, DECIMAL_WORD_NUM(Decimal64))) return 1;
785,550✔
1063
  if (pOps->lt(pleft, pright, DECIMAL_WORD_NUM(Decimal64))) return -1;
456,673✔
1064
  return 0;
49,422✔
1065
}
1066

1067
int32_t compareDecimal64SameScaleDesc(const void* pLeft, const void* pRight) {
×
1068
  const SDecimalOps* pOps = getDecimalOps(TSDB_DATA_TYPE_DECIMAL64);
×
1069
  if (pOps->lt(pLeft, pRight, DECIMAL_WORD_NUM(Decimal64))) return 1;
×
1070
  if (pOps->gt(pLeft, pRight, DECIMAL_WORD_NUM(Decimal64))) return -1;
×
1071
  return 0;
×
1072
}
1073

1074
int32_t compareDecimal128SameScale(const void* pleft, const void* pright) {
2,396,424✔
1075
  const SDecimalOps* pOps = getDecimalOps(TSDB_DATA_TYPE_DECIMAL);
2,396,424✔
1076
  if (pOps->gt(pleft, pright, DECIMAL_WORD_NUM(Decimal))) return 1;
2,396,424✔
1077
  if (pOps->lt(pleft, pright, DECIMAL_WORD_NUM(Decimal))) return -1;
1,398,583✔
1078
  return 0;
129,249✔
1079
}
1080

1081
int32_t compareDecimal128SameScaleDesc(const void* pLeft, const void* pRight) {
×
1082
  const SDecimalOps* pOps = getDecimalOps(TSDB_DATA_TYPE_DECIMAL);
×
1083
  if (pOps->lt(pLeft, pRight, DECIMAL_WORD_NUM(Decimal))) return 1;
×
1084
  if (pOps->gt(pLeft, pRight, DECIMAL_WORD_NUM(Decimal))) return -1;
×
1085
  return 0;
×
1086
}
1087

1088
int32_t compareJsonValDesc(const void *pLeft, const void *pRight) { return compareJsonVal(pRight, pLeft); }
204✔
1089

1090
/*
1091
 * Compare two strings
1092
 *    TSDB_MATCH:            Match
1093
 *    TSDB_NOMATCH:          No match
1094
 *    TSDB_NOWILDCARDMATCH:  No match in spite of having * or % wildcards.
1095
 * Like matching rules:
1096
 *      '%': Matches zero or more characters
1097
 *      '_': Matches one character
1098
 *
1099
 */
1100
int32_t patternMatch(const char *pattern, size_t psize, const char *str, size_t ssize,
88,317,575✔
1101
                     const SPatternCompareInfo *pInfo) {
1102
  char c, c1;
1103

1104
  int32_t i = 0;
88,317,575✔
1105
  int32_t j = 0;
88,317,575✔
1106
  int32_t nMatchChar = 0;
88,317,575✔
1107

1108
  while ((i < psize) && ((c = pattern[i++]) != 0)) {
561,219,568!
1109
    if (c == pInfo->matchAll) { /* Match "*" */
549,888,383✔
1110

1111
      while ((i < psize) && ((c = pattern[i++]) == pInfo->matchAll || c == pInfo->matchOne)) {
76,909,187✔
1112
        if (c == pInfo->matchOne) {
5,520✔
1113
          if (j >= ssize || str[j++] == 0) {  // empty string, return not match
5,272!
1114
            return TSDB_PATTERN_NOWILDCARDMATCH;
2✔
1115
          } else {
1116
            ++nMatchChar;
5,270✔
1117
          }
1118
        }
1119
      }
1120

1121
      if (i >= psize && (c == pInfo->umatchOne || c == pInfo->umatchAll)) {
76,903,667!
1122
        return TSDB_PATTERN_MATCH; /* "*" at the end of the pattern matches */
76,846,226✔
1123
      }
1124

1125
      if (c == '\\' && (pattern[i] == '_' || pattern[i] == '%')) {
57,441!
1126
        c = pattern[i];
1,742✔
1127
        i++;
1,742✔
1128
      }
1129

1130
      char rejectList[2] = {toupper(c), tolower(c)};
57,441✔
1131

1132
      str += nMatchChar;
57,441✔
1133
      int32_t remain = ssize - nMatchChar;
57,441✔
1134
      while (1) {
9,610,546✔
1135
        size_t n = tstrncspn(str, remain, rejectList, 2);
9,667,987✔
1136

1137
        str += n;
9,670,378✔
1138
        remain -= n;
9,670,378✔
1139

1140
        if ((remain <= 0) || str[0] == 0) {
9,670,378!
1141
          break;
1142
        }
1143

1144
        int32_t ret = patternMatch(&pattern[i], psize - i, ++str, --remain, pInfo);
9,629,125✔
1145
        if (ret != TSDB_PATTERN_NOMATCH) {
9,628,336✔
1146
          return ret;
17,790✔
1147
        }
1148
      }
1149

1150
      return TSDB_PATTERN_NOWILDCARDMATCH;
41,253✔
1151
    }
1152

1153
    if (j < ssize) {
472,984,714✔
1154
      c1 = str[j++];
472,984,262✔
1155
      ++nMatchChar;
472,984,262✔
1156

1157
      if (c == '\\' && (pattern[i] == '_' || pattern[i] == '%')) {
472,984,262✔
1158
        if (c1 != pattern[i]) {
315✔
1159
          return TSDB_PATTERN_NOMATCH;
203✔
1160
        } else {
1161
          i++;
112✔
1162
          continue;
112✔
1163
        }
1164
      }
1165

1166
      if (c == c1 || tolower(c) == tolower(c1) || (c == pInfo->matchOne && c1 != 0)) {
472,983,947✔
1167
        continue;
472,901,881✔
1168
      }
1169
    }
1170

1171
    return TSDB_PATTERN_NOMATCH;
82,518✔
1172
  }
1173

1174
  return (j >= ssize || str[j] == 0) ? TSDB_PATTERN_MATCH : TSDB_PATTERN_NOMATCH;
11,331,185!
1175
}
1176

1177
int32_t rawStrPatternMatch(const char *str, const char *pattern) {
2,476✔
1178
  SPatternCompareInfo pInfo = PATTERN_COMPARE_INFO_INITIALIZER;
2,476✔
1179

1180
  size_t pLen = strlen(pattern);
2,476✔
1181
  size_t sz = strlen(str);
2,476✔
1182
  if (pLen > TSDB_MAX_FIELD_LEN) {
2,476!
1183
    return 1;
×
1184
  }
1185

1186
  int32_t ret = patternMatch(pattern, pLen, str, sz, &pInfo);
2,476✔
1187
  return (ret == TSDB_PATTERN_MATCH) ? 0 : 1;
2,476✔
1188
}
1189

1190
int32_t wcsPatternMatch(const TdUcs4 *pattern, size_t psize, const TdUcs4 *str, size_t ssize,
75,696,886✔
1191
                        const SPatternCompareInfo *pInfo) {
1192
  TdUcs4 c, c1;
1193

1194
  int32_t i = 0;
75,696,886✔
1195
  int32_t j = 0;
75,696,886✔
1196
  int32_t nMatchChar = 0;
75,696,886✔
1197

1198
  while ((i < psize) && ((c = pattern[i++]) != 0)) {
455,241,389!
1199
    if (c == pInfo->umatchAll) { /* Match "%" */
453,610,297✔
1200

1201
      while ((i < psize) && ((c = pattern[i++]) == pInfo->umatchAll || c == pInfo->umatchOne)) {
73,981,935!
1202
        if (c == pInfo->umatchOne) {
36!
1203
          if (j >= ssize || str[j++] == 0) {
36!
1204
            return TSDB_PATTERN_NOWILDCARDMATCH;
2✔
1205
          } else {
1206
            ++nMatchChar;
34✔
1207
          }
1208
        }
1209
      }
1210

1211
      if (i >= psize && (c == pInfo->umatchOne || c == pInfo->umatchAll)) {
73,981,899!
1212
        return TSDB_PATTERN_MATCH;
73,980,450✔
1213
      }
1214

1215
      if (c == '\\' && (pattern[i] == '_' || pattern[i] == '%')) {
1,449!
1216
        c = pattern[i];
4✔
1217
        i++;
4✔
1218
      }
1219

1220
      TdUcs4 rejectList[2] = {towupper(c), towlower(c)};
1,449✔
1221

1222
      str += nMatchChar;
1,449✔
1223
      int32_t remain = ssize - nMatchChar;
1,449✔
1224
      while (1) {
1,988✔
1225
        size_t n = twcsncspn(str, remain, rejectList, 2);
3,437✔
1226

1227
        str += n;
4,300✔
1228
        remain -= n;
4,300✔
1229

1230
        if ((remain <= 0) || str[0] == 0) {
4,300!
1231
          break;
1232
        }
1233

1234
        int32_t ret = wcsPatternMatch(&pattern[i], psize - i, ++str, --remain, pInfo);
4,059✔
1235
        if (ret != TSDB_PATTERN_NOMATCH) {
4,071✔
1236
          return ret;
2,083✔
1237
        }
1238
      }
1239

1240
      return TSDB_PATTERN_NOWILDCARDMATCH;
241✔
1241
    }
1242

1243
    if (j < ssize) {
379,628,396✔
1244
      c1 = str[j++];
379,628,114✔
1245
      nMatchChar++;
379,628,114✔
1246

1247
      if (c == '\\' && (pattern[i] == '_' || pattern[i] == '%')) {
379,628,114!
1248
        if (c1 != pattern[i]) {
2!
1249
          return TSDB_PATTERN_NOMATCH;
×
1250
        } else {
1251
          i++;
2✔
1252
          continue;
2✔
1253
        }
1254
      }
1255

1256
      if (c == c1 || towlower(c) == towlower(c1) || (c == pInfo->umatchOne && c1 != 0)) {
379,628,112!
1257
        continue;
379,544,501✔
1258
      }
1259
    }
1260

1261
    return TSDB_PATTERN_NOMATCH;
83,893✔
1262
  }
1263

1264
  return (j >= ssize || str[j] == 0) ? TSDB_PATTERN_MATCH : TSDB_PATTERN_NOMATCH;
1,631,092!
1265
}
1266

1267
int32_t comparestrRegexNMatch(const void *pLeft, const void *pRight) {
49,750,322✔
1268
  return comparestrRegexMatch(pLeft, pRight) ? 0 : 1;
49,750,322✔
1269
}
1270

1271
typedef struct UsingRegex {
1272
  regex_t pRegex;
1273
  int32_t lastUsedTime;
1274
} UsingRegex;
1275
typedef UsingRegex* HashRegexPtr;
1276

1277
typedef struct RegexCache {
1278
  SHashObj *regexHash;
1279
  void     *regexCacheTmr;
1280
  void     *timer;
1281
  SRWLatch  mutex;
1282
  bool      exit;
1283
  int8_t    inited;
1284
} RegexCache;
1285
static RegexCache sRegexCache;
1286
#define MAX_REGEX_CACHE_SIZE   20
1287
#define REGEX_CACHE_CLEAR_TIME 30
1288

1289
static void checkRegexCache(void* param, void* tmrId) {
5,828✔
1290
  int32_t  code = 0;
5,828✔
1291
  taosRLockLatch(&sRegexCache.mutex);
5,828✔
1292
  if(sRegexCache.exit) {
5,828!
1293
    goto _exit;
×
1294
  }
1295
  bool stopped = taosTmrReset(checkRegexCache, REGEX_CACHE_CLEAR_TIME * 1000, param, sRegexCache.regexCacheTmr, &tmrId);
5,828✔
1296
  if (stopped) {
5,828!
1297
    uError("failed to reset regex cache timer");
×
1298
    goto _exit;
×
1299
  }
1300
  if (taosHashGetSize(sRegexCache.regexHash) < MAX_REGEX_CACHE_SIZE) {
5,828✔
1301
    goto _exit;
5,765✔
1302
  }
1303

1304
  if (taosHashGetSize(sRegexCache.regexHash) >= MAX_REGEX_CACHE_SIZE) {
63!
1305
    UsingRegex **ppUsingRegex = taosHashIterate(sRegexCache.regexHash, NULL);
63✔
1306
    while ((ppUsingRegex != NULL)) {
1,695✔
1307
      if (taosGetTimestampSec() - (*ppUsingRegex)->lastUsedTime > REGEX_CACHE_CLEAR_TIME) {
1,632✔
1308
        size_t len = 0;
461✔
1309
        char* key = (char*)taosHashGetKey(ppUsingRegex, &len);
461✔
1310
        if (TSDB_CODE_SUCCESS != taosHashRemove(sRegexCache.regexHash, key, len)) {
461!
1311
          uError("failed to remove regex pattern %s from cache", key);
×
1312
          goto _exit;
×
1313
        }
1314
      }
1315
      ppUsingRegex = taosHashIterate(sRegexCache.regexHash, ppUsingRegex);
1,632✔
1316
    }
1317
  }
1318
_exit:
63✔
1319
  taosRUnLockLatch(&sRegexCache.mutex);
5,828✔
1320
}
5,828✔
1321

1322
void regexCacheFree(void *ppUsingRegex) {
1,048✔
1323
  regfree(&(*(UsingRegex **)ppUsingRegex)->pRegex);
1,048✔
1324
  taosMemoryFree(*(UsingRegex **)ppUsingRegex);
1,048!
1325
}
1,048✔
1326

1327
int32_t InitRegexCache() {
21,217✔
1328
  #ifdef WINDOWS
1329
    return 0;
1330
  #endif
1331
  if (atomic_val_compare_exchange_8(&sRegexCache.inited, 0, 1) != 0) return TSDB_CODE_SUCCESS;
21,217!
1332
  sRegexCache.regexHash = taosHashInit(64, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), false, HASH_ENTRY_LOCK);
21,217✔
1333
  if (sRegexCache.regexHash == NULL) {
21,217!
1334
    uError("failed to create RegexCache");
×
1335
    return terrno;
×
1336
  }
1337
  taosHashSetFreeFp(sRegexCache.regexHash, regexCacheFree);
21,217✔
1338
  sRegexCache.regexCacheTmr = taosTmrInit(0, 0, 0, "REGEXCACHE");
21,217✔
1339
  if (sRegexCache.regexCacheTmr == NULL) {
21,217!
1340
    uError("failed to create regex cache check timer");
×
1341
    return terrno;
×
1342
  }
1343

1344
  sRegexCache.exit = false;
21,217✔
1345
  taosInitRWLatch(&sRegexCache.mutex);
21,217✔
1346
  sRegexCache.timer = taosTmrStart(checkRegexCache, REGEX_CACHE_CLEAR_TIME * 1000, NULL, sRegexCache.regexCacheTmr);
21,217✔
1347
  if (sRegexCache.timer == NULL) {
21,217!
1348
    uError("failed to start regex cache timer");
×
1349
    return terrno;
×
1350
  }
1351

1352
  return TSDB_CODE_SUCCESS;
21,217✔
1353
}
1354

1355
void DestroyRegexCache(){
21,217✔
1356
  #ifdef WINDOWS
1357
    return;
1358
  #endif
1359
  int32_t code = 0;
21,217✔
1360
  uInfo("[regex cache] destory regex cache");
21,217!
1361
  bool ret = taosTmrStopA(&sRegexCache.timer);
21,217✔
1362
  if (!ret) {
21,217✔
1363
    uInfo("stop regex cache timer may be failed");
1,845!
1364
  }
1365
  taosWLockLatch(&sRegexCache.mutex);
21,217✔
1366
  sRegexCache.exit = true;
21,217✔
1367
  taosWUnLockLatch(&sRegexCache.mutex);
21,217✔
1368
  taosHashCleanup(sRegexCache.regexHash);
21,217✔
1369
  sRegexCache.regexHash = NULL;
21,217✔
1370
  taosTmrCleanUp(sRegexCache.regexCacheTmr);
21,217✔
1371
  sRegexCache.regexCacheTmr = NULL;
21,217✔
1372
}
21,217✔
1373

1374
int32_t checkRegexPattern(const char *pPattern) {
49,973✔
1375
  if (pPattern == NULL) {
49,973!
1376
    return TSDB_CODE_PAR_REGULAR_EXPRESSION_ERROR;
×
1377
  }
1378

1379
  regex_t regex;
1380
  int32_t cflags = REG_EXTENDED;
49,973✔
1381
  int32_t ret = regcomp(&regex, pPattern, cflags);
49,973✔
1382
  if (ret != 0) {
49,976✔
1383
    char msgbuf[256] = {0};
4,016✔
1384
    (void)regerror(ret, &regex, msgbuf, tListLen(msgbuf));
4,016✔
1385
    uError("Failed to compile regex pattern %s. reason %s", pPattern, msgbuf);
4,016!
1386
    return TSDB_CODE_PAR_REGULAR_EXPRESSION_ERROR;
4,016✔
1387
  }
1388
  regfree(&regex);
45,960✔
1389
  return TSDB_CODE_SUCCESS;
45,958✔
1390
}
1391

1392
int32_t getRegComp(const char *pPattern, HashRegexPtr **regexRet) {
1,893,947✔
1393
  HashRegexPtr* ppUsingRegex = (HashRegexPtr*)taosHashAcquire(sRegexCache.regexHash, pPattern, strlen(pPattern));
1,893,947✔
1394
  if (ppUsingRegex != NULL) {
1,894,027✔
1395
    (*ppUsingRegex)->lastUsedTime = taosGetTimestampSec();
1,892,985✔
1396
    *regexRet = ppUsingRegex;
1,892,892✔
1397
    return TSDB_CODE_SUCCESS;
1,892,892✔
1398
  }
1399
  UsingRegex *pUsingRegex = taosMemoryMalloc(sizeof(UsingRegex));
1,042!
1400
  if (pUsingRegex == NULL) {
1,043!
1401
    uError("Failed to Malloc when compile regex pattern %s.", pPattern);
×
1402
    return terrno;
×
1403
  }
1404
  int32_t cflags = REG_EXTENDED;
1,043✔
1405
  int32_t ret = regcomp(&pUsingRegex->pRegex, pPattern, cflags);
1,043✔
1406
  if (ret != 0) {
1,044!
1407
    char msgbuf[256] = {0};
×
1408
    (void)regerror(ret, &pUsingRegex->pRegex, msgbuf, tListLen(msgbuf));
×
1409
    uError("Failed to compile regex pattern %s. reason %s", pPattern, msgbuf);
×
1410
    taosMemoryFree(pUsingRegex);
×
1411
    return TSDB_CODE_PAR_REGULAR_EXPRESSION_ERROR;
×
1412
  }
1413

1414
  while (true) {
×
1415
    int code = taosHashPut(sRegexCache.regexHash, pPattern, strlen(pPattern), &pUsingRegex, sizeof(UsingRegex *));
1,044✔
1416
    if (code != 0 && code != TSDB_CODE_DUP_KEY) {
1,048!
1417
      regexCacheFree(&pUsingRegex);
×
1418
      uError("Failed to put regex pattern %s into cache, exception internal error.", pPattern);
×
1419
      return code;
×
1420
    } else if (code == TSDB_CODE_DUP_KEY) {
1,048✔
1421
      terrno = 0;
51✔
1422
    }
1423
    ppUsingRegex = (UsingRegex **)taosHashAcquire(sRegexCache.regexHash, pPattern, strlen(pPattern));
1,048✔
1424
    if (ppUsingRegex) {
1,048!
1425
      if (*ppUsingRegex != pUsingRegex) {
1,048✔
1426
        regexCacheFree(&pUsingRegex);
51✔
1427
      }
1428
      pUsingRegex = (*ppUsingRegex);
1,048✔
1429
      break;
1,048✔
1430
    } else {
1431
      continue;
×
1432
    }
1433
  }
1434
  pUsingRegex->lastUsedTime = taosGetTimestampSec();
1,048✔
1435
  *regexRet = ppUsingRegex;
1,048✔
1436
  return TSDB_CODE_SUCCESS;
1,048✔
1437
}
1438

1439
void releaseRegComp(UsingRegex  **regex){
1,393,849✔
1440
  taosHashRelease(sRegexCache.regexHash, regex);
1,393,849✔
1441
}
1,394,056✔
1442

1443
static threadlocal UsingRegex ** ppUsingRegex;
1444
static threadlocal regex_t * pRegex;
1445
static threadlocal char    *pOldPattern = NULL;
1446

1447
#ifdef WINDOWS
1448
static threadlocal regex_t gRegex;
1449

1450
void DestoryThreadLocalRegComp() {
1451
  if (NULL != pOldPattern) {
1452
    regfree(&gRegex);
1453
    taosMemoryFree(pOldPattern);
1454
    pOldPattern = NULL;
1455
  }
1456
}
1457

1458
int32_t threadGetRegComp(regex_t **regex, const char *pPattern) {
1459
  if (NULL != pOldPattern) {
1460
    if (strcmp(pOldPattern, pPattern) == 0) {
1461
      *regex = &gRegex;
1462
      return 0;
1463
    } else {
1464
      DestoryThreadLocalRegComp();
1465
    }
1466
  }
1467
  pOldPattern = taosStrdup(pPattern);
1468
  if (NULL == pOldPattern) {
1469
    uError("Failed to Malloc when compile regex pattern %s.", pPattern);
1470
    return terrno;
1471
  }
1472
  int32_t cflags = REG_EXTENDED;
1473
  int32_t ret = regcomp(&gRegex, pPattern, cflags);
1474
  if (ret != 0) {
1475
    char msgbuf[256] = {0};
1476
    (void)regerror(ret, &gRegex, msgbuf, tListLen(msgbuf));
1477
    uError("Failed to compile regex pattern %s. reason %s", pPattern, msgbuf);
1478
    taosMemoryFree(pOldPattern);
1479
    pOldPattern = NULL;
1480
    return TSDB_CODE_PAR_REGULAR_EXPRESSION_ERROR;
1481
  }
1482
  *regex = &gRegex;
1483
  return 0;
1484
}
1485
#else
1486
void DestoryThreadLocalRegComp() {
3,303,750✔
1487
  if (NULL != pOldPattern) {
3,303,750✔
1488
    releaseRegComp(ppUsingRegex);
1,393,919✔
1489
    taosMemoryFree(pOldPattern);
1,394,054!
1490
    ppUsingRegex = NULL;
1,393,982✔
1491
    pRegex = NULL;
1,393,982✔
1492
    pOldPattern = NULL;
1,393,982✔
1493
  }
1494
}
3,303,813✔
1495

1496
int32_t threadGetRegComp(regex_t **regex, const char *pPattern) {
178,183,558✔
1497
  if (NULL != pOldPattern) {
178,183,558✔
1498
    if (strcmp(pOldPattern, pPattern) == 0) {
178,182,936✔
1499
      *regex = pRegex;
176,847,157✔
1500
      return 0;
176,847,157✔
1501
    } else {
1502
      DestoryThreadLocalRegComp();
1,335,779✔
1503
    }
1504
  }
1505

1506
  HashRegexPtr *ppRegex = NULL;
1,390,278✔
1507
  int32_t code = getRegComp(pPattern, &ppRegex);
1,390,278✔
1508
  if (code != TSDB_CODE_SUCCESS) {
1,393,762!
1509
    return code;
×
1510
  }
1511
  pOldPattern = taosStrdup(pPattern);
1,393,762!
1512
  if (NULL == pOldPattern) {
1,393,813!
1513
    uError("Failed to Malloc when compile regex pattern %s.", pPattern);
×
1514
    return terrno;
×
1515
  }
1516
  ppUsingRegex = ppRegex;
1,393,813✔
1517
  pRegex = &((*ppUsingRegex)->pRegex);
1,393,813✔
1518
  *regex = &(*ppRegex)->pRegex;
1,393,813✔
1519
  return 0;
1,393,813✔
1520
}
1521
#endif
1522

1523
static int32_t doExecRegexMatch(const char *pString, const char *pPattern) {
177,530,883✔
1524
  int32_t ret = 0;
177,530,883✔
1525
  char    msgbuf[256] = {0};
177,530,883✔
1526

1527
  regex_t *regex = NULL;
177,530,883✔
1528
  ret = threadGetRegComp(&regex, pPattern);
177,530,883✔
1529
  if (ret != 0) {
177,585,684!
1530
    return ret;
×
1531
  }
1532

1533
  regmatch_t pmatch[1];
1534
  ret = regexec(regex, pString, 1, pmatch, 0);
177,585,684✔
1535
  if (ret != 0 && ret != REG_NOMATCH) {
177,614,220!
1536
    terrno =  TSDB_CODE_PAR_REGULAR_EXPRESSION_ERROR; 
×
1537
    (void)regerror(ret, regex, msgbuf, sizeof(msgbuf));
×
1538
    uDebug("Failed to match %s with pattern %s, reason %s", pString, pPattern, msgbuf)
×
1539
  }
1540

1541
  return (ret == 0) ? 0 : 1;
177,609,538✔
1542
}
1543

1544
int32_t comparestrRegexMatch(const void *pLeft, const void *pRight) {
100,680,503✔
1545
  size_t sz = varDataLen(pRight);
100,680,503✔
1546
  char  *pattern = taosMemoryMalloc(sz + 1);
100,680,503!
1547
  if (NULL == pattern) {
100,655,673!
1548
    return 1;  // terrno has been set
×
1549
  }
1550

1551
  (void)memcpy(pattern, varDataVal(pRight), varDataLen(pRight));
100,655,673✔
1552
  pattern[sz] = 0;
100,655,673✔
1553

1554
  sz = varDataLen(pLeft);
100,655,673✔
1555
  char *str = taosMemoryMalloc(sz + 1);
100,655,673!
1556
  if (NULL == str) {
100,639,400!
1557
    taosMemoryFree(pattern);
×
1558
    return 1;  // terrno has been set
×
1559
  }
1560

1561
  (void)memcpy(str, varDataVal(pLeft), sz);
100,639,400✔
1562
  str[sz] = 0;
100,639,400✔
1563

1564
  int32_t ret = doExecRegexMatch(str, pattern);
100,639,400✔
1565

1566
  taosMemoryFree(str);
100,697,584!
1567
  taosMemoryFree(pattern);
100,669,935✔
1568

1569
  return (ret == 0) ? 0 : 1;
100,651,672✔
1570
}
1571

1572
int32_t comparewcsRegexMatch(const void *pString, const void *pPattern) {
76,915,590✔
1573
  size_t len = varDataLen(pPattern);
76,915,590✔
1574
  char  *pattern = taosMemoryMalloc(len + 1);
76,915,590!
1575
  if (NULL == pattern) {
76,884,211!
1576
    return 1;  // terrno has been set
×
1577
  }
1578

1579
  int convertLen = taosUcs4ToMbs((TdUcs4 *)varDataVal(pPattern), len, pattern, NULL);
76,884,211✔
1580
  if (convertLen < 0) {
76,937,760!
1581
    taosMemoryFree(pattern);
×
1582
    return 1; // terrno has been set
×
1583
  }
1584

1585
  pattern[convertLen] = 0;
76,937,760✔
1586

1587
  len = varDataLen(pString);
76,937,760✔
1588
  char *str = taosMemoryMalloc(len + 1);
76,937,760✔
1589
  if (NULL == str) {
76,896,376!
1590
    taosMemoryFree(pattern);
×
1591
    return 1; // terrno has been set
×
1592
  }
1593

1594
  convertLen = taosUcs4ToMbs((TdUcs4 *)varDataVal(pString), len, str, NULL);
76,896,376✔
1595
  if (convertLen < 0) {
76,936,368!
1596
    taosMemoryFree(str);
×
1597
    taosMemoryFree(pattern);
×
1598
    return 1; // terrno has been set
×
1599
  }
1600

1601
  str[convertLen] = 0;
76,936,368✔
1602

1603
  int32_t ret = doExecRegexMatch(str, pattern);
76,936,368✔
1604

1605
  taosMemoryFree(str);
76,931,560!
1606
  taosMemoryFree(pattern);
76,904,824✔
1607

1608
  return (ret == 0) ? 0 : 1;
76,892,900✔
1609
}
1610

1611
int32_t comparewcsRegexNMatch(const void *pLeft, const void *pRight) {
23,841,021✔
1612
  return comparewcsRegexMatch(pLeft, pRight) ? 0 : 1;
23,841,021✔
1613
}
1614

1615
int32_t taosArrayCompareString(const void *a, const void *b) {
231✔
1616
  const char *x = *(const char **)a;
231✔
1617
  const char *y = *(const char **)b;
231✔
1618

1619
  return strcmp(x, y);
231✔
1620
}
1621

1622
int32_t comparestrPatternMatch(const void *pLeft, const void *pRight) {
78,687,235✔
1623
  SPatternCompareInfo pInfo = PATTERN_COMPARE_INFO_INITIALIZER;
78,687,235✔
1624

1625
  if (varDataTLen(pRight) > TSDB_MAX_FIELD_LEN) {
78,687,235!
1626
    return 1;
×
1627
  }
1628
  size_t pLen = varDataLen(pRight);
78,687,235✔
1629
  size_t sz = varDataLen(pLeft);
78,687,235✔
1630

1631
  int32_t ret = patternMatch(varDataVal(pRight), pLen, varDataVal(pLeft), sz, &pInfo);
78,687,235✔
1632
  return (ret == TSDB_PATTERN_MATCH) ? 0 : 1;
78,662,498✔
1633
}
1634

1635
int32_t comparestrPatternNMatch(const void *pLeft, const void *pRight) {
1,704,390✔
1636
  return comparestrPatternMatch(pLeft, pRight) ? 0 : 1;
1,704,390✔
1637
}
1638

1639
int32_t comparewcsPatternMatch(const void *pLeft, const void *pRight) {
75,693,239✔
1640
  SPatternCompareInfo pInfo = PATTERN_COMPARE_INFO_INITIALIZER;
75,693,239✔
1641

1642
  size_t psize = varDataLen(pRight);
75,693,239✔
1643

1644
  int32_t ret = wcsPatternMatch((TdUcs4 *)varDataVal(pRight), psize / TSDB_NCHAR_SIZE, (TdUcs4 *)varDataVal(pLeft),
75,693,239✔
1645
                                varDataLen(pLeft) / TSDB_NCHAR_SIZE, &pInfo);
75,693,239✔
1646
  return (ret == TSDB_PATTERN_MATCH) ? 0 : 1;
75,670,904✔
1647
}
1648

1649
int32_t comparewcsPatternNMatch(const void *pLeft, const void *pRight) {
1,610,769✔
1650
  return comparewcsPatternMatch(pLeft, pRight) ? 0 : 1;
1,610,769✔
1651
}
1652

1653
__compar_fn_t getComparFunc(int32_t type, int32_t optr) {
9,280,985✔
1654
  __compar_fn_t comparFn = NULL;
9,280,985✔
1655

1656
  if (optr == OP_TYPE_IN && (type != TSDB_DATA_TYPE_BINARY && type != TSDB_DATA_TYPE_VARBINARY &&
9,280,985!
1657
                             type != TSDB_DATA_TYPE_NCHAR && type != TSDB_DATA_TYPE_GEOMETRY)) {
×
1658
    switch (type) {
×
1659
      case TSDB_DATA_TYPE_BOOL:
×
1660
      case TSDB_DATA_TYPE_TINYINT:
1661
      case TSDB_DATA_TYPE_UTINYINT:
1662
        return setChkInBytes1;
×
1663
      case TSDB_DATA_TYPE_SMALLINT:
×
1664
      case TSDB_DATA_TYPE_USMALLINT:
1665
        return setChkInBytes2;
×
1666
      case TSDB_DATA_TYPE_INT:
×
1667
      case TSDB_DATA_TYPE_UINT:
1668
      case TSDB_DATA_TYPE_FLOAT:
1669
        return setChkInBytes4;
×
1670
      case TSDB_DATA_TYPE_BIGINT:
×
1671
      case TSDB_DATA_TYPE_UBIGINT:
1672
      case TSDB_DATA_TYPE_DOUBLE:
1673
      case TSDB_DATA_TYPE_TIMESTAMP:
1674
        return setChkInBytes8;
×
1675
      default:
×
1676
        uError("getComparFunc data type unexpected type:%d, optr:%d", type, optr);
×
1677
        terrno = TSDB_CODE_FUNC_FUNTION_PARA_TYPE;
×
1678
        return NULL;
×
1679
    }
1680
  }
1681

1682
  if (optr == OP_TYPE_NOT_IN && (type != TSDB_DATA_TYPE_BINARY && type != TSDB_DATA_TYPE_VARBINARY &&
9,280,985!
1683
                                 type != TSDB_DATA_TYPE_NCHAR && type != TSDB_DATA_TYPE_GEOMETRY)) {
×
1684
    switch (type) {
×
1685
      case TSDB_DATA_TYPE_BOOL:
×
1686
      case TSDB_DATA_TYPE_TINYINT:
1687
      case TSDB_DATA_TYPE_UTINYINT:
1688
        return setChkNotInBytes1;
×
1689
      case TSDB_DATA_TYPE_SMALLINT:
×
1690
      case TSDB_DATA_TYPE_USMALLINT:
1691
        return setChkNotInBytes2;
×
1692
      case TSDB_DATA_TYPE_INT:
×
1693
      case TSDB_DATA_TYPE_UINT:
1694
      case TSDB_DATA_TYPE_FLOAT:
1695
        return setChkNotInBytes4;
×
1696
      case TSDB_DATA_TYPE_BIGINT:
×
1697
      case TSDB_DATA_TYPE_UBIGINT:
1698
      case TSDB_DATA_TYPE_DOUBLE:
1699
      case TSDB_DATA_TYPE_TIMESTAMP:
1700
        return setChkNotInBytes8;
×
1701
      default:
×
1702
        uError("getComparFunc data type unexpected type:%d, optr:%d", type, optr);
×
1703
        terrno = TSDB_CODE_FUNC_FUNTION_PARA_TYPE;
×
1704
        return NULL;
×
1705
    }
1706
  }
1707

1708
  switch (type) {
9,280,985!
1709
    case TSDB_DATA_TYPE_BOOL:
1,602,396✔
1710
    case TSDB_DATA_TYPE_TINYINT:
1711
      comparFn = compareInt8Val;
1,602,396✔
1712
      break;
1,602,396✔
1713
    case TSDB_DATA_TYPE_SMALLINT:
559,989✔
1714
      comparFn = compareInt16Val;
559,989✔
1715
      break;
559,989✔
1716
    case TSDB_DATA_TYPE_INT:
1,839,194✔
1717
      comparFn = compareInt32Val;
1,839,194✔
1718
      break;
1,839,194✔
1719
    case TSDB_DATA_TYPE_BIGINT:
1,521,916✔
1720
    case TSDB_DATA_TYPE_TIMESTAMP:
1721
      comparFn = compareInt64Val;
1,521,916✔
1722
      break;
1,521,916✔
1723
    case TSDB_DATA_TYPE_FLOAT:
245,821✔
1724
      comparFn = compareFloatVal;
245,821✔
1725
      break;
245,821✔
1726
    case TSDB_DATA_TYPE_DOUBLE:
2,362,656✔
1727
      comparFn = compareDoubleVal;
2,362,656✔
1728
      break;
2,362,656✔
1729
    case TSDB_DATA_TYPE_VARBINARY:
2,735✔
1730
      if (optr == OP_TYPE_IN) {
2,735!
1731
        comparFn = compareChkInString;
×
1732
      } else if (optr == OP_TYPE_NOT_IN) {
2,735!
1733
        comparFn = compareChkNotInString;
×
1734
      } else { /* normal relational comparFn */
1735
        comparFn = compareLenBinaryVal;
2,735✔
1736
      }
1737
      break;
2,735✔
1738
    case TSDB_DATA_TYPE_BINARY:
91,773✔
1739
    case TSDB_DATA_TYPE_GEOMETRY: {
1740
      if (optr == OP_TYPE_MATCH) {
91,773!
1741
        comparFn = comparestrRegexMatch;
×
1742
      } else if (optr == OP_TYPE_NMATCH) {
91,773!
1743
        comparFn = comparestrRegexNMatch;
×
1744
      } else if (optr == OP_TYPE_LIKE) { /* wildcard query using like operator */
91,773!
1745
        comparFn = comparestrPatternMatch;
×
1746
      } else if (optr == OP_TYPE_NOT_LIKE) { /* wildcard query using like operator */
91,773!
1747
        comparFn = comparestrPatternNMatch;
×
1748
      } else if (optr == OP_TYPE_IN) {
91,773!
1749
        comparFn = compareChkInString;
×
1750
      } else if (optr == OP_TYPE_NOT_IN) {
91,773!
1751
        comparFn = compareChkNotInString;
×
1752
      } else { /* normal relational comparFn */
1753
        comparFn = compareLenPrefixedStr;
91,773✔
1754
      }
1755

1756
      break;
91,773✔
1757
    }
1758

1759
    case TSDB_DATA_TYPE_NCHAR: {
30,717✔
1760
      if (optr == OP_TYPE_MATCH) {
30,717!
1761
        comparFn = comparewcsRegexMatch;
×
1762
      } else if (optr == OP_TYPE_NMATCH) {
30,717!
1763
        comparFn = comparewcsRegexNMatch;
×
1764
      } else if (optr == OP_TYPE_LIKE) {
30,717!
1765
        comparFn = comparewcsPatternMatch;
×
1766
      } else if (optr == OP_TYPE_NOT_LIKE) {
30,717!
1767
        comparFn = comparewcsPatternNMatch;
×
1768
      } else if (optr == OP_TYPE_IN) {
30,717!
1769
        comparFn = compareChkInString;
×
1770
      } else if (optr == OP_TYPE_NOT_IN) {
30,717!
1771
        comparFn = compareChkNotInString;
×
1772
      } else {
1773
        comparFn = compareLenPrefixedWStr;
30,717✔
1774
      }
1775
      break;
30,717✔
1776
    }
1777

1778
    case TSDB_DATA_TYPE_UTINYINT:
1,507✔
1779
      comparFn = compareUint8Val;
1,507✔
1780
      break;
1,507✔
1781
    case TSDB_DATA_TYPE_USMALLINT:
668,192✔
1782
      comparFn = compareUint16Val;
668,192✔
1783
      break;
668,192✔
1784
    case TSDB_DATA_TYPE_UINT:
2,759✔
1785
      comparFn = compareUint32Val;
2,759✔
1786
      break;
2,759✔
1787
    case TSDB_DATA_TYPE_UBIGINT:
354,358✔
1788
      comparFn = compareUint64Val;
354,358✔
1789
      break;
354,358✔
1790

UNCOV
1791
    default:
×
UNCOV
1792
      comparFn = compareInt32Val;
×
UNCOV
1793
      break;
×
1794
  }
1795

1796
  return comparFn;
9,280,985✔
1797
}
1798

1799
__compar_fn_t getKeyComparFunc(int32_t keyType, int32_t order) {
576,879,167✔
1800
  switch (keyType) {
576,879,167!
1801
    case TSDB_DATA_TYPE_TINYINT:
30,001✔
1802
    case TSDB_DATA_TYPE_BOOL:
1803
      return (order == TSDB_ORDER_ASC) ? compareInt8Val : compareInt8ValDesc;
30,001✔
1804
    case TSDB_DATA_TYPE_SMALLINT:
41,100✔
1805
      return (order == TSDB_ORDER_ASC) ? compareInt16Val : compareInt16ValDesc;
41,100✔
1806
    case TSDB_DATA_TYPE_INT:
2,557,039✔
1807
      return (order == TSDB_ORDER_ASC) ? compareInt32Val : compareInt32ValDesc;
2,557,039✔
1808
    case TSDB_DATA_TYPE_BIGINT:
570,875,056✔
1809
    case TSDB_DATA_TYPE_TIMESTAMP:
1810
      return (order == TSDB_ORDER_ASC) ? compareInt64Val : compareInt64ValDesc;
570,875,056✔
1811
    case TSDB_DATA_TYPE_FLOAT:
12,658✔
1812
      return (order == TSDB_ORDER_ASC) ? compareFloatVal : compareFloatValDesc;
12,658✔
1813
    case TSDB_DATA_TYPE_DOUBLE:
156,363✔
1814
      return (order == TSDB_ORDER_ASC) ? compareDoubleVal : compareDoubleValDesc;
156,363✔
1815
    case TSDB_DATA_TYPE_UTINYINT:
268✔
1816
      return (order == TSDB_ORDER_ASC) ? compareUint8Val : compareUint8ValDesc;
268!
1817
    case TSDB_DATA_TYPE_USMALLINT:
260✔
1818
      return (order == TSDB_ORDER_ASC) ? compareUint16Val : compareUint16ValDesc;
260!
1819
    case TSDB_DATA_TYPE_UINT:
808,435✔
1820
      return (order == TSDB_ORDER_ASC) ? compareUint32Val : compareUint32ValDesc;
808,435✔
1821
    case TSDB_DATA_TYPE_UBIGINT:
840,963✔
1822
      return (order == TSDB_ORDER_ASC) ? compareUint64Val : compareUint64ValDesc;
840,963✔
1823
    case TSDB_DATA_TYPE_VARBINARY:
3✔
1824
      return (order == TSDB_ORDER_ASC) ? compareLenBinaryVal : compareLenBinaryValDesc;
3!
1825
    case TSDB_DATA_TYPE_BINARY:
1,911,801✔
1826
    case TSDB_DATA_TYPE_GEOMETRY:
1827
      return (order == TSDB_ORDER_ASC) ? compareLenPrefixedStr : compareLenPrefixedStrDesc;
1,911,801✔
1828
    case TSDB_DATA_TYPE_NCHAR:
95,259✔
1829
      return (order == TSDB_ORDER_ASC) ? compareLenPrefixedWStr : compareLenPrefixedWStrDesc;
95,259✔
1830
    case TSDB_DATA_TYPE_JSON:
48✔
1831
      return (order == TSDB_ORDER_ASC) ? compareJsonVal : compareJsonValDesc;
48✔
1832
    case TSDB_DATA_TYPE_DECIMAL64:
20✔
1833
      return (order == TSDB_ORDER_ASC) ? compareDecimal64SameScale : compareDecimal64SameScaleDesc;
20!
1834
    case TSDB_DATA_TYPE_DECIMAL:
60✔
1835
      return (order == TSDB_ORDER_ASC) ? compareDecimal128SameScale : compareDecimal128SameScaleDesc;
60!
UNCOV
1836
    default:
×
UNCOV
1837
      return (order == TSDB_ORDER_ASC) ? compareInt32Val : compareInt32ValDesc;
×
1838
  }
1839
}
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

© 2025 Coveralls, Inc