registerSnapshotEngine
Syntax
registerSnapshotEngine(dbName, tableName, keyColumnName)
Arguments
dbName is a string indicating the name of a distributed database.
tableName is a string indicating the name of a table.
keyColumnName is a string indicating the name of a column.
Details
Register a snapshot engine for a distributed table. After registering the snapshot engine, we can get the most recent row of each group specified by keyColumnName with the following SQL statement:
select [HINT_SNAPSHOT] * from loadTable(dbName,tableName).
Please note that this command can be executed in single node mode. If used in a
cluster, we cannot specify where
conditions in the SQL
statement.
Only one snapshot engine can be registered for a DFS table. After a system restart, we need to register the snapshot engine again.
Use command unregisterSnapshotEngine to unregister a snapshot engine.
Examples
Create a partitioned table:
db1=database("",VALUE,2018.09.01..2018.09.30)
db2=database("",VALUE,`AAPL`MSFT`MS`C)
db=database("dfs://compoDB",COMPO,[db1,db2])
t=table(1:0,`date`sym`val,[DATE,SYMBOL,DOUBLE])
pt=db.createPartitionedTable(t,`pt,`date`sym);
registerSnapshotEngine("dfs://compoDB","pt","sym");
def writeData(batch){
pt=loadTable("dfs://compoDB","pt")
tmp=table(batch:0,`date`sym`val,[DATE,SYMBOL,DOUBLE])
dates=take(2018.09.01..2018.09.30,batch)
syms=take(`AAPL`MSFT`MS`C,batch)
vals=rand(100.0,batch)
insert into tmp values(dates,syms,vals)
pt.append!(tmp)
}
writeData(1000);
select [HINT_SNAPSHOT] * from loadTable("dfs://compoDB","pt");
date | sym | val |
---|---|---|
2018.09.29 | AAPL | 24.945753 |
2018.09.29 | MS | 14.034453 |
2018.09.30 | C | 3.89175 |
2018.09.30 | MSFT | 17.720025 |
writeData(1000);
select [HINT_SNAPSHOT] * from loadTable("dfs://compoDB","pt");
date | sym | val |
---|---|---|
2018.09.29 | AAPL | 86.296883 |
2018.09.29 | MS | 48.17885 |
2018.09.30 | C | 83.7821 |
2018.09.30 | MSFT | 44.415456 |