Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
public publishTasks(
table: dataform.ITable,
runConfig: dataform.IRunConfig,
tableMetadata: dataform.ITableMetadata
): Tasks {
const tasks = Tasks.create();
// Drop the existing view or table if we are changing it's type.
if (tableMetadata && tableMetadata.type != this.baseTableType(table.type)) {
tasks.add(
Task.statement(this.dropIfExists(table.target, this.oppositeTableType(table.type)))
);
}
if (table.type == "incremental") {
if (runConfig.fullRefresh || !tableMetadata || tableMetadata.type == "view") {
tasks.add(Task.statement(this.createOrReplace(table)));
} else {
// The table exists, insert new rows.
tasks.add(
Task.statement(
this.insertInto(
table.target,
tableMetadata.fields.map(f => f.name),
this.where(table.incrementalQuery || table.query, table.where)
)
)
);
public publishTasks(
table: dataform.ITable,
runConfig: dataform.IRunConfig,
tableMetadata: dataform.ITableMetadata
): Tasks {
const tasks = Tasks.create();
// Drop the existing view or table if we are changing it's type.
if (tableMetadata && tableMetadata.type != this.baseTableType(table.type)) {
tasks.add(
Task.statement(this.dropIfExists(table.target, this.oppositeTableType(table.type)))
);
}
if (table.type == "incremental") {
if (runConfig.fullRefresh || !tableMetadata || tableMetadata.type == "view") {
tasks.add(Task.statement(this.createOrReplace(table)));
} else {
// The table exists, insert new rows.
tasks.add(
Task.statement(
this.insertInto(
table.target,
tableMetadata.fields.map(f => f.name),
this.where(table.incrementalQuery || table.query, table.where)
)
)
);
}
} else {
tasks.add(Task.statement(this.createOrReplace(table)));
}
return tasks;
tableMetadata: dataform.ITableMetadata
): Tasks {
const tasks = Tasks.create();
// Drop the existing view or table if we are changing it's type.
if (tableMetadata && tableMetadata.type != this.baseTableType(table.type)) {
tasks.add(
Task.statement(this.dropIfExists(table.target, this.oppositeTableType(table.type)))
);
}
if (table.type == "incremental") {
if (runConfig.fullRefresh || !tableMetadata || tableMetadata.type == "view") {
tasks.add(Task.statement(this.createOrReplace(table)));
} else {
// The table exists, insert new rows.
tasks.add(
Task.statement(
this.insertInto(
table.target,
tableMetadata.fields.map(f => f.name),
this.where(table.incrementalQuery || table.query, table.where)
)
)
);
}
} else {
tasks.add(Task.statement(this.createOrReplace(table)));
}
return tasks;
}
public assertTasks(
assertion: dataform.IAssertion,
projectConfig: dataform.IProjectConfig
): Tasks {
const target =
assertion.target ||
dataform.Target.create({
schema: projectConfig.assertionSchema,
name: assertion.name
});
return Tasks.create()
.add(Task.statement(this.dropIfExists(target, "view")))
.add(
Task.statement(`
create view ${this.resolveTarget(target)}
as ${assertion.query}`)
)
.add(Task.assertion(`select sum(1) as row_count from ${this.resolveTarget(target)}`));
}
Task.statement(
`${alreadyExists ? "alter" : "create"} view ${this.resolveTarget(table.target)} as ${
table.query
}`
)
);
}
const tempTableTarget = dataform.Target.create({
schema: table.target.schema,
name: table.target.name + "_temp"
});
return Tasks.create()
.add(Task.statement(this.dropIfExists(tempTableTarget, this.baseTableType(table.type))))
.add(Task.statement(this.createTable(table, tempTableTarget)))
.add(Task.statement(this.dropIfExists(table.target, "table")))
.add(
Task.statement(
`rename object ${this.resolveTarget(tempTableTarget)} to ${table.target.name} `
)
);
}
private createOrReplace(table: dataform.ITable, alreadyExists: boolean) {
if (table.type === "view") {
return Tasks.create().add(
Task.statement(
`${alreadyExists ? "alter" : "create"} view ${this.resolveTarget(table.target)} as ${
table.query
}`
)
);
}
const tempTableTarget = dataform.Target.create({
schema: table.target.schema,
name: table.target.name + "_temp"
});
return Tasks.create()
.add(Task.statement(this.dropIfExists(tempTableTarget, this.baseTableType(table.type))))
.add(Task.statement(this.createTable(table, tempTableTarget)))
.add(Task.statement(this.dropIfExists(table.target, "table")))
.add(
public assertTasks(
assertion: dataform.IAssertion,
projectConfig: dataform.IProjectConfig
): Tasks {
const tasks = Tasks.create();
const target =
assertion.target ||
dataform.Target.create({
schema: projectConfig.assertionSchema,
name: assertion.name
});
tasks.add(Task.statement(this.createOrReplaceView(target, assertion.query)));
tasks.add(Task.assertion(`select sum(1) as row_count from ${this.resolveTarget(target)}`));
return tasks;
}
return Tasks.create().add(
Task.statement(
`${alreadyExists ? "alter" : "create"} view ${this.resolveTarget(table.target)} as ${
table.query
}`
)
);
}
const tempTableTarget = dataform.Target.create({
schema: table.target.schema,
name: table.target.name + "_temp"
});
return Tasks.create()
.add(Task.statement(this.dropIfExists(tempTableTarget, this.baseTableType(table.type))))
.add(Task.statement(this.createTable(table, tempTableTarget)))
.add(Task.statement(this.dropIfExists(table.target, "table")))
.add(
Task.statement(
`rename object ${this.resolveTarget(tempTableTarget)} to ${table.target.name} `
)
);
}