Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

E2e eval #12

Open
wants to merge 47 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
ab82704
Starting to make changes to get postgres working
kimdavidd Sep 16, 2019
4381777
Testing
kimdavidd Sep 18, 2019
d642cb7
Merge branch 'master' of https://github.com/yifanwu/diel into postgres
dkqntiqn Oct 2, 2019
a974bdd
tested with postgres sensor test
dkqntiqn Oct 4, 2019
ebb5c8c
changed setup for postgresql to make developers put table definitions
dkqntiqn Oct 6, 2019
d88dced
implemented materialization for postgres. just adding materialize for…
dkqntiqn Oct 6, 2019
1f889ad
added basic postgres materialization test. borrowed test cases from n…
dkqntiqn Oct 10, 2019
8cf1bf7
added checking for latest in the command and programs in the ast
dkqntiqn Oct 10, 2019
28ee465
basic materialization tests are fixed to work with sqlast
dkqntiqn Oct 10, 2019
6b45cd5
added syntax for materialize into diel. finished materialization test…
dkqntiqn Oct 10, 2019
2808bc1
tried to come up with e2e test with materialization but need helpgit …
dkqntiqn Oct 11, 2019
82e4d6c
Added some performance time prints
kimdavidd Oct 17, 2019
6310984
oops fixed a bug
kimdavidd Oct 17, 2019
3163b8e
modified to downloadable file
dkqntiqn Oct 20, 2019
f396401
changed to non-auto download. do diel.downloadPerformance() to downlo…
dkqntiqn Oct 20, 2019
bf63ff3
Changed the downloading format to CSV
kimdavidd Oct 22, 2019
ae87c5a
changed to performance.now() to measure time
dkqntiqn Oct 28, 2019
d10d992
drop cascade. bursty and materialize test.
dkqntiqn Oct 31, 2019
e4b7521
added toggleMaterialization and this field to the table
dkqntiqn Nov 1, 2019
d0ca2cc
dropping cascade for sqlite syntax
dkqntiqn Nov 1, 2019
80984ab
attempting runtime function for cleanup
dkqntiqn Nov 2, 2019
0d839b0
finished implementing shutdown. needed some fix in the diel-db-server
dkqntiqn Nov 2, 2019
e8f170d
postgres cleanup testing finished
dkqntiqn Nov 2, 2019
b8cc70c
implemented trigger for postgres materialization. WORKING
dkqntiqn Nov 4, 2019
06d18e9
attempting to correctly order the triggers
dkqntiqn Nov 6, 2019
51be2f2
Commiting execTime timing
kimdavidd Nov 8, 2019
92f50e3
Fixing merge conflict
kimdavidd Nov 8, 2019
6a1dc02
trying to make cleanup queries for triggers
dkqntiqn Nov 13, 2019
c52296b
think I implemented drop trigger for postgres correctly
dkqntiqn Nov 15, 2019
b9ad2cd
checked with diff servers. WORKING.before merging
dkqntiqn Nov 15, 2019
cc30d3a
Merge branch 'e2eEval' of https://github.com/yifanwu/diel into e2eEval
dkqntiqn Nov 15, 2019
8268911
made materializeFix trigger dependency fixing test
dkqntiqn Nov 16, 2019
7f8ebaf
fixed materialization dependency and finished testing. need e2e testing
dkqntiqn Nov 16, 2019
5973161
passing functional tests after slight modification to materialization
dkqntiqn Nov 20, 2019
3b0c65a
fixed syntax sugar bug. made test setup for materializefix
dkqntiqn Nov 20, 2019
b55cdf0
checked trigger after table on sqlite
dkqntiqn Nov 20, 2019
95277a3
fixed slight bug and tested on postgres
dkqntiqn Nov 20, 2019
e5a1cab
after fixing materialization on table not views. checked it was corre…
dkqntiqn Nov 20, 2019
c0b5197
made testing environment for trigger order
dkqntiqn Nov 20, 2019
b31303e
finally caught a trigger order problem for postgres
dkqntiqn Nov 20, 2019
2bcaff9
all the tests passing
dkqntiqn Nov 20, 2019
4aba5d4
done alphabetizing the triggers for postgres
dkqntiqn Nov 20, 2019
ee6ae69
Added logs for exec
kimdavidd Nov 22, 2019
6a350bf
Added eval for exec
kimdavidd Nov 22, 2019
8e733e7
multiple connections. most recent before pulling
dkqntiqn Nov 27, 2019
26e7a2e
merged with master
dkqntiqn Nov 27, 2019
0f7b323
merged with david's
dkqntiqn Nov 27, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
},
"homepage": "https://github.com/yifanwu/diel#readme",
"devDependencies": {
"@types/file-saver": "^2.0.1",
"antlr4ts-cli": "^0.4.0-alpha.4",
"awesome-typescript-loader": "^5.2.1",
"ignore-loader": "^0.1.2",
Expand All @@ -58,6 +59,8 @@
"dependencies": {
"@types/sql.js": "^1.0.0",
"antlr4ts": "^0.4.1-alpha.0",
"sql.js": "^1.0.0"
"file-saver": "^2.0.2",
"json-diff": "^0.5.4",
"sql.js": "^0.5.0"
}
}
23 changes: 18 additions & 5 deletions src/compiler/DielPhysicalExecution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { GetRelationDef, GetAllOutputs, GetOriginalRelations } from "./DielAstGe
import { AddRelation, DeleteRelation } from "./DielAstVisitors";

export const LocalDbId = 1;
export let materializationTime = 0;

// local helper function
// not using a set here because sets do not work well over complex objects...
Expand Down Expand Up @@ -245,11 +246,18 @@ export class DielPhysicalExecution {
// find any static table that was not used by outputs...
GetOriginalRelations(this.ast).map(r => {
if ((r.relationType === RelationType.Table)
|| (r.relationType === RelationType.DerivedTable)) {
|| (r.relationType === RelationType.DerivedTable)
|| (r.relationType === RelationType.EventTable)
) {
if (!distributions.find(d => d.relationName === r.rName)) {
// we need to add this to the local one
// fixme: might be relevant for workers as well
const newOriginal = GetSqlOriginalRelationFromDielRelation(r);

// @Lucie Question: when are we adding timestep,,,?
// are we adding to all the event tables?
const addTimeColumns = (r.relationType === RelationType.EventTable);

const newOriginal = GetSqlOriginalRelationFromDielRelation(r, addTimeColumns);
if (newOriginal) {
// need to do the following check because the distribution pass may also add relations
// sigh this is a bit messy.
Expand Down Expand Up @@ -279,9 +287,14 @@ export class DielPhysicalExecution {
localAst.triggers = triggers;

// materialization pass
this.sqlAstSpecPerDb.forEach(ast => {
TransformAstForMaterialization(ast);
});
if (this.metaData.materialize) {
this.sqlAstSpecPerDb.forEach((ast, dbId) => {
const dbDriver = this.metaData.dbs.get(dbId).dbDriver;
TransformAstForMaterialization(ast, dbDriver);
});
}
console.log("transformed ast after materialization");
console.log(this.sqlAstSpecPerDb);
}

/**
Expand Down
110 changes: 82 additions & 28 deletions src/compiler/codegen/codeGenSql.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { ReportDielUserError, LogInternalError, DielInternalErrorType, LogInternalWarning } from "../../util/messages";
import { SqlAst, SqlRelationType, SqlRelation, SqlOriginalRelation, SqlDerivedRelation, TriggerAst } from "../../parser/sqlAstTypes";
import { DropClause, AstType, DropType, Command, InsertionClause, RelationSelection, CompositeSelection, SetOperator, CompositeSelectionUnit, SelectionUnit, RelationReference, ColumnSelection, JoinType, JoinAst, ExprAst, ExprType, ExprValAst, DielDataType, ExprColumnAst, ExprRelationAst, ExprParen, ExprFunAst, FunctionType, BuiltInFunc, GroupByAst, OrderByAst, Order, Column, RelationReferenceType, RelationReferenceDirect, RelationReferenceSubquery, ExprStarAst, DeleteClause, DerivedRelation, RelationType } from "../../parser/dielAstTypes";
import { DbDriver } from "../..";

// export function generateSqlFromDielAst(ast: DielAst, options?: { replace: boolean; isRemote: boolean}) {
// const isRemote = options ? options.isRemote ? options.isRemote : false : false;
Expand All @@ -12,38 +13,40 @@ import { DropClause, AstType, DropType, Command, InsertionClause, RelationSelect
export function generateCleanUpAstFromSqlAst(ast: SqlAst): DropClause[] {
// basically drop everything
// triggers etc.
const tables = ast.relations.map(r => ({
const tables: DropClause[] = ast.relations.map(r => ({
astType: AstType.Drop,
dropType: r.relationType === SqlRelationType.Table ? DropType.Table : DropType.View,
dropName: r.rName
dropName: r.rName,
isMaterialized: r.relationType === SqlRelationType.View && (r as SqlDerivedRelation).isMaterialized,
}));

let triggers = ast.triggers.map(t => ({
let triggers: DropClause[] = ast.triggers.map(t => ({
astType: AstType.Drop,
dropType: DropType.Trigger,
dropName: t.tName
dropName: t.tName,
dropAfter: t.afterRelationName,
}));
// note that we might need to do dependency order?
return triggers.concat(tables);
}

export function generateStringFromSqlIr(sqlAst: SqlAst, replace = false): string[] {
export function generateStringFromSqlIr(sqlAst: SqlAst, replace = false, dbDrvier?: DbDriver): string[] {
// if remoteType is server, then we need to drop the old ones if we want to make a new one
// we need to architect this properly to scale, but a quick fix for now
const relations = sqlAst.relations.map(t => GenerateSqlRelationString(t, replace));
let triggers = sqlAst.triggers.map(t => generateTrigger({ trigger: t, replace }));
let commands = sqlAst.commands.map(c => generateCommand(c));
const relations = sqlAst.relations.map(t => GenerateSqlRelationString(t, replace, dbDrvier));
let triggers = sqlAst.triggers.map(t => generateTrigger({ trigger: t, replace }, dbDrvier));
let commands = sqlAst.commands.map(c => generateCommand(c, dbDrvier));
return relations.concat(triggers).concat(commands);
}

function generateCommand(command: Command): string {
function generateCommand(command: Command, dbDrvier?: DbDriver): string {
switch (command.astType) {
case AstType.Delete:
return generateDelete(command as DeleteClause);
case AstType.Insert:
return generateInserts(command as InsertionClause);
case AstType.Drop:
return generateDrop(command as DropClause);
return generateDrop(command as DropClause, dbDrvier);
case AstType.RelationSelection:
return generateSelect((command as RelationSelection).compositeSelections);
default:
Expand All @@ -52,8 +55,23 @@ function generateCommand(command: Command): string {
}
}

export function generateDrop(command: DropClause) {
return `DROP ${command.dropType} ${command.dropName};`;
export function generateDrop(command: DropClause, dbDrvier?: DbDriver) {
const isViewAndMaterializedPostgres = command.isMaterialized &&
dbDrvier && dbDrvier === DbDriver.Postgres &&
command.dropType === DropType.View;
let dropFunction = "";
if (isViewAndMaterializedPostgres) {
// drop the function too
dropFunction = `DROP FUNCTION IF EXISTS refresh_mat_view_${command.dropName} CASCADE;`;
}
return `${dropFunction} ` +
`DROP ${isViewAndMaterializedPostgres ? "MATERIALIZED " : ""}` +
`${command.dropType} ` +
`IF EXISTS ` +
`${command.dropName} ` +
`${(dbDrvier && dbDrvier === DbDriver.Postgres && command.dropType === DropType.Trigger) ? `ON ${command.dropAfter} ` : ""}` +
`${(dbDrvier && dbDrvier === DbDriver.Postgres) ? `CASCADE` : ""};`
;
}

export function generateDelete(command: DeleteClause) {
Expand All @@ -64,22 +82,23 @@ export function generateDelete(command: DeleteClause) {
return `DELETE FROM ${command.relationName} ${pred};`;
}

export function GenerateSqlRelationString(r: SqlRelation, replace = false): string {
export function GenerateSqlRelationString(r: SqlRelation, replace = false, dbDrvier?: DbDriver): string {

switch (r.relationType) {
case SqlRelationType.Table:
return generateTableSpec(r as SqlOriginalRelation, replace);
return generateTableSpec(r as SqlOriginalRelation, replace, dbDrvier);
case SqlRelationType.View:
return generateSqlViews(r as SqlDerivedRelation, replace);
return generateSqlViews(r as SqlDerivedRelation, replace, dbDrvier);
default:
LogInternalError("Not all Sql relation types are handled", DielInternalErrorType.UnionTypeNotAllHandled);
return "";
}
}

// FIXME note that we should probably not use the if not exist as a crutch
function generateTableSpec(t: SqlOriginalRelation, replace = false): string {
const replaceQuery = replace ? `DROP TABLE IF EXISTS ${t.rName};` : "";
function generateTableSpec(t: SqlOriginalRelation, replace = false, dbDrvier?: DbDriver): string {
const replaceQuery = replace ? `DROP TABLE IF EXISTS ${t.rName}
${(dbDrvier && dbDrvier === DbDriver.Postgres) ? "CASCADE" : ""};` : "";
return `${replaceQuery}
CREATE TABLE ${t.rName} (
${t.columns.map(c => " " + generateColumnDefinition(c)).join(",\n")}
Expand All @@ -98,11 +117,34 @@ export function GenerateStrFromDielDerivedRelation(v: DerivedRelation) {
return `create ${rStr} ${v.rName} AS ${generateSelect(v.selection.compositeSelections)}`;
}

export function generateSqlViews(v: SqlDerivedRelation, replace = false): string {
const replaceQuery = replace ? `DROP VIEW IF EXISTS ${v.rName};` : "";
export function generatePostgresFunction(vName: string, originalRelations: Set<string>): string {
if (originalRelations.size > 0) {
// create a function once but multiple triggers for each original Relations
const functionName = `refresh_mat_view_${vName}`;
const functionQuery = `create or replace function ${functionName}()
returns trigger language plpgsql as
$$
begin
refresh materialized view ${vName};
return null;
end
$$;
`;
return functionQuery;
}
return "";
}

export function generateSqlViews(v: SqlDerivedRelation, replace = false, dbDrvier?: DbDriver): string {
const replaceQuery = replace ? `DROP VIEW IF EXISTS ${v.rName}
${(dbDrvier && dbDrvier === DbDriver.Postgres) ? "CASCADE" : ""};` : "";
const materialize = v.isMaterialized ? `MATERIALIZED` : "";
const triggerQueries = v.isMaterialized && v.originalRelations && dbDrvier === DbDriver.Postgres ?
generatePostgresFunction(v.rName, v.originalRelations) : "";
return `${replaceQuery}
CREATE VIEW ${v.rName} AS
${generateSelect(v.selection)}
CREATE ${materialize} VIEW ${v.rName} AS
${generateSelect(v.selection)};
${triggerQueries}
`;
}

Expand Down Expand Up @@ -310,13 +352,25 @@ function generateLimit(e: ExprAst | undefined): string {
return `LIMIT ${GetSqlStringFromExpr(e)}`;
}

function generateTrigger({ trigger, replace = false }: { trigger: TriggerAst; replace?: boolean; }): string {
const replaceQuery = replace ? `DROP TRIGGER IF EXISTS ${trigger.tName};` : "";
let program = `${replaceQuery}
CREATE TRIGGER ${trigger.tName} AFTER INSERT ON ${trigger.afterRelationName}\nBEGIN\n`;
program += trigger.commands.map(p => generateCommand(p)).join("\n");
program += "\nEND;";
return program;
function generateTrigger({ trigger, replace = false }: { trigger: TriggerAst; replace?: boolean; }, dbDrvier?: DbDriver): string {
const replaceQuery = replace ? `DROP TRIGGER IF EXISTS ${trigger.tName}
${(dbDrvier && dbDrvier === DbDriver.Postgres) ? `ON ${trigger.afterRelationName} CASCADE` : ""};` : "";
if (dbDrvier && dbDrvier === DbDriver.Postgres && trigger.functionName) {
// postgres trigger
return `${replaceQuery}
CREATE TRIGGER ${trigger.tName}
AFTER INSERT ON ${trigger.afterRelationName}
FOR EACH STATEMENT
EXECUTE PROCEDURE ${trigger.functionName}();
`;
} else {
// sqlite trigger
let program = `${replaceQuery}
CREATE TRIGGER ${trigger.tName} AFTER INSERT ON ${trigger.afterRelationName}\nBEGIN\n`;
program += trigger.commands.map(p => generateCommand(p, dbDrvier)).join("\n");
program += "\nEND;";
return program;
}
}

export function generateInsertClauseStringForValue(raw: any): string {
Expand Down
1 change: 1 addition & 0 deletions src/compiler/compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export function CompileAst(ast: DielAst) {
// there should be a progressive version of this already.
// do not support crossfilter for now, but easy to fix!
export function CompileNewRelationToExistingAst(ast: DielAst, relation: OriginalRelation | DerivedRelation) {
alert(relation.rName + " " + relation.relationType);
if (IsRelationTypeDerived(relation.relationType)) {
CompileDerivedAstGivenAst(ast, relation as DerivedRelation);
} else {
Expand Down
Loading