From f8d56c2a542f7449cfd95b4508be1d9bf91e1e5d Mon Sep 17 00:00:00 2001 From: Pedro Date: Mon, 17 Nov 2014 15:39:27 +0100 Subject: [PATCH] extended frontend --- frontend-hyrise/index.html | 48 ++++++++++++++++++++++-------- frontend-hyrise/run_server.sh | 2 ++ frontend-hyrise/sample-queries.sql | 15 ++++++++++ 3 files changed, 53 insertions(+), 12 deletions(-) create mode 100755 frontend-hyrise/run_server.sh create mode 100644 frontend-hyrise/sample-queries.sql diff --git a/frontend-hyrise/index.html b/frontend-hyrise/index.html index 13f540a..ba2a279 100644 --- a/frontend-hyrise/index.html +++ b/frontend-hyrise/index.html @@ -4,7 +4,8 @@ - + + Hyrise SQL Frontend @@ -76,12 +77,23 @@ $(function() { function addSampleQuery(name, query) { var btn = $(''); - btn.click(function() { $('#queryInput').val(query); }); + btn.click(function(evt) { + $('#queryInput').val(query); + if (!evt.shiftKey) { + $('#submitBtn').click(); + } + }); $('#sampleQueries').append(btn); } + function addBuggyQuery(name, query) { var btn = $(''); - btn.click(function() { $('#queryInput').val(query); }); + btn.click(function(evt) { + $('#queryInput').val(query); + if (!evt.shiftKey) { + $('#submitBtn').click(); + } + }); $('#buggyQueries').append(btn); } @@ -164,18 +176,30 @@ $(function() { return true; }); - addSampleQuery('Load Tables', '\ -CREATE TABLE students FROM TBL FILE \'test/students.tbl\';\n\ -CREATE TABLE test FROM TBL FILE \'test/lin_xxs.tbl\';'); - - addSampleQuery('SELECT 1', 'SELECT * FROM students;') - addSampleQuery('SELECT 2', 'SELECT name, city, grade FROM (SELECT * FROM students WHERE city = \'Potsdam\') t1 WHERE grade <= 1.5 OR grade >= 3.5;'); - addSampleQuery('GROUP', 'SELECT city, AVG(grade) AS average|, MIN(grade) AS best, MAX(grade) AS worst FROM students GROUP BY city;'); - addSampleQuery('UNION', 'SELECT * FROM students WHERE grade = 1.3 UNION SELECT * FROM students WHERE grade = 3.7;'); - addSampleQuery('JOIN', 'SELECT * FROM students t1 JOIN students t2 ON t1.student_number = t2.student_number'); addBuggyQuery('GROUP', 'SELECT AVG(grade) FROM (SELECT city, AVG(grade) FROM students GROUP BY city) t1'); addBuggyQuery('UNION', 'SELECT name FROM students WHERE grade > 2.0 UNION SELECT name FROM students'); + + ////////////////////////////////////////////////// + // Load sample queries + $.get('sample-queries.sql', function(data) { + var lines = data.split('\n'); + var name, query = ""; + $.each(lines, function(i, line) { + if (line[0] == '#') { + // New query + if (name) addSampleQuery(name, query); + name = line.substring(1); + query = ""; + } else { + query += line + '\n'; + } + }); + if (name) addSampleQuery(name, query); + }); + ////////////////////////////////////////////////// + + }); diff --git a/frontend-hyrise/run_server.sh b/frontend-hyrise/run_server.sh new file mode 100755 index 0000000..b0b4362 --- /dev/null +++ b/frontend-hyrise/run_server.sh @@ -0,0 +1,2 @@ +#!/bin/sh +python -m SimpleHTTPServer 10101 \ No newline at end of file diff --git a/frontend-hyrise/sample-queries.sql b/frontend-hyrise/sample-queries.sql new file mode 100644 index 0000000..62203fa --- /dev/null +++ b/frontend-hyrise/sample-queries.sql @@ -0,0 +1,15 @@ +# Load Tables +CREATE TABLE IF NOT EXISTS students FROM TBL FILE 'test/students.tbl'; +CREATE TABLE IF NOT EXISTS test FROM TBL FILE 'test/lin_xxs.tbl'; +CREATE TABLE IF NOT EXISTS companies FROM TBL FILE 'test/tables/companies.tbl'; +CREATE TABLE IF NOT EXISTS employees FROM TBL FILE 'test/tables/employees.tbl'; +# SELECT (1) +SELECT * FROM students; +# SELECT (2) +SELECT name, city, grade FROM (SELECT * FROM students WHERE city = 'Potsdam') t1 WHERE grade <= 1.5 OR grade >= 3.5; +# GROUP +SELECT city, AVG(grade) AS average|, MIN(grade) AS best, MAX(grade) AS worst FROM students GROUP BY city; +# UNION +SELECT * FROM students WHERE grade = 1.3 UNION SELECT * FROM students WHERE grade = 3.7; +# JOIN +SELECT * FROM companies JOIN employees ON company_id = employee_company_id \ No newline at end of file