From e51fd4bf77b4aa7d9904adcd53fcc592902d3e58 Mon Sep 17 00:00:00 2001 From: lichuang Date: Thu, 20 May 2021 15:32:25 +0800 Subject: [PATCH] [TD-4034]get latest schema from super table --- src/tsdb/src/tsdbMain.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/tsdb/src/tsdbMain.c b/src/tsdb/src/tsdbMain.c index 3241d617b6..29842c0c16 100644 --- a/src/tsdb/src/tsdbMain.c +++ b/src/tsdb/src/tsdbMain.c @@ -616,17 +616,34 @@ static void tsdbStopStream(STsdbRepo *pRepo) { } } +static STSchema* getTableLatestSchema(STable *pTable) { + if (pTable->numOfSchemas > 0) { + return pTable->schema[pTable->numOfSchemas - 1]; + } + + if (pTable->type == TSDB_CHILD_TABLE) { + if (pTable->pSuper && pTable->pSuper->numOfSchemas) { + tsdbInfo("getTableLatestSchema of table %s from super table", pTable->name->data); + return pTable->pSuper->schema[pTable->pSuper->numOfSchemas - 1]; + } + } + return NULL; +} + static int restoreLastColumns(STsdbRepo *pRepo, STable *pTable, SReadH* pReadh) { - if (pTable->numOfSchemas == 0) { + STSchema *pSchema = getTableLatestSchema(pTable); + if (pSchema == NULL) { + tsdbError("getTableLatestSchema of table %s fail", pTable->name->data); return 0; } + SBlock* pBlock; int numColumns; int32_t blockIdx; SDataStatis* pBlockStatis = NULL; SDataRow row = NULL; // restore last column data with last schema - STSchema *pSchema = pTable->schema[pTable->numOfSchemas - 1]; + int err = 0; numColumns = schemaNCols(pSchema); -- GitLab