导数的API

<< Click to Display Table of Contents >>

当前位置:  数据集市 > 二次开发 

导数的API

Previous pageReturn to chapter overviewNext page

初始化环境

// 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.

必需 init license,才可使用。

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);

如需要设置参数,譬如 “mem.proc.count” 可通过 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);

初始化数据文件夹及文件位置。

// 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");

如需要设置 meta 属性,可在这里设置则生成的文件将被标明是 region=beijing。

// temp generate files path.

String genPath = Setting.getHome() + "/gen";

设置生成的临时文件保存的路径,此处设在 {bihome}/gen 下。

生成数据 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");

如需要设置参数传递给 query,则需要设置进 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();

从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);

注意:这里 split 需要等待,否则有可能生成失败,等待的时间由数据大小决定,设置足够大的值的话就好。

将数据文件通过 AddFolderTask 加载到系统内。

// Init GSFolder.

GSFolder folder = initFolder(holder, holder.getFolder(), genFile, cols);

AddFolderTask task = new AddFolderTask(folder, holder.isAppend());

GNodeResult result = task.exec();

具体可参考附录 -Push data 例子。