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

taosdata / TDengine / #4667

14 Aug 2025 01:04PM UTC coverage: 59.532% (-0.6%) from 60.112%
#4667

push

travis-ci

web-flow
fix(query): fix order by column check of union operator (#32524)

136437 of 292055 branches covered (46.72%)

Branch coverage included in aggregate %.

1 of 13 new or added lines in 1 file covered. (7.69%)

2683 existing lines in 164 files now uncovered.

206730 of 284385 relevant lines covered (72.69%)

4603587.36 hits per line

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

65.57
/source/dnode/vnode/src/meta/metaEntry.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

16
#include "meta.h"
17
#include "osMemPool.h"
18
#include "osMemory.h"
19
#include "tencode.h"
20
#include "tmsg.h"
21

22
static bool schemasHasTypeMod(const SSchema *pSchema, int32_t nCols) {
3,268,721✔
23
  for (int32_t i = 0; i < nCols; i++) {
60,557,922✔
24
    if (HAS_TYPE_MOD(pSchema + i)) {
57,380,554✔
25
      return true;
91,353✔
26
    }
27
  }
28
  return false;
3,177,368✔
29
}
30

31
static int32_t metaEncodeExtSchema(SEncoder* pCoder, const SMetaEntry* pME) {
459,404✔
32
  if (pME->pExtSchemas) {
459,404✔
33
    const SSchemaWrapper *pSchWrapper = NULL;
26,569✔
34
    bool                  hasTypeMods = false;
26,569✔
35
    if (pME->type == TSDB_SUPER_TABLE) {
26,569✔
36
      pSchWrapper = &pME->stbEntry.schemaRow;
26,385✔
37
    } else if (pME->type == TSDB_NORMAL_TABLE) {
184!
38
      pSchWrapper = &pME->ntbEntry.schemaRow;
184✔
39
    } else {
40
      return 0;
×
41
    }
42
    hasTypeMods = schemasHasTypeMod(pSchWrapper->pSchema, pSchWrapper->nCols);
26,569✔
43

44
    for (int32_t i = 0; i < pSchWrapper->nCols && hasTypeMods; ++i) {
5,504,903✔
45
      TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pME->pExtSchemas[i].typeMod));
10,956,668!
46
    }
47
  }
48
  return 0;
459,404✔
49
}
50

51
int meteEncodeColRefEntry(SEncoder *pCoder, const SMetaEntry *pME) {
1,528✔
52
  const SColRefWrapper *pw = &pME->colRef;
1,528✔
53
  TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pw->nCols));
3,056!
54
  TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pw->version));
3,056!
55
  uTrace("encode cols:%d", pw->nCols);
1,528!
56

57
  for (int32_t i = 0; i < pw->nCols; i++) {
16,388✔
58
    SColRef *p = &pw->pColRef[i];
14,860✔
59
    TAOS_CHECK_RETURN(tEncodeI8(pCoder, p->hasRef));
29,720!
60
    TAOS_CHECK_RETURN(tEncodeI16v(pCoder, p->id));
29,720!
61
    if (p->hasRef) {
14,860✔
62
      TAOS_CHECK_RETURN(tEncodeCStr(pCoder, p->refDbName));
17,132!
63
      TAOS_CHECK_RETURN(tEncodeCStr(pCoder, p->refTableName));
17,132!
64
      TAOS_CHECK_RETURN(tEncodeCStr(pCoder, p->refColName));
17,132!
65
    }
66
  }
67
  return 0;
1,528✔
68
}
69

70
static int32_t metaDecodeExtSchemas(SDecoder* pDecoder, SMetaEntry* pME) {
3,109,404✔
71
  bool hasExtSchema = false;
3,109,404✔
72
  SSchemaWrapper* pSchWrapper = NULL;
3,109,404✔
73
  if (pME->type == TSDB_SUPER_TABLE) {
3,109,404✔
74
    pSchWrapper = &pME->stbEntry.schemaRow;
3,106,420✔
75
  } else if (pME->type == TSDB_NORMAL_TABLE) {
2,984!
76
    pSchWrapper = &pME->ntbEntry.schemaRow;
3,410✔
77
  } else {
78
    return 0;
×
79
  }
80

81
  hasExtSchema = schemasHasTypeMod(pSchWrapper->pSchema, pSchWrapper->nCols);
3,109,830✔
82
  if (hasExtSchema && pSchWrapper->nCols > 0) {
3,111,498!
83
    pME->pExtSchemas = (SExtSchema*)tDecoderMalloc(pDecoder, sizeof(SExtSchema) * pSchWrapper->nCols);
69,193!
84
    if (pME->pExtSchemas == NULL) {
69,199!
85
      return terrno;
×
86
    }
87

88
    for (int32_t i = 0; i < pSchWrapper->nCols && hasExtSchema; i++) {
7,493,775!
89
      TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pME->pExtSchemas[i].typeMod));
14,849,214!
90
    }
91
  }
92

93
  return 0;
3,111,442✔
94
}
95

96
SExtSchema* metaGetSExtSchema(const SMetaEntry *pME) {
132,826✔
97
  const SSchemaWrapper *pSchWrapper = NULL;
132,826✔
98
  bool                  hasTypeMods = false;
132,826✔
99
  if (pME->type == TSDB_SUPER_TABLE) {
132,826✔
100
    pSchWrapper = &pME->stbEntry.schemaRow;
92,836✔
101
  } else if (pME->type == TSDB_NORMAL_TABLE) {
39,990!
102
    pSchWrapper = &pME->ntbEntry.schemaRow;
40,021✔
103
  } else {
104
    return NULL;
×
105
  }
106
  hasTypeMods = schemasHasTypeMod(pSchWrapper->pSchema, pSchWrapper->nCols);
132,857✔
107

108
  if (hasTypeMods) {
132,857✔
109
    SExtSchema *ret = taosMemoryMalloc(sizeof(SExtSchema) * pSchWrapper->nCols);
138!
110
    if (ret != NULL) {
118!
111
      memcpy(ret, pME->pExtSchemas, pSchWrapper->nCols * sizeof(SExtSchema));
118✔
112
    }
113
    return ret;
118✔
114
  }
115
  return NULL;
132,719✔
116
}
117

118
int meteDecodeColRefEntry(SDecoder *pDecoder, SMetaEntry *pME) {
5,062✔
119
  SColRefWrapper *pWrapper = &pME->colRef;
5,062✔
120
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pWrapper->nCols));
10,123!
121
  if (pWrapper->nCols == 0) {
5,061!
122
    return 0;
×
123
  }
124

125
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pWrapper->version));
10,122!
126
  uDebug("decode cols:%d", pWrapper->nCols);
5,061!
127
  pWrapper->pColRef = (SColRef *)tDecoderMalloc(pDecoder, pWrapper->nCols * sizeof(SColRef));
5,061!
128
  if (pWrapper->pColRef == NULL) {
5,066!
129
    return terrno;
×
130
  }
131

132
  for (int i = 0; i < pWrapper->nCols; i++) {
69,298✔
133
    SColRef *p = &pWrapper->pColRef[i];
64,273✔
134
    TAOS_CHECK_RETURN(tDecodeI8(pDecoder, (int8_t *)&p->hasRef));
128,496!
135
    TAOS_CHECK_RETURN(tDecodeI16v(pDecoder, &p->id));
128,450!
136
    if (p->hasRef) {
64,227✔
137
      TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, p->refDbName));
36,102!
138
      TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, p->refTableName));
36,114!
139
      TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, p->refColName));
36,124✔
140
    }
141
  }
142
  return 0;
5,025✔
143
}
144

145
static FORCE_INLINE int32_t metatInitDefaultSColRefWrapper(SDecoder *pDecoder, SColRefWrapper *pRef,
146
                                                            SSchemaWrapper *pSchema) {
147
  pRef->nCols = pSchema->nCols;
×
148
  if ((pRef->pColRef = (SColRef *)tDecoderMalloc(pDecoder, pRef->nCols * sizeof(SColRef))) == NULL) {
×
149
    return terrno;
×
150
  }
151

152
  for (int32_t i = 0; i < pRef->nCols; i++) {
×
153
    SColRef  *pColRef = &pRef->pColRef[i];
×
154
    SSchema  *pColSchema = &pSchema->pSchema[i];
×
155
    pColRef->id = pColSchema->colId;
×
156
    pColRef->hasRef = false;
×
157
  }
158
  return 0;
×
159
}
160

161
static int32_t metaCloneColRef(const SColRefWrapper*pSrc, SColRefWrapper *pDst) {
764✔
162
  if (pSrc->nCols > 0) {
764!
163
    pDst->nCols = pSrc->nCols;
764✔
164
    pDst->version = pSrc->version;
764✔
165
    pDst->pColRef = (SColRef*)taosMemoryCalloc(pSrc->nCols, sizeof(SColRef));
764!
166
    if (NULL == pDst->pColRef) {
764!
167
      return terrno;
×
168
    }
169
    memcpy(pDst->pColRef, pSrc->pColRef, pSrc->nCols * sizeof(SColRef));
764✔
170
  }
171
  return 0;
764✔
172
}
173

174
static int32_t metaEncodeComprEntryImpl(SEncoder *pCoder, SColCmprWrapper *pw) {
121,068✔
175
  int32_t code = 0;
121,068✔
176
  TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pw->nCols));
242,136!
177
  TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pw->version));
242,136!
178
  uTrace("encode cols:%d", pw->nCols);
121,068✔
179

180
  for (int32_t i = 0; i < pw->nCols; i++) {
24,165,877✔
181
    SColCmpr *p = &pw->pColCmpr[i];
24,044,697✔
182
    TAOS_CHECK_RETURN(tEncodeI16v(pCoder, p->id));
48,089,394!
183
    TAOS_CHECK_RETURN(tEncodeU32(pCoder, p->alg));
48,089,394!
184
  }
185
  return code;
121,180✔
186
}
187
int meteEncodeColCmprEntry(SEncoder *pCoder, const SMetaEntry *pME) {
121,091✔
188
  const SColCmprWrapper *pw = &pME->colCmpr;
121,091✔
189
  return metaEncodeComprEntryImpl(pCoder, (SColCmprWrapper *)pw);
121,091✔
190
}
191
int meteDecodeColCmprEntry(SDecoder *pDecoder, SMetaEntry *pME) {
3,688,976✔
192
  SColCmprWrapper *pWrapper = &pME->colCmpr;
3,688,976✔
193
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pWrapper->nCols));
7,378,402!
194
  if (pWrapper->nCols == 0) {
3,689,426!
195
    return 0;
×
196
  }
197

198
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pWrapper->version));
7,379,425!
199
  uDebug("dencode cols:%d", pWrapper->nCols);
3,689,999✔
200
  pWrapper->pColCmpr = (SColCmpr *)tDecoderMalloc(pDecoder, pWrapper->nCols * sizeof(SColCmpr));
3,690,037✔
201
  if (pWrapper->pColCmpr == NULL) {
3,692,827!
202
    return terrno;
×
203
  }
204

205
  for (int i = 0; i < pWrapper->nCols; i++) {
90,475,175✔
206
    SColCmpr *p = &pWrapper->pColCmpr[i];
86,796,101✔
207
    TAOS_CHECK_RETURN(tDecodeI16v(pDecoder, &p->id));
173,584,071!
208
    TAOS_CHECK_RETURN(tDecodeU32(pDecoder, &p->alg));
173,570,318!
209
  }
210
  return 0;
3,679,074✔
211
}
212
static FORCE_INLINE int32_t metatInitDefaultSColCmprWrapper(SDecoder *pDecoder, SColCmprWrapper *pCmpr,
213
                                                            SSchemaWrapper *pSchema) {
214
  pCmpr->nCols = pSchema->nCols;
31✔
215

216
  if (pDecoder == NULL) {
31✔
217
    pCmpr->pColCmpr = taosMemoryCalloc(1, pCmpr->nCols * sizeof(SColCmpr));
362!
218
  } else {
219
    pCmpr->pColCmpr = (SColCmpr *)tDecoderMalloc(pDecoder, pCmpr->nCols * sizeof(SColCmpr));
×
220
  }
221

222
  if (pCmpr->pColCmpr == NULL) {
362!
223
    return terrno;
×
224
  }
225

226
  for (int32_t i = 0; i < pCmpr->nCols; i++) {
1,592!
227
    SColCmpr *pColCmpr = &pCmpr->pColCmpr[i];
1,230✔
228
    SSchema  *pColSchema = &pSchema->pSchema[i];
1,230✔
229
    pColCmpr->id = pColSchema->colId;
1,230✔
230
    pColCmpr->alg = createDefaultColCmprByType(pColSchema->type);
1,230✔
231
  }
232
  return 0;
362✔
233
}
234

235
static int32_t metaCloneColCmpr(const SColCmprWrapper *pSrc, SColCmprWrapper *pDst) {
432,340✔
236
  if (pSrc->nCols > 0) {
432,340✔
237
    pDst->nCols = pSrc->nCols;
390,203✔
238
    pDst->version = pSrc->version;
390,203✔
239
    pDst->pColCmpr = (SColCmpr *)taosMemoryCalloc(pSrc->nCols, sizeof(SColCmpr));
390,203!
240
    if (NULL == pDst->pColCmpr) {
390,329!
241
      return terrno;
×
242
    }
243
    memcpy(pDst->pColCmpr, pSrc->pColCmpr, pSrc->nCols * sizeof(SColCmpr));
390,329✔
244
  }
245
  return 0;
432,466✔
246
}
247

248
static void metaCloneColRefFree(SColRefWrapper *pColRef) {
433,214✔
249
  if (pColRef) {
433,214!
250
    taosMemoryFreeClear(pColRef->pColRef);
433,216!
251
  }
252
}
433,214✔
253

254
static void metaCloneColCmprFree(SColCmprWrapper *pCmpr) {
433,185✔
255
  if (pCmpr) {
433,185!
256
    taosMemoryFreeClear(pCmpr->pColCmpr);
433,198!
257
  }
258
}
433,223✔
259

260
int metaEncodeEntry(SEncoder *pCoder, const SMetaEntry *pME) {
496,000✔
261
  TAOS_CHECK_RETURN(tStartEncode(pCoder));
496,000✔
262
  TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->version));
993,658!
263
  TAOS_CHECK_RETURN(tEncodeI8(pCoder, pME->type));
993,658!
264
  TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->uid));
993,658!
265

266
  if (pME->type > 0) {
496,829✔
267
    if (pME->name == NULL) {
460,419!
268
      return TSDB_CODE_INVALID_PARA;
×
269
    }
270

271
    TAOS_CHECK_RETURN(tEncodeCStr(pCoder, pME->name));
920,838!
272

273
    if (pME->type == TSDB_SUPER_TABLE) {
460,419✔
274
      TAOS_CHECK_RETURN(tEncodeI8(pCoder, pME->flags));
173,180!
275
      TAOS_CHECK_RETURN(tEncodeSSchemaWrapper(pCoder, &pME->stbEntry.schemaRow));
173,180!
276
      TAOS_CHECK_RETURN(tEncodeSSchemaWrapper(pCoder, &pME->stbEntry.schemaTag));
173,180!
277
      if (TABLE_IS_ROLLUP(pME->flags)) {
86,590!
278
        TAOS_CHECK_RETURN(tEncodeSRSmaParam(pCoder, &pME->stbEntry.rsmaParam));
×
279
      }
280
    } else if (pME->type == TSDB_CHILD_TABLE || pME->type == TSDB_VIRTUAL_CHILD_TABLE) {
373,829✔
281
      TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->ctbEntry.btime));
675,730!
282
      TAOS_CHECK_RETURN(tEncodeI32(pCoder, pME->ctbEntry.ttlDays));
675,730!
283
      TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pME->ctbEntry.commentLen));
675,730!
284
      if (pME->ctbEntry.commentLen > 0) {
337,865✔
285
        TAOS_CHECK_RETURN(tEncodeCStr(pCoder, pME->ctbEntry.comment));
156!
286
      }
287
      TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->ctbEntry.suid));
675,730!
288
      TAOS_CHECK_RETURN(tEncodeTag(pCoder, (const STag *)pME->ctbEntry.pTags));
337,865!
289
    } else if (pME->type == TSDB_NORMAL_TABLE || pME->type == TSDB_VIRTUAL_NORMAL_TABLE) {
35,964!
290
      TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->ntbEntry.btime));
71,928!
291
      TAOS_CHECK_RETURN(tEncodeI32(pCoder, pME->ntbEntry.ttlDays));
71,928!
292
      TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pME->ntbEntry.commentLen));
71,928!
293
      if (pME->ntbEntry.commentLen > 0) {
35,964✔
294
        TAOS_CHECK_RETURN(tEncodeCStr(pCoder, pME->ntbEntry.comment));
156!
295
      }
296
      TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pME->ntbEntry.ncid));
71,928!
297
      TAOS_CHECK_RETURN(tEncodeSSchemaWrapper(pCoder, &pME->ntbEntry.schemaRow));
71,928!
298
    } else if (pME->type == TSDB_TSMA_TABLE) {
×
299
      TAOS_CHECK_RETURN(tEncodeTSma(pCoder, pME->smaEntry.tsma));
×
300
    } else {
301
      metaError("meta/entry: invalide table type: %" PRId8 " encode failed.", pME->type);
×
302
      return TSDB_CODE_INVALID_PARA;
×
303
    }
304
    if (pME->type == TSDB_VIRTUAL_NORMAL_TABLE || pME->type == TSDB_VIRTUAL_CHILD_TABLE) {
460,361✔
305
      TAOS_CHECK_RETURN(meteEncodeColRefEntry(pCoder, pME));
1,646!
306
    } else {
307
      if (pME->type == TSDB_SUPER_TABLE && TABLE_IS_COL_COMPRESSED(pME->flags)) {
458,715!
308
        TAOS_CHECK_RETURN(meteEncodeColCmprEntry(pCoder, pME));
86,493✔
309
      } else if (pME->type == TSDB_NORMAL_TABLE) {
372,222✔
310
        if (pME->colCmpr.nCols != 0) {
35,002✔
311
          TAOS_CHECK_RETURN(meteEncodeColCmprEntry(pCoder, pME));
34,640!
312
        } else {
313
          metaWarn("meta/entry: failed to get compress cols, type:%d", pME->type);
362!
314
          SColCmprWrapper colCmprs = {0};
362✔
315
          int32_t code = metatInitDefaultSColCmprWrapper(NULL, &colCmprs, (SSchemaWrapper *)&pME->ntbEntry.schemaRow);
362!
316
          if (code != 0) {
362!
317
            taosMemoryFree(colCmprs.pColCmpr);
×
318
            TAOS_CHECK_RETURN(code);
×
319
          }
320
          code = metaEncodeComprEntryImpl(pCoder, &colCmprs);
362✔
321
          taosMemoryFree(colCmprs.pColCmpr);
362!
322
          TAOS_CHECK_RETURN(code);
362!
323
        }
324
      }
325
    }
326
    TAOS_CHECK_RETURN(metaEncodeExtSchema(pCoder, pME));
459,907!
327
  }
328
  if (pME->type == TSDB_SUPER_TABLE) {
496,717✔
329
    TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->stbEntry.keep));
173,100!
330
  }
331

332
  tEndEncode(pCoder);
496,717✔
333
  return 0;
496,748✔
334
}
335

336
int metaDecodeEntryImpl(SDecoder *pCoder, SMetaEntry *pME, bool headerOnly) {
6,252,626✔
337
  TAOS_CHECK_RETURN(tStartDecode(pCoder));
6,252,626!
338
  TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->version));
12,504,224!
339
  TAOS_CHECK_RETURN(tDecodeI8(pCoder, &pME->type));
12,501,735!
340
  TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->uid));
12,497,151!
341

342
  if (headerOnly) {
6,246,558✔
343
    tEndDecode(pCoder);
1,214✔
344
    return 0;
1,214✔
345
  }
346

347
  if (pME->type > 0) {
6,245,344!
348
    TAOS_CHECK_RETURN(tDecodeCStr(pCoder, &pME->name));
12,492,789!
349

350
    if (pME->type == TSDB_SUPER_TABLE) {
6,246,261✔
351
      TAOS_CHECK_RETURN(tDecodeI8(pCoder, &pME->flags));
6,210,059!
352
      TAOS_CHECK_RETURN(tDecodeSSchemaWrapperEx(pCoder, &pME->stbEntry.schemaRow));
6,193,065!
353
      TAOS_CHECK_RETURN(tDecodeSSchemaWrapperEx(pCoder, &pME->stbEntry.schemaTag));
6,181,443!
354
      if (TABLE_IS_ROLLUP(pME->flags)) {
3,093,066!
355
        TAOS_CHECK_RETURN(tDecodeSRSmaParam(pCoder, &pME->stbEntry.rsmaParam));
×
356
      }
357
    } else if (pME->type == TSDB_CHILD_TABLE || pME->type == TSDB_VIRTUAL_CHILD_TABLE) {
3,140,890✔
358
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->ctbEntry.btime));
5,110,457!
359
      TAOS_CHECK_RETURN(tDecodeI32(pCoder, &pME->ctbEntry.ttlDays));
5,109,806!
360
      TAOS_CHECK_RETURN(tDecodeI32v(pCoder, &pME->ctbEntry.commentLen));
5,108,564!
361
      if (pME->ctbEntry.commentLen > 0) {
2,553,961✔
362
        TAOS_CHECK_RETURN(tDecodeCStr(pCoder, &pME->ctbEntry.comment));
308!
363
      }
364
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->ctbEntry.suid));
5,107,373!
365
      TAOS_CHECK_RETURN(tDecodeTag(pCoder, (STag **)&pME->ctbEntry.pTags));
2,553,412!
366
    } else if (pME->type == TSDB_NORMAL_TABLE || pME->type == TSDB_VIRTUAL_NORMAL_TABLE) {
585,636!
367
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->ntbEntry.btime));
1,171,091!
368
      TAOS_CHECK_RETURN(tDecodeI32(pCoder, &pME->ntbEntry.ttlDays));
1,170,756!
369
      TAOS_CHECK_RETURN(tDecodeI32v(pCoder, &pME->ntbEntry.commentLen));
1,170,261!
370
      if (pME->ntbEntry.commentLen > 0) {
584,960✔
371
        TAOS_CHECK_RETURN(tDecodeCStr(pCoder, &pME->ntbEntry.comment));
350!
372
      }
373
      TAOS_CHECK_RETURN(tDecodeI32v(pCoder, &pME->ntbEntry.ncid));
1,169,836!
374
      TAOS_CHECK_RETURN(tDecodeSSchemaWrapperEx(pCoder, &pME->ntbEntry.schemaRow));
1,168,342!
375
    } else if (pME->type == TSDB_TSMA_TABLE) {
×
376
      pME->smaEntry.tsma = tDecoderMalloc(pCoder, sizeof(STSma));
×
377
      if (!pME->smaEntry.tsma) {
×
378
        return terrno;
×
379
      }
380
      TAOS_CHECK_RETURN(tDecodeTSma(pCoder, pME->smaEntry.tsma, true));
×
381
    } else {
382
      metaError("meta/entry: invalide table type: %" PRId8 " decode failed.", pME->type);
×
383
      return TSDB_CODE_INVALID_PARA;
×
384
    }
385
    if (pME->type == TSDB_SUPER_TABLE) {
6,243,672✔
386
      if (TABLE_IS_COL_COMPRESSED(pME->flags)) {
3,105,689!
387
        TAOS_CHECK_RETURN(meteDecodeColCmprEntry(pCoder, pME));
3,106,020!
388

389
        if (pME->colCmpr.nCols == 0) {
3,106,953!
390
          TAOS_CHECK_RETURN(metatInitDefaultSColCmprWrapper(pCoder, &pME->colCmpr, &pME->stbEntry.schemaRow));
×
391
        }
392
      } else {
393
        TAOS_CHECK_RETURN(metatInitDefaultSColCmprWrapper(pCoder, &pME->colCmpr, &pME->stbEntry.schemaRow));
×
394
        TABLE_SET_COL_COMPRESSED(pME->flags);
×
395
      }
396
    } else if (pME->type == TSDB_NORMAL_TABLE) {
3,137,983✔
397
      if (!tDecodeIsEnd(pCoder)) {
583,621!
398
        uDebug("set type: %d, tableName:%s", pME->type, pME->name);
583,632✔
399
        TAOS_CHECK_RETURN(meteDecodeColCmprEntry(pCoder, pME));
583,632✔
400
        if (pME->colCmpr.nCols == 0) {
583,485!
401
          TAOS_CHECK_RETURN(metatInitDefaultSColCmprWrapper(pCoder, &pME->colCmpr, &pME->ntbEntry.schemaRow));
×
402
        }
403
      } else {
404
        uDebug("set default type: %d, tableName:%s", pME->type, pME->name);
×
405
        TAOS_CHECK_RETURN(metatInitDefaultSColCmprWrapper(pCoder, &pME->colCmpr, &pME->ntbEntry.schemaRow));
×
406
      }
407
      TABLE_SET_COL_COMPRESSED(pME->flags);
583,485✔
408
    } else if (pME->type == TSDB_VIRTUAL_NORMAL_TABLE || pME->type == TSDB_VIRTUAL_CHILD_TABLE) {
2,554,362✔
409
      if (!tDecodeIsEnd(pCoder)) {
5,061!
410
        uDebug("set type: %d, tableName:%s", pME->type, pME->name);
5,061!
411
        TAOS_CHECK_RETURN(meteDecodeColRefEntry(pCoder, pME));
5,061!
412
      } else {
413
        uDebug("set default type: %d, tableName:%s", pME->type, pME->name);
×
414
        if (pME->type == TSDB_VIRTUAL_NORMAL_TABLE) {
×
415
           TAOS_CHECK_RETURN(metatInitDefaultSColRefWrapper(pCoder, &pME->colRef, &pME->ntbEntry.schemaRow));
×
416
        }
417
      }
418
    }
419
    if (!tDecodeIsEnd(pCoder)) {
6,242,966✔
420
      TAOS_CHECK_RETURN(metaDecodeExtSchemas(pCoder, pME));
3,109,787!
421
    }
422
  }
423
  if (pME->type == TSDB_SUPER_TABLE) {
6,244,836✔
424
    if (!tDecodeIsEnd(pCoder)) {
3,109,711!
425
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->stbEntry.keep));
6,219,763!
426
    }
427
  }
428

429

430
  tEndDecode(pCoder);
6,244,891✔
431
  return 0;
6,245,846✔
432
}
433

434
int metaDecodeEntry(SDecoder *pCoder, SMetaEntry *pME) { return metaDecodeEntryImpl(pCoder, pME, false); }
6,252,372✔
435

436
static int32_t metaCloneSchema(const SSchemaWrapper *pSrc, SSchemaWrapper *pDst) {
766,911✔
437
  if (pSrc == NULL || pDst == NULL) {
766,911!
438
    return TSDB_CODE_INVALID_PARA;
×
439
  }
440

441
  pDst->nCols = pSrc->nCols;
766,939✔
442
  pDst->version = pSrc->version;
766,939✔
443
  pDst->pSchema = (SSchema *)taosMemoryMalloc(pSrc->nCols * sizeof(SSchema));
766,939!
444
  if (pDst->pSchema == NULL) {
766,979!
445
    return terrno;
×
446
  }
447
  memcpy(pDst->pSchema, pSrc->pSchema, pSrc->nCols * sizeof(SSchema));
766,979✔
448
  return TSDB_CODE_SUCCESS;
766,979✔
449
}
450

451
static void metaCloneSchemaFree(SSchemaWrapper *pSchema) {
766,997✔
452
  if (pSchema) {
766,997!
453
    taosMemoryFreeClear(pSchema->pSchema);
767,014!
454
  }
455
}
767,096✔
456

457
void metaCloneEntryFree(SMetaEntry **ppEntry) {
433,292✔
458
  if (ppEntry == NULL || *ppEntry == NULL) {
433,292!
459
    return;
97✔
460
  }
461

462
  taosMemoryFreeClear((*ppEntry)->name);
433,195!
463

464
  if ((*ppEntry)->type < 0) {
433,200!
465
    taosMemoryFreeClear(*ppEntry);
×
466
    return;
×
467
  }
468

469
  if (TSDB_SUPER_TABLE == (*ppEntry)->type) {
433,200✔
470
    metaCloneSchemaFree(&(*ppEntry)->stbEntry.schemaRow);
376,196✔
471
    metaCloneSchemaFree(&(*ppEntry)->stbEntry.schemaTag);
376,211✔
472
  } else if (TSDB_CHILD_TABLE == (*ppEntry)->type || TSDB_VIRTUAL_CHILD_TABLE == (*ppEntry)->type) {
57,004✔
473
    taosMemoryFreeClear((*ppEntry)->ctbEntry.comment);
42,220!
474
    taosMemoryFreeClear((*ppEntry)->ctbEntry.pTags);
42,220!
475
  } else if (TSDB_NORMAL_TABLE == (*ppEntry)->type || TSDB_VIRTUAL_NORMAL_TABLE == (*ppEntry)->type) {
14,784!
476
    metaCloneSchemaFree(&(*ppEntry)->ntbEntry.schemaRow);
14,784✔
477
    taosMemoryFreeClear((*ppEntry)->ntbEntry.comment);
14,784!
478
  } else {
479
    return;
×
480
  }
481
  metaCloneColCmprFree(&(*ppEntry)->colCmpr);
433,216✔
482
  taosMemoryFreeClear((*ppEntry)->pExtSchemas);
433,212!
483
  metaCloneColRefFree(&(*ppEntry)->colRef);
433,214✔
484

485
  taosMemoryFreeClear(*ppEntry);
433,204!
486
  return;
433,219✔
487
}
488

489
int32_t metaCloneEntry(const SMetaEntry *pEntry, SMetaEntry **ppEntry) {
433,069✔
490
  int32_t code = TSDB_CODE_SUCCESS;
433,069✔
491

492
  if (NULL == pEntry || NULL == ppEntry) {
433,069!
493
    return TSDB_CODE_INVALID_PARA;
×
494
  }
495

496
  *ppEntry = (SMetaEntry *)taosMemoryCalloc(1, sizeof(SMetaEntry));
433,087!
497
  if (NULL == *ppEntry) {
433,235!
498
    return terrno;
×
499
  }
500

501
  (*ppEntry)->version = pEntry->version;
433,235✔
502
  (*ppEntry)->type = pEntry->type;
433,235✔
503
  (*ppEntry)->uid = pEntry->uid;
433,235✔
504

505
  if (pEntry->type < 0) {
433,235!
506
    return TSDB_CODE_SUCCESS;
×
507
  }
508

509
  if (pEntry->name) {
433,235✔
510
    (*ppEntry)->name = tstrdup(pEntry->name);
433,233✔
511
    if (NULL == (*ppEntry)->name) {
433,191!
UNCOV
512
      code = terrno;
×
513
      metaCloneEntryFree(ppEntry);
×
514
      return code;
×
515
    }
516
  }
517

518
  if (pEntry->type == TSDB_SUPER_TABLE) {
433,216✔
519
    (*ppEntry)->flags = pEntry->flags;
376,213✔
520

521
    code = metaCloneSchema(&pEntry->stbEntry.schemaRow, &(*ppEntry)->stbEntry.schemaRow);
376,213✔
522
    if (code) {
376,161!
523
      metaCloneEntryFree(ppEntry);
×
524
      return code;
×
525
    }
526

527
    code = metaCloneSchema(&pEntry->stbEntry.schemaTag, &(*ppEntry)->stbEntry.schemaTag);
376,161✔
528
    if (code) {
376,119!
UNCOV
529
      metaCloneEntryFree(ppEntry);
×
530
      return code;
×
531
    }
532
    (*ppEntry)->stbEntry.keep = pEntry->stbEntry.keep;
376,128✔
533
  } else if (pEntry->type == TSDB_CHILD_TABLE || pEntry->type == TSDB_VIRTUAL_CHILD_TABLE) {
57,003✔
534
    (*ppEntry)->ctbEntry.btime = pEntry->ctbEntry.btime;
42,219✔
535
    (*ppEntry)->ctbEntry.ttlDays = pEntry->ctbEntry.ttlDays;
42,219✔
536
    (*ppEntry)->ctbEntry.suid = pEntry->ctbEntry.suid;
42,219✔
537

538
    // comment
539
    (*ppEntry)->ctbEntry.commentLen = pEntry->ctbEntry.commentLen;
42,219✔
540
    if (pEntry->ctbEntry.commentLen > 0) {
42,219✔
541
      (*ppEntry)->ctbEntry.comment = taosMemoryMalloc(pEntry->ctbEntry.commentLen + 1);
45!
542
      if (NULL == (*ppEntry)->ctbEntry.comment) {
45!
543
        code = terrno;
×
544
        metaCloneEntryFree(ppEntry);
×
545
        return code;
×
546
      }
547
      memcpy((*ppEntry)->ctbEntry.comment, pEntry->ctbEntry.comment, pEntry->ctbEntry.commentLen + 1);
45✔
548
    }
549

550
    // tags
551
    STag *pTags = (STag *)pEntry->ctbEntry.pTags;
42,219✔
552
    (*ppEntry)->ctbEntry.pTags = taosMemoryCalloc(1, pTags->len);
42,219!
553
    if (NULL == (*ppEntry)->ctbEntry.pTags) {
42,222!
554
      code = terrno;
×
555
      metaCloneEntryFree(ppEntry);
×
556
      return code;
×
557
    }
558
    memcpy((*ppEntry)->ctbEntry.pTags, pEntry->ctbEntry.pTags, pTags->len);
42,222✔
559
  } else if (pEntry->type == TSDB_NORMAL_TABLE || pEntry->type == TSDB_VIRTUAL_NORMAL_TABLE) {
14,784!
560
    (*ppEntry)->ntbEntry.btime = pEntry->ntbEntry.btime;
14,784✔
561
    (*ppEntry)->ntbEntry.ttlDays = pEntry->ntbEntry.ttlDays;
14,784✔
562
    (*ppEntry)->ntbEntry.ncid = pEntry->ntbEntry.ncid;
14,784✔
563

564
    // schema
565
    code = metaCloneSchema(&pEntry->ntbEntry.schemaRow, &(*ppEntry)->ntbEntry.schemaRow);
14,784✔
566
    if (code) {
14,784!
567
      metaCloneEntryFree(ppEntry);
×
568
      return code;
×
569
    }
570

571
    // comment
572
    (*ppEntry)->ntbEntry.commentLen = pEntry->ntbEntry.commentLen;
14,784✔
573
    if (pEntry->ntbEntry.commentLen > 0) {
14,784✔
574
      (*ppEntry)->ntbEntry.comment = taosMemoryMalloc(pEntry->ntbEntry.commentLen + 1);
49!
575
      if (NULL == (*ppEntry)->ntbEntry.comment) {
49!
576
        code = terrno;
×
577
        metaCloneEntryFree(ppEntry);
×
578
        return code;
×
579
      }
580
      memcpy((*ppEntry)->ntbEntry.comment, pEntry->ntbEntry.comment, pEntry->ntbEntry.commentLen + 1);
49✔
581
    }
582
  } else {
583
    return TSDB_CODE_INVALID_PARA;
×
584
  }
585

586
  if (pEntry->type == TSDB_VIRTUAL_NORMAL_TABLE || pEntry->type == TSDB_VIRTUAL_CHILD_TABLE) {
433,134✔
587
    code = metaCloneColRef(&pEntry->colRef, &(*ppEntry)->colRef);
786✔
588
    if (code) {
764!
589
      metaCloneEntryFree(ppEntry);
×
590
      return code;
×
591
    }
592
  } else {
593
    code = metaCloneColCmpr(&pEntry->colCmpr, &(*ppEntry)->colCmpr);
432,348✔
594
    if (code) {
432,467✔
595
      metaCloneEntryFree(ppEntry);
9✔
596
      return code;
×
597
    }
598
  }
599
  if (pEntry->pExtSchemas && pEntry->colCmpr.nCols > 0) {
433,222!
600
    (*ppEntry)->pExtSchemas = taosMemoryCalloc(pEntry->colCmpr.nCols, sizeof(SExtSchema));
23,682!
601
    if (!(*ppEntry)->pExtSchemas) {
23,679!
602
      code = terrno;
×
603
      metaCloneEntryFree(ppEntry);
×
604
      return code;
×
605
    }
606
    memcpy((*ppEntry)->pExtSchemas, pEntry->pExtSchemas, sizeof(SExtSchema) * pEntry->colCmpr.nCols);
23,679✔
607
  }
608

609
  return code;
433,219✔
610
}
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