My table is hash partitioned on the “name” column. I want to retrieve all records with a certain name value from all the partitions. Any DolphinDB functions to fulfill it?
Asked
Active
Viewed 33 times
1 Answers
0
The best way is to add a filter with the 'partition()' function in your SQL WHERE clause. Suppose the hash value of this name is 5 (use hashBucket
to get the hash value), add partition(name,5)
to the WHERE clause to query only the partitions with hash value of 5.
login(`admin,`123456)
n=10000
name="test"+string(rand(10, n))
x=rand(1.0, n)
t=table(name, x)
db=database("dfs://hashdb", HASH, [SYMBOL, 5])
pt = db.createPartitionedTable(t, `pt, `name)
pt.append!(t)
pt=loadTable(db,`pt)
select * from pt where partition(name, hashBucket(`test5, 5))

jinwandalaohu
- 226
- 1
- 7