Coder Social home page Coder Social logo

Comments (3)

charmby avatar charmby commented on June 15, 2024

同时,这个设计特别奇怪

dbPath="dfs://db_value_date"
if s.existsDatabase(dbPath):
    s.dropDatabase(dbPath)
dates=np.array(pd.date_range(start='20120101', end='20120110'), dtype="datetime64[D]")
db = s.database(dbName='mydb', partitionType=keys.VALUE, partitions=dates,dbPath=dbPath)
df = pd.DataFrame({'datetime':np.array(['2012-01-01T00:00:00', '2012-01-02T00:00:00'], dtype='datetime64'), 'sym':['AA', 'BB'], 'val':[1,2]})
t = s.table(data=df)
db.createPartitionedTable(table=t, tableName='pt', partitionColumns='datetime').append(t)
re=s.loadTable(tableName='pt', dbPath=dbPath).toDF()

为什么建表的时候需要传入data,一般的应用场景下都是先create table再进行数据写入,难道每次想写入数据的时候都创建一个新的表???

from api_python3.

charmby avatar charmby commented on June 15, 2024
dbPath="dfs://db_value_date"
if s.existsDatabase(dbPath):
    s.dropDatabase(dbPath)
dates=np.array(pd.date_range(start='20120101', end='20120110'), dtype="datetime64[D]")
db = s.database(dbName='mydb', partitionType=keys.VALUE, partitions=dates,dbPath=dbPath)
df = pd.DataFrame({'datetime':np.array(['2012-01-01T00:00:00', '2012-01-02T00:00:00'], dtype='datetime64'), 'sym':['AA', 'BB'], 'val':[1,2]})
t = s.table(data=df)
db.createPartitionedTable(table=t, tableName='pt', partitionColumns='datetime').append(t)
re=s.loadTable(tableName='pt', dbPath=dbPath).toDF()

另一个奇怪的点在于, database为什么要指定分区。。数据不应该是和表挂钩吗?一个表期望使用时间D进行分区?一个期望使用股票板块plate进行分区,另一个使用股票id进行分区
归属同一个数据库的时候难道要分别设置分区吗???为啥要和库挂钩??

from api_python3.

ffliu29 avatar ffliu29 commented on June 15, 2024

问题 1: 您方便提供一下报错信息吗?
问题 2:建表语句为 db.createPartitionedTable(table=t, tableName='pt', partitionColumns='datetime'), 其中 table 参数提供的表只是作为创建表的表结构,它可以是一个空表也可以是个有数据的表,如果有数据是不会写入创建表的,真正写入数据的部分在 append(t)。如果表不存在,可以先创建一个表,如 pt = db.createPartitionedTable(table=t, tableName='pt', partitionColumns='datetime'),如果是已经存在的表,则先通过 pt = s.loadTable 加载 pt 表对象。后续可以通过 pt.append(t) 或者其他写入函数向该表写入数据,不需要创建一个新表。
问题 3:数据库分区有利于并行计算,增加可用性等等,关于数据库分区的说明可以参考教程:https://gitee.com/dolphindb/Tutorials_CN/blob/master/database.md。
相同分区方案的分区表可以存在同一个数据库。如果您希望数据表不分区可以使用维度表(通过函数 createTable 创建,此时您数据库可以任意设置一个分区方案),关于维度表的说明可以参考 https://www.dolphindb.cn/cn/help/130/FunctionsandCommands/FunctionReferences/c/createTable.html

from api_python3.

Related Issues (15)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.