How to remove all records from a DFS table but keep its schema?

105 views Asked by At

I have defined the DFS table schema and write test data into it.

Now, I want to delete all test data but keep my table schema, how?

Suppose I have the following DFS table:

n=1000000
ID=rand(150, n)
dates=2017.08.07..2017.08.11
date=rand(dates, n)
x=rand(10.0, n)
t=table(ID, date, x)
dbDate = database(, VALUE, 2017.08.07..2017.08.11)
dbID = database(, RANGE, 0 50 100 150)

dbName="dfs://compoDB"
if(existsDatabase(dbName)){
        dropDatabase(dbName)
}
db = database(dbName, COMPO, [dbDate, dbID])
pt = db.createPartitionedTable(t, `pt, `date`ID)
pt.append!(t);
1

There are 1 answers

0
Polly On

You can use DolphinDB built-in function truncate.

Let’s conduct a test.

  1. Check the number of rows of your DFS table.

select count(*) from loadTable("dfs://compoDB", `pt)

Return:

count
1000000
  1. Use the truncate function (takes around 100ms).

truncate(dbName, `pt)

  1. Check the rows again.

select count(*) from loadTable("dfs://compoDB", `pt)

Return:

count
0

All your records are removed.