提交 d7e96770 编写于 作者: S slguan

[TD-10] pass tag values

上级 5085e458
...@@ -322,25 +322,38 @@ static void dnodeProcessCreateTableMsg(SWriteMsg *pMsg) { ...@@ -322,25 +322,38 @@ static void dnodeProcessCreateTableMsg(SWriteMsg *pMsg) {
pTable->createdTime = htobe64(pTable->createdTime); pTable->createdTime = htobe64(pTable->createdTime);
SSchema *pSchema = (SSchema *) pTable->data; SSchema *pSchema = (SSchema *) pTable->data;
int totalCols = pTable->numOfColumns + pTable->numOfTags;
for (int i = 0; i < totalCols; i++) {
pSchema[i].colId = htons(pSchema[i].colId);
pSchema[i].bytes = htons(pSchema[i].bytes);
}
STableCfg tCfg; STableCfg tCfg;
tsdbInitTableCfg(&tCfg, pTable->tableType, pTable->uid, pTable->sid); tsdbInitTableCfg(&tCfg, pTable->tableType, pTable->uid, pTable->sid);
STSchema *pDestSchema = tdNewSchema(pTable->numOfColumns); STSchema *pDestSchema = tdNewSchema(pTable->numOfColumns);
for (int i = 0; i < pTable->numOfColumns; i++) { for (int i = 0; i < pTable->numOfColumns; i++) {
tdSchemaAppendCol(pDestSchema, pSchema[i].type, htons(pSchema[i].colId), htons(pSchema[i].bytes)); tdSchemaAppendCol(pDestSchema, pSchema[i].type, pSchema[i].colId, pSchema[i].bytes);
} }
tsdbTableSetSchema(&tCfg, pDestSchema, false); tsdbTableSetSchema(&tCfg, pDestSchema, false);
if (pTable->numOfTags != NULL) { if (pTable->numOfTags != 0) {
STSchema *pDestTagSchema = tdNewSchema(pTable->numOfTags); STSchema *pDestTagSchema = tdNewSchema(pTable->numOfTags);
for (int i = pTable->numOfColumns; i < pTable->numOfColumns + pTable->numOfTags; i++) { for (int i = pTable->numOfColumns; i < totalCols; i++) {
tdSchemaAppendCol(pDestTagSchema, pSchema[i].type, htons(pSchema[i].colId), htons(pSchema[i].bytes)); tdSchemaAppendCol(pDestTagSchema, pSchema[i].type, pSchema[i].colId, pSchema[i].bytes);
} }
tsdbTableSetSchema(&tCfg, pDestTagSchema, false); tsdbTableSetSchema(&tCfg, pDestTagSchema, false);
}
if (pTable->tableType == TSDB_CHILD_TABLE) {
// TODO: add data row // TODO: add data row
char *pTagData = pTable->data + totalCols * sizeof(SSchema);
int accumBytes = 0;
SDataRow dataRow = tdNewDataRowFromSchema(pDestTagSchema);
for (int i = 0; i < pTable->numOfTags; i++) {
tdAppendColVal(dataRow, pTagData + accumBytes, pDestTagSchema->columns + i);
accumBytes += pSchema[i + pTable->numOfColumns].bytes;
}
tsdbTableSetTagValue(&tCfg, dataRow, false);
} }
rpcRsp.code = tsdbCreateTable(pTsdb, &tCfg); rpcRsp.code = tsdbCreateTable(pTsdb, &tCfg);
......
...@@ -358,8 +358,9 @@ int32_t mgmtCreateNormalTable(SCMCreateTableMsg *pCreate, int32_t contLen, SVgOb ...@@ -358,8 +358,9 @@ int32_t mgmtCreateNormalTable(SCMCreateTableMsg *pCreate, int32_t contLen, SVgOb
pTable->nextColId = 0; pTable->nextColId = 0;
for (int32_t col = 0; col < pCreate->numOfColumns; col++) { for (int32_t col = 0; col < pCreate->numOfColumns; col++) {
SSchema *tschema = (SSchema *) pTable->schema; SSchema *tschema = pTable->schema;
tschema[col].colId = pTable->nextColId++; tschema[col].colId = pTable->nextColId++;
tschema[col].bytes = pTable->schema[col].bytes;
} }
pTable->sqlLen = pCreate->sqlLen; pTable->sqlLen = pCreate->sqlLen;
......
...@@ -235,9 +235,10 @@ int32_t mgmtCreateSuperTable(SDbObj *pDb, SCMCreateTableMsg *pCreate) { ...@@ -235,9 +235,10 @@ int32_t mgmtCreateSuperTable(SDbObj *pDb, SCMCreateTableMsg *pCreate) {
memcpy(pStable->schema, pCreate->schema, numOfCols * sizeof(SSchema)); memcpy(pStable->schema, pCreate->schema, numOfCols * sizeof(SSchema));
pStable->nextColId = 0; pStable->nextColId = 0;
for (int32_t col = 0; col < pStable->numOfColumns; col++) { for (int32_t col = 0; col < numOfCols; col++) {
SSchema *tschema = pStable->schema; SSchema *tschema = pStable->schema;
tschema[col].colId = pStable->nextColId++; tschema[col].colId = pStable->nextColId++;
tschema[col].bytes = htons(tschema[col].bytes);
} }
if (sdbInsertRow(tsSuperTableSdb, pStable, 0) < 0) { if (sdbInsertRow(tsSuperTableSdb, pStable, 0) < 0) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册