<< Click to Display Table of Contents >> Import Data to Data Mart API |
•Initialization environment
// prepare the environments.
String bihome ="E:/source/yonghongsoft/source/home";
System.setProperty("bi.home", bihome);
String license = Setting.get("license");
//need call init license to get the permission to execute data.
//the init must needed.
License must be initialized before it can be used.
if(license == null || !g5.util.KeyUtil.init(license)) {
System.out.println("_________key invalid____"); return;
}
//init the Data Mart server.
DCUtil.init(false);
//set the thread count. according to CPU count and license permission.
//Setting.setInt("mem.proc.count", 2);
If the parameter needs to be set such as “mem.proc.count”, it can set by Setting.
//set false to ignore the naming checking.
//if the system status is not right while checking file is true, the system cannot be start.
Setting.setBoolean("dc.naming.check.file", false);
Initialized data file and folder positions.
// init values for file/folder/append from
GSFolderC holder = new GSFolderC();
holder.setFolder("testQryFolder");
holder.setFile("testQryFile");
holder.setAppend(true);
// set meta.
//holder.setMeta("region", "beijing");
If meta attribute needs to be set, it can be set here. The produced file will be marked as region=beijing.
// temp generate files path.
String genPath = Setting.getHome() + "/gen";
Set the saving path of generated temporary file, and the setting can be done under {bihome}/gen.
Generate data DataGrid.
// init the query
QueryRep rep = QueryRep.get();
Query qry = (Query) rep.getAsset(new AssetRef(Query.SQL, "testQry"), null);
// create the context for query, the context will contains some environment parameters.
QContext context = new QContextImpl(null, QContext.RT_MODE, null);
//set max rows for query, while execute query, only get max rows results.
//context.set(context.MAX_ROWS, 10000000);
//force to load data from real source.
context.set(QContext.REFRESH, Boolean.TRUE);
// set your parameter here for query.
//context.set("param", "value");
If the parameter needs to be set and transfer to query, the setting needs to be done in context.
// get query columns.
QCol[] cols = qry.cols(true);
// get DataGrid
GQuery gqry = GQuery.create(qry, context, cols, null, null, null, null);
DataGrid grid = gqry.getGrid();
Generate data file from DataGrid.
//generate Data Mart files from DataGrid to a temp folder genPath.
File genFile = new File(holder.getFile());
Splitter split = new Splitter(cols, grid, null, genFile, null);
split.gen();
split.waitFor(1000 * 60 * 60 * 24);
➢Attention: the split here needs to wait, otherwise the generation might be fail. The waiting time is subjected to the data size, so it will be faster with the value big enough.
Load the data file to the system through AddFolderTask.
// Init GSFolder.
GSFolder folder = initFolder(holder, holder.getFolder(), genFile, cols);
AddFolderTask task = new AddFolderTask(folder, holder.isAppend());
GNodeResult result = task.exec();
The -Push data example can be referred for details.