@license Zeldus 0.1.1 Copyright (c) 2014, Roger Noble All Rights Reserved.
Licensed under MIT.
See https://raw.githubusercontent.com/RogerNoble/zeldus/master/LICENSE
define([
'utils/QueryParser',
'blocks/BasicBlock',
'common/OperatorFactory',
'common/ResultPrinter'],
function(QueryParser, BasicBlock, OperatorFactory, ResultPrinter) {
var tables = {};
Option name | Type | Description |
---|---|---|
executionPlan | Object | an execution plan generated by the QueryParser |
callback | Object | callback fucntion called once a result is ready |
runs the execution plan and returns a result to the callback
function runQuery(executionPlan, callback){
var factory = new OperatorFactory(tables);
//start timer
var queryStart = new Date();
//output column names
var columns = executionPlan.children.map(function(column){ return column.column; }),
tree = factory.get(executionPlan);
var result = new ResultPrinter(
tree,
columns
);
result.getJSON(function(data){
var queryEnd = new Date();
console.log('Query execution: ' + ((queryEnd - queryStart) / 1000) + ' seconds');
callback(data, executionPlan);
});
}
Option name | Type | Description |
---|---|---|
options | Object | a configuration object |
Zeldus
function Zeldus(options) {
var self = this,
onLoadedCallback = null;
//setup tables
if(options.dataSource){
self.loadStart = new Date();
for(var i = 0; i < options.dataSource.length; i++){
options.dataSource[i].get(loadTable);
}
}
Option name | Type | Description |
---|---|---|
name | Object | the name of the projection |
projection | Object |
Create a projection for a given table
self.createProjection = function(name, projection){
};
Option name | Type | Description |
---|---|---|
query | Object | an SQL query |
callback | Object | a callback function |
Execute a query and return the results to a callback function
self.execute = function(query, callback) {
//parse query to generate plan
var parser = new QueryParser();
var executionPlan = parser.parse(query);
console.log(JSON.stringify(executionPlan));
//run plan
runQuery(executionPlan, callback);
};
self.onDataLoaded = function(callback){
onLoadedCallback = callback;
}
self.version = '0.1.2';
Option name | Type | Description |
---|---|---|
tableName | Object | the name of the table |
results | Object | the result of a data load |
Load data into a table of columns
function loadTable(tableName, results){
tables[tableName] = {};
for(var i = 0; i < results.length; i++){
for(var column in results[i]){
if (results[i].hasOwnProperty(column)) {
//create columns
if(tables[tableName][column] === undefined){
tables[tableName][column] = [];
}
//add blocks (uncompressed)
tables[tableName][column].push(new BasicBlock(results[i][column], i));
}
}
}
var loadEnd = new Date();
console.log('Data load: ' + ((loadEnd - self.loadStart) / 1000) + ' seconds');
onLoadedCallback();
}
}
return Zeldus;
});