add timestamp precision support
This commit is contained in:
parent
3d70319913
commit
dec30e4473
|
@ -21,6 +21,7 @@ typedef struct {
|
||||||
SHashObj* fieldHash;
|
SHashObj* fieldHash;
|
||||||
SArray* tags; //SArray<SSchema>
|
SArray* tags; //SArray<SSchema>
|
||||||
SArray* fields; //SArray<SSchema>
|
SArray* fields; //SArray<SSchema>
|
||||||
|
uint8_t precision;
|
||||||
} SSmlSTableSchema;
|
} SSmlSTableSchema;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
@ -117,6 +118,7 @@ int32_t loadTableMeta(TAOS* taos, char* tableName, SSmlSTableSchema* schema) {
|
||||||
taosHashGetClone(tscTableMetaInfo, fullTableName, strlen(fullTableName), NULL, tableMeta, -1);
|
taosHashGetClone(tscTableMetaInfo, fullTableName, strlen(fullTableName), NULL, tableMeta, -1);
|
||||||
|
|
||||||
tstrncpy(schema->sTableName, tableName, strlen(tableName)+1);
|
tstrncpy(schema->sTableName, tableName, strlen(tableName)+1);
|
||||||
|
schema->precision = tableMeta->tableInfo.precision;
|
||||||
for (int i=0; i<tableMeta->tableInfo.numOfColumns; ++i) {
|
for (int i=0; i<tableMeta->tableInfo.numOfColumns; ++i) {
|
||||||
SSchema field;
|
SSchema field;
|
||||||
tstrncpy(field.name, tableMeta->schema[i].name, strlen(tableMeta->schema[i].name)+1);
|
tstrncpy(field.name, tableMeta->schema[i].name, strlen(tableMeta->schema[i].name)+1);
|
||||||
|
@ -486,6 +488,25 @@ int32_t insertPoints(TAOS* taos, TAOS_SML_DATA_POINT* points, int32_t numPoints)
|
||||||
strncpy(point->childTableName, childTableName, tableNameLen);
|
strncpy(point->childTableName, childTableName, tableNameLen);
|
||||||
point->childTableName[tableNameLen] = '\0';
|
point->childTableName[tableNameLen] = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (int j = 0; j < point->tagNum; ++j) {
|
||||||
|
TAOS_SML_KV* kv = point->tags + j;
|
||||||
|
if (kv->type == TSDB_DATA_TYPE_TIMESTAMP) {
|
||||||
|
int64_t ts = *(int64_t*)(kv->value);
|
||||||
|
ts = convertTimePrecision(ts, TSDB_TIME_PRECISION_NANO, point->schema->precision);
|
||||||
|
*(int64_t*)(kv->value) = ts;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int j = 0; j < point->fieldNum; ++j) {
|
||||||
|
TAOS_SML_KV* kv = point->fields + j;
|
||||||
|
if (kv->type == TSDB_DATA_TYPE_TIMESTAMP) {
|
||||||
|
int64_t ts = *(int64_t*)(kv->value);
|
||||||
|
ts = convertTimePrecision(ts, TSDB_TIME_PRECISION_NANO, point->schema->precision);
|
||||||
|
*(int64_t*)(kv->value) = ts;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
SArray* cTablePoints = NULL;
|
SArray* cTablePoints = NULL;
|
||||||
SArray** pCTablePoints = taosHashGet(cname2points, point->childTableName, strlen(point->childTableName));
|
SArray** pCTablePoints = taosHashGet(cname2points, point->childTableName, strlen(point->childTableName));
|
||||||
if (pCTablePoints) {
|
if (pCTablePoints) {
|
||||||
|
@ -596,7 +617,6 @@ int taos_sml_insert(TAOS* taos, TAOS_SML_DATA_POINT* points, int numPoint) {
|
||||||
point->schema = pStableSchema;
|
point->schema = pStableSchema;
|
||||||
}
|
}
|
||||||
|
|
||||||
SArray* schemaActions = taosArrayInit(32, sizeof(SSchemaAction));
|
|
||||||
size_t numStable = taosArrayGetSize(stableArray);
|
size_t numStable = taosArrayGetSize(stableArray);
|
||||||
for (int i = 0; i < numStable; ++i) {
|
for (int i = 0; i < numStable; ++i) {
|
||||||
SSmlSTableSchema* pointSchema = taosArrayGet(stableArray, i);
|
SSmlSTableSchema* pointSchema = taosArrayGet(stableArray, i);
|
||||||
|
@ -615,8 +635,10 @@ int taos_sml_insert(TAOS* taos, TAOS_SML_DATA_POINT* points, int numPoint) {
|
||||||
memcpy(schemaAction.createSTable.sTableName, pointSchema->sTableName, TSDB_TABLE_NAME_LEN);
|
memcpy(schemaAction.createSTable.sTableName, pointSchema->sTableName, TSDB_TABLE_NAME_LEN);
|
||||||
schemaAction.createSTable.tags = pointSchema->tags;
|
schemaAction.createSTable.tags = pointSchema->tags;
|
||||||
schemaAction.createSTable.fields = pointSchema->fields;
|
schemaAction.createSTable.fields = pointSchema->fields;
|
||||||
taosArrayPush(schemaActions, &schemaAction);
|
applySchemaAction(taos, &schemaAction);
|
||||||
}else if (code == TSDB_CODE_SUCCESS) {
|
code = loadTableMeta(taos, pointSchema->sTableName, &dbSchema);
|
||||||
|
pointSchema->precision = dbSchema.precision;
|
||||||
|
} else if (code == TSDB_CODE_SUCCESS) {
|
||||||
size_t pointTagSize = taosArrayGetSize(pointSchema->tags);
|
size_t pointTagSize = taosArrayGetSize(pointSchema->tags);
|
||||||
size_t pointFieldSize = taosArrayGetSize(pointSchema->fields);
|
size_t pointFieldSize = taosArrayGetSize(pointSchema->fields);
|
||||||
|
|
||||||
|
@ -629,7 +651,7 @@ int taos_sml_insert(TAOS* taos, TAOS_SML_DATA_POINT* points, int numPoint) {
|
||||||
bool actionNeeded = false;
|
bool actionNeeded = false;
|
||||||
generateSchemaAction(pointTag, dbTagHash, true, pointSchema->sTableName, &schemaAction, &actionNeeded);
|
generateSchemaAction(pointTag, dbTagHash, true, pointSchema->sTableName, &schemaAction, &actionNeeded);
|
||||||
if (actionNeeded) {
|
if (actionNeeded) {
|
||||||
taosArrayPush(schemaActions, &schemaAction);
|
applySchemaAction(taos, &schemaAction);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -643,19 +665,16 @@ int taos_sml_insert(TAOS* taos, TAOS_SML_DATA_POINT* points, int numPoint) {
|
||||||
bool actionNeeded = false;
|
bool actionNeeded = false;
|
||||||
generateSchemaAction(pointCol, dbFieldHash, false, pointSchema->sTableName, &schemaAction, &actionNeeded);
|
generateSchemaAction(pointCol, dbFieldHash, false, pointSchema->sTableName, &schemaAction, &actionNeeded);
|
||||||
if (actionNeeded) {
|
if (actionNeeded) {
|
||||||
taosArrayPush(schemaActions, &schemaAction);
|
applySchemaAction(taos, &schemaAction);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pointSchema->precision = dbSchema.precision;
|
||||||
} else {
|
} else {
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < taosArrayGetSize(schemaActions); ++i) {
|
|
||||||
SSchemaAction* action = taosArrayGet(schemaActions, i);
|
|
||||||
applySchemaAction(taos, action);
|
|
||||||
}
|
|
||||||
|
|
||||||
insertPoints(taos, points, numPoint);
|
insertPoints(taos, points, numPoint);
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,7 @@ static void prepare_data(TAOS* taos) {
|
||||||
result = taos_query(taos, "drop database if exists test;");
|
result = taos_query(taos, "drop database if exists test;");
|
||||||
taos_free_result(result);
|
taos_free_result(result);
|
||||||
usleep(100000);
|
usleep(100000);
|
||||||
result = taos_query(taos, "create database test;");
|
result = taos_query(taos, "create database test precision 'us';");
|
||||||
taos_free_result(result);
|
taos_free_result(result);
|
||||||
usleep(100000);
|
usleep(100000);
|
||||||
taos_select_db(taos, "test");
|
taos_select_db(taos, "test");
|
||||||
|
@ -950,11 +950,19 @@ void verify_stream(TAOS* taos) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t verify_schema_less(TAOS* taos) {
|
int32_t verify_schema_less(TAOS* taos) {
|
||||||
prepare_data(taos);
|
TAOS_RES *result;
|
||||||
|
result = taos_query(taos, "drop database if exists test;");
|
||||||
|
taos_free_result(result);
|
||||||
|
usleep(100000);
|
||||||
|
result = taos_query(taos, "create database test precision 'us';");
|
||||||
|
taos_free_result(result);
|
||||||
|
usleep(100000);
|
||||||
|
taos_select_db(taos, "test");
|
||||||
|
|
||||||
char* lines[] = {
|
char* lines[] = {
|
||||||
"st,t1=3i,t2=4,t3=\"t3\" c1=3i,c3=L\"passit\",c2=false,c4=4 1626006833639",
|
"st,t1=3i,t2=4,t3=\"t3\" c1=3i,c3=L\"passit\",c2=false,c4=4 1626006833639000000",
|
||||||
"st,t1=4i,t2=5,t3=\"t4\" c1=3i,c3=L\"passitagain\",c2=true,c4=5 1626006833640",
|
"st,t1=4i,t2=5,t3=\"t4\" c1=3i,c3=L\"passitagain\",c2=true,c4=5 1626006833640000000",
|
||||||
"st,t1=4i,t2=5,t3=\"t4\" c1=3i,c3=L\"passitagain\",c2=true,c4=5 1626006833642"
|
"st,t1=4i,t2=5,t3=\"t4\" c1=3i,c3=L\"passitagain\",c2=true,c4=5 1626006833642000000"
|
||||||
};
|
};
|
||||||
int code = taos_insert_by_lines(taos, lines , 3);
|
int code = taos_insert_by_lines(taos, lines , 3);
|
||||||
return code;
|
return code;
|
||||||
|
|
Loading…
Reference in New Issue