-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
231 lines (222 loc) · 8.57 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
<!DOCTYPE html>
<html>
<head>
<title>Zeldus</title>
<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
<!-- Bootstrap Latest compiled and minified CSS -->
<link rel="stylesheet" href="http://netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css">
<!-- Bootstrap Latest compiled and minified JavaScript -->
<script src="http://netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script>
<!-- D3 -->
<script src="http://d3js.org/d3.v3.min.js"></script>
<!-- Dagre-d3 -->
<script src="http://cpettitt.github.io/project/graphlib/latest/graphlib.min.js"></script>
<script src="http://cpettitt.github.io/project/dagre-d3/latest/dagre-d3.js"></script>
<!-- require -->
<script type="text/javascript" src="src/lib/requirejs/require.js"></script>
<style type="text/css">
textarea { width: 100%; height: 200px; }
.marginTop { margin-top: 20px; }
.centre { text-align: center; }
.row { margin: 0 !important;}
.nav-tabs { margin-top: 10px; }
/*.node circle { fill: #fff; stroke: steelblue; stroke-width: 1.5px; }
.node { font: 10px sans-serif; }
.link { fill: none; stroke: #ccc; stroke-width: 1.5px; }*/
svg { overflow: hidden; }
.node rect { stroke: #333; stroke-width: 1.5px; fill: #fff; }
.edgeLabel rect { fill: #fff; }
.edgePath { stroke: #333; stroke-width: 1.5px; fill: none; }
#queryEditor { display: none; }
</style>
</head>
<body>
<a class="hidden-xs" href="https://github.com/RogerNoble/zeldus"><img style="position: absolute; top: 0; right: 0; border: 0;" src="https://s3.amazonaws.com/github/ribbons/forkme_right_darkblue_121621.png" alt="Fork me on GitHub"></a>
<div class="row">
<div class="col-md-6 col-md-offset-3">
<img src="http://rogernoble.github.io/zeldus/images/zeldus.png" alt="zeldus" />
<h4><em>A client side column oriented DBMS</em></h4>
<p>Zeldus is a client side database management system that once loaded can be queried with regular SQL syntax.</p>
<p><a href="https://github.com/RogerNoble/zeldus">View the project on GitHub</a></br><a href="docs/index.html">API documentation</a></p>
</div>
</div>
<div class="row">
<div class="col-md-2 col-md-offset-1">
<h4>Example queries</h4>
<pre>select shipdate </br>from lineitem</pre>
<pre>select shipdate, linenumber </br>from lineitem</pre>
<pre>select shipdate </br>from lineitem </br>where shipdate > 19940101</pre>
<pre>select linenumber </br>from lineitem </br>where shipdate > 19940101</pre>
<pre>select linenumber, shipmode </br>from lineitem </br>where supplierkey = 777 </br>and shipdate > 19940101</pre>
<em>...and many more!</em>
<h4>Table: lineitem</h4>
<ul>
<li>orderkey (int)</li>
<li>partkey (int)</li>
<li>supplierkey (int)</li>
<li>linenumber (int)</li>
<li>quantity (decimal)</li>
<li>extendedprice (decimal)</li>
<li>discount (decimal)</li>
<li>tax (decimal)</li>
<li>returnflag (string)</li>
<li>linestatus (string)</li>
<li>shipdate (int)</li>
<li>commitdate (int)</li>
<li>receiptdate (int)</li>
<li>shipinstruct (string)</li>
<li>shipmode (string)</li>
<li>comment (string)</li>
</ul>
</div>
<div class="col-md-6">
<h5>Loading...</h5>
<div id="queryEditor">
<h5>Enter a query</h5>
<textarea id="sqlquery">
select shipdate from lineitem
</textarea>
<button type="submit" class="btn btn-danger" onclick="execute()">Execute</button>
<ul class="nav nav-tabs">
<li class="active"><a href="#results" data-toggle="tab" onclick="hideExecutionPlan();">Results</a></li>
<li><a href="#plan" data-toggle="tab" onclick="renderExecutionPlan();">Execution Plan</a></li>
</ul>
<div class="tab-content">
<div class="tab-pane active" id="results">
<div id="queryResultsMetadata" class="marginTop"></div>
<div id="queryResults" class="marginTop"></div>
</div>
<div class="tab-pane" id="plan">
</div>
</div>
<svg id="executionPlan" width="650" height="680"><g transform="translate(20,20)"/></svg>
</div>
</div>
<div class="col-md-2">
<h4>Avaliable keywords</h4>
<pre>select, from and where</pre>
<h4>Predicates</h4>
<pre>=, >, <, >=, <=, <> and !=</pre>
<h4>Coming soon</h4>
<pre>group by, count, sum, min, max</pre>
</div>
</div>
<div class="row">
<div class="col-md-6 col-md-offset-3 centre">
<a href="https://github.com/RogerNoble/zeldus">Zeldus</a> Copyright © 2014, <a href="http://www.rogernoble.com">Roger Noble</a> All Rights Reserved.
</div>
</div>
<script type="text/javascript">
var queryResults = document.getElementById('queryResults'),
queryResultsMetadata = document.getElementById('queryResultsMetadata'),
queryEditor = document.getElementById('queryEditor'),
exp = null;
require.config({
baseUrl: "src"
});
//~~ Zeldus ~~
var db = null;
require(['Zeldus', 'utils/dsloader'], function(Zeldus, DSLoader) {
db = new Zeldus({
dataSource: [ new DSLoader('lineitem', 'data/lineitem.json') ]
});
db.onDataLoaded(function(e){ queryEditor.style.display = 'block'; });
});
function execute(){
if(db != null){
var sqlquery = document.getElementById('sqlquery');
if(sqlquery.value != null && sqlquery.value.length > 0){
exp = null;
//start timer
var queryStart = new Date();
db.execute(sqlquery.value, function(results, executionPlan){
var queryEnd = new Date();
var resultsTable = '';
var limit = results.length < 100 ? results.length : 100;
for(var i = 0; i < limit; i++){
//table header
if(i == 0){
resultsTable += '<tr>';
for(var c in results[i]){
resultsTable += '<th>' + c + '</th>';
}
resultsTable += '</tr>';
}
//contents
resultsTable += '<tr>';
for(var c in results[i]){
resultsTable += '<td>' + results[i][c] + '</td>';
}
resultsTable += '</tr>';
}
queryResultsMetadata.innerHTML = 'Execution: ' + results.length + ' records in ' + ((queryEnd - queryStart) / 1000) + ' seconds'
queryResults.innerHTML = '<table class="table">' + resultsTable + '</table>';
exp = executionPlan;
});
}else{
//log
}
}
}
function renderExecutionPlan(){
if(exp != null){
// Create a new directed graph
var g = new dagreD3.graphlib.Graph()
.setGraph({})
.setDefaultEdgeLabel(function() { return {}; });
getExecutionPlanNodes(g, exp);
getExecutionPlanEdges(g, exp);
var renderer = new dagreD3.render();
renderer(d3.select("#executionPlan g"), g);
d3.select("#executionPlan g").attr("visibility", "visible");
}
}
function getExecutionPlanNodes(digraph, operator){
if(operator.children){
for(var i = 0; i < operator.children.length; i++){
getExecutionPlanNodes(digraph, operator.children[i])
}
}
if(operator.filter){
for(var i = 0; i < operator.filter.length; i++){
getExecutionPlanNodes(digraph, operator.filter[i])
}
}
digraph.setNode(JSON.stringify(operator), { label: operatorLabels(operator)});
}
function getExecutionPlanEdges(digraph, operator){
if(operator.children){
for(var i = 0; i < operator.children.length; i++){
if(!edgeCheck(digraph, operator.children[i], operator))
digraph.setEdge(JSON.stringify(operator.children[i]), JSON.stringify(operator));
if(operator.filter){
for(var j = 0; j < operator.filter.length; j++){
digraph.setEdge(JSON.stringify(operator.filter[j]), JSON.stringify(operator.children[i]));
getExecutionPlanEdges(digraph, operator.filter[j]);
}
}
getExecutionPlanEdges(digraph, operator.children[i]);
}
}
}
function hideExecutionPlan(){
d3.select("#executionPlan g").attr("visibility", "hidden");
}
function edgeCheck(digraph, source, target){
for(var e in digraph._edges){
if(digraph._edges[e].u == JSON.stringify(source) && digraph._edges[e].v == JSON.stringify(target))
return true;
}
return false;
}
function operatorLabels(operator){
var predicateTypes = {'E': '=', 'GT': '>', 'LT': '<', 'GTE': '>=', 'LTE': '<=', 'NE': '!=' };
if(operator.type == 'ds'){
return 'data source\n[' + operator.table + '].[' + operator.column + ']' + (operator.predicate ? ' ' + predicateTypes[operator.predicate.type] + ' ' + operator.predicate.value : '');
}else{
return operator.type + ' operator';
}
}
</script>
</body>
</html>