Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
80 views
in Technique[技术] by (71.8m points)

在python中怎么建库建表

我在DolphinDB GUI中创建了如下分布式数据库表,它是分区类型是组合分区,第一层按日期值分区,第二层按设备id范围分区。

    dbName="dfs://forwardtekDdb1"
    tableName="windTurbine"
    login("admin","123456")
    if(exists(dbName))
        dropDatabase(dbName)
        
    tableSchema = table(100:0,`id`tm`val,[INT,DATETIME,FLOAT]);
    db1 = database("",VALUE,2017.01M..2020.12M)
    db2 = database("",RANGE,0..1000*30+1)
    db = database(dbName,COMPO,[db1,db2])
    dfsTable = db.createPartitionedTable(tableSchema,tableName,`tm`id)

现在我想把它移植到python中,请问应该怎么写?我在python api readme第3.2节找到了创建分区表的例子,但它是值分区,不是组合分区,我还是不知道应该怎么写。


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
import dolphindb as ddb

s = ddb.session()
s.connect("127.0.0.1", 8848,"admin","123456")

dbName="dfs://forwardtekDdb2"
tableName='windTurbine'
script="""
dbName='{db}'

if(exists(dbName))
    dropDatabase(dbName)

tableSchema = table(100:0,`id`tm`val,[INT,DATETIME,FLOAT]);
db1 = database("",VALUE,2017.01M..2020.12M)
db2 = database("",RANGE,0..1000*30+1)
db = database(dbName,COMPO,[db1,db2])
db.createPartitionedTable(tableSchema,'{tb}',`tm`id)
""".format(db=dbName,tb=tableName)
s.run(script)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...