feat: reduce the pain of having to bring various schemas every time write data
fengjiachun opened this issue · 0 comments
fengjiachun commented
In order to improve the compactness and write performance of network data transmission, we require that TableSchema information be filled in every time a write request is called.:
TableSchema schema =
TableSchema
.newBuilder(TableName.with("public", "monitor"))
.semanticTypes(SemanticType.Tag, SemanticType.Timestamp, SemanticType.Field, SemanticType.Field)
.dataTypes(ColumnDataType.String, ColumnDataType.TimestampMillisecond, ColumnDataType.Float64,
ColumnDataType.Float64) //
.columnNames("host", "ts", "cpu", "memory") //
.build();
WriteRows rows = WriteRows.newBuilder(schema).build();
rows.insert("127.0.0.1", System.currentTimeMillis(), 0.1, null) //
.insert("127.0.0.2", System.currentTimeMillis(), 0.3, 0.5) //
.finish();
CompletableFuture<Result<WriteOk, Err>> future = greptimeDB.write(rows);
However, this has caused inconvenience for users and made the writing process complex and cumbersome. Therefore, we need to find a solution to solve this problem.
My idea is cache TableSchema
and provide a method to search for schema by table name:
TableSchema schema = TableSchema.findByName(tableName);
WriteRows rows = WriteRows.newBuilder(schema).build();
rows.insert("127.0.0.1", System.currentTimeMillis(), 0.1, null) //
.insert("127.0.0.2", System.currentTimeMillis(), 0.3, 0.5) //
.finish();
This requires that the following insert values must be in the same order as the schema.
Is there a better way?