TSDB引擎创建分布式表失败:The sort keys must be specifed for TSDB engine.

以下代码在创建TSDB分布式表的时候出现了异常: The sort keys must be specified for TSDB engine.

请问如何正确创建分布式表?

dbName = "dfs://tsdb_value_int"
n = 10000
t = table(n:n, [`int,`long,`short,`float,`double,`string,`char,`bool,`timestamp], [INT, LONG, SHORT,FLOAT, DOUBLE, STRING, CHAR, BOOL, TIMESTAMP])
pt1 = db.createPartitionedTable(table=t, tableName=`pt1, partitionColumns=`int,compressMethods=dict(`timestamp`long,`delta`delta),keepDuplicates=ALL)


请先 登录 后评论

1 个回答

Draco Chen

使用TSDB 引擎,必须指定sortColumns参数。TSDB引擎根据sortColumns 的各列的顺序维护一个索引,因此可以优先把查询频率高的字段作为sortColumns 中位置靠前的列。例如:

dbName = "dfs://tsdb_value_int"
if(existsDatabase(dbName)){
dropDatabase(dbName)
}
db = database(directory=dbName, partitionType=VALUE, partitionScheme=1..10,engine="TSDB")
n = 10000
t = table(n:n, [`int,`long,`short,`float,`double,`string,`char,`bool,`timestamp], [INT, LONG, SHORT,FLOAT, DOUBLE, STRING, CHAR, BOOL, TIMESTAMP])
pt1 = db.createPartitionedTable(table=t, tableName=`pt1, partitionColumns=`int,compressMethods=dict(`timestamp`long,`delta`delta),sortColumns=`short`int, keepDuplicates=ALL)
t[`int] = rand(100,n)
t[`long] = rand(100000l,n)
t[`short] = rand(10h,n)
t[`float] = rand(100.0f,n)
t[`double] = rand(100.0,n)
t[`string] = rand("A"+string(1..1000),n)
t[`char] = rand(100,n)
t[`bool] = rand([true,false],n)
tem = 2012.06.13T13:30:10.000
ts = array(timestamp,0,n)
for(i in 1..n){
tem=temporalAdd(tem, 1, `s)
ts.append!(tem)
 }
t[`timestamp] = ts
pt1.append!(t)

参数更多细节请参考https://www.dolphindb.cn/cn/help/FunctionsandCommands/FunctionReferences/c/createPartitionedTable.html

请先 登录 后评论