Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
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
17 changes: 15 additions & 2 deletions cli/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,15 @@ const quietCompileOption: INamedOption<yargs.Options> = {
}
};

const disableAssertionsOption: INamedOption<yargs.Options> = {
name: "disable-assertions",
option: {
describe: "Disables all assertions including built-in assertions (uniqueKey, nonNull, rowConditions) and manual assertions (type: assertion).",
type: "boolean",
default: false
}
};

const icebergOption: INamedOption<yargs.Options> = {
name: "iceberg",
option: {
Expand Down Expand Up @@ -355,6 +364,7 @@ export function runCli() {
jsonOutputOption,
timeoutOption,
quietCompileOption,
disableAssertionsOption,
...ProjectConfigOptions.allYargsOptions
],
processFn: async argv => {
Expand All @@ -367,7 +377,8 @@ export function runCli() {
const compiledGraph = await compile({
projectDir,
projectConfigOverride: ProjectConfigOptions.constructProjectConfigOverride(argv),
timeoutMillis: argv[timeoutOption.name] || undefined
timeoutMillis: argv[timeoutOption.name] || undefined,
disableAssertions: argv[disableAssertionsOption.name] || false
});
printCompiledGraph(compiledGraph, argv[jsonOutputOption.name], argv[quietCompileOption.name]);
if (compiledGraphHasErrors(compiledGraph)) {
Expand Down Expand Up @@ -510,6 +521,7 @@ export function runCli() {
jsonOutputOption,
timeoutOption,
tagsOption,
disableAssertionsOption,
...ProjectConfigOptions.allYargsOptions
],
processFn: async argv => {
Expand All @@ -526,7 +538,8 @@ export function runCli() {
const compiledGraph = await compile({
projectDir: argv[projectDirOption.name],
projectConfigOverride: ProjectConfigOptions.constructProjectConfigOverride(argv),
timeoutMillis: argv[timeoutOption.name] || undefined
timeoutMillis: argv[timeoutOption.name] || undefined,
disableAssertions: argv[disableAssertionsOption.name] || false
});
if (compiledGraphHasErrors(compiledGraph)) {
printCompiledGraphErrors(compiledGraph.graphErrors, argv[quietCompileOption.name]);
Expand Down
233 changes: 233 additions & 0 deletions cli/index_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -576,4 +576,237 @@ SELECT 1 as test
expect(afterFormatCheckResult.exitCode).equals(0);
expect(afterFormatCheckResult.stdout).contains("All files are formatted correctly");
});

test("disable-assertions flag excludes assertions from compilation and execution", async () => {
const projectDir = tmpDirFixture.createNewTmpDir();
const npmCacheDir = tmpDirFixture.createNewTmpDir();
const workflowSettingsPath = path.join(projectDir, "workflow_settings.yaml");
const packageJsonPath = path.join(projectDir, "package.json");

await getProcessResult(
execFile(nodePath, [cliEntryPointPath, "init", projectDir, "dataform-open-source", "US"])
);

const workflowSettings = dataform.WorkflowSettings.create(
loadYaml(fs.readFileSync(workflowSettingsPath, "utf8"))
);
delete workflowSettings.dataformCoreVersion;
fs.writeFileSync(workflowSettingsPath, dumpYaml(workflowSettings));
fs.writeFileSync(
packageJsonPath,
`{
"dependencies":{
"@dataform/core": "${version}"
}
}`
);
await getProcessResult(
execFile(npmPath, [
"install",
"--prefix",
projectDir,
"--cache",
npmCacheDir,
corePackageTarPath
])
);

const assertionFilePath = path.join(projectDir, "definitions", "test_assertion.sqlx");
fs.ensureFileSync(assertionFilePath);
fs.writeFileSync(
assertionFilePath,
`
config { type: "assertion" }
SELECT 1 WHERE FALSE
`
);

const tableFilePath = path.join(projectDir, "definitions", "example_table.sqlx");
fs.ensureFileSync(tableFilePath);
fs.writeFileSync(
tableFilePath,
`
config {
type: "table",
assertions: {
uniqueKey: ["id"]
}
}
SELECT 1 as id
`
);

const compileResult = await getProcessResult(
execFile(nodePath, [
cliEntryPointPath,
"compile",
projectDir,
"--json",
"--disable-assertions"
])
);

expect(compileResult.exitCode).equals(0);
expect(JSON.parse(compileResult.stdout)).deep.equals({
tables: [
{
type: "table",
enumType: "TABLE",
target: {
database: "dataform-open-source",
schema: "dataform",
name: "example_table"
},
canonicalTarget: {
database: "dataform-open-source",
schema: "dataform",
name: "example_table"
},
query: "\n\nSELECT 1 as id\n",
disabled: false,
fileName: "definitions/example_table.sqlx",
hermeticity: "NON_HERMETIC",
tags: []
}
],
views: [],
incrementalTables: [],
assertions: [
{
target: {
database: "dataform-open-source",
schema: "dataform_assertions",
name: "test_assertion"
},
canonicalTarget: {
database: "dataform-open-source",
schema: "dataform_assertions",
name: "test_assertion"
},
query: "SELECT 1 WHERE FALSE",
disabled: true,
fileName: "definitions/test_assertion.sqlx",
hermeticity: "HERMETIC",
tags: []
},
{
target: {
database: "dataform-open-source",
schema: "dataform_assertions",
name: "dataform_example_table_assertions_uniqueKey_0"
},
canonicalTarget: {
database: "dataform-open-source",
schema: "dataform_assertions",
name: "dataform_example_table_assertions_uniqueKey_0"
},
parentAction: {
database: "dataform-open-source",
schema: "dataform",
name: "example_table"
},
dependencyTargets: [
{
database: "dataform-open-source",
schema: "dataform",
name: "example_table"
}
],
query:
"\nSELECT\n *\nFROM (\n SELECT\n id,\n COUNT(1) AS index_row_count\n FROM `dataform-open-source.dataform.example_table`\n GROUP BY id\n ) AS data\nWHERE index_row_count > 1\n",
disabled: true,
fileName: "definitions/example_table.sqlx",
hermeticity: "HERMETIC",
tags: []
}
],
operations: [],
tests: [],
notebooks: [],
projectConfig: {
warehouse: "bigquery",
defaultSchema: "dataform",
assertionSchema: "dataform_assertions",
defaultDatabase: "dataform-open-source",
defaultLocation: "US"
},
graphErrors: {},
dataformCoreVersion: version,
targets: [
{
database: "dataform-open-source",
schema: "dataform",
name: "example_table"
}
]
});

const runResult = await getProcessResult(
execFile(nodePath, [
cliEntryPointPath,
"run",
projectDir,
"--dry-run",
"--disable-assertions",
"--json"
])
);

expect(runResult.exitCode).equals(0);
expect(JSON.parse(runResult.stdout)).deep.equals({
actions: [
{
fileName: "definitions/example_table.sqlx",
hermeticity: "NON_HERMETIC",
tableType: "table",
target: {
database: "dataform-open-source",
name: "example_table",
schema: "dataform"
},
tasks: [
{
statement:
"create or replace table `dataform-open-source.dataform.example_table` as \n\nSELECT 1 as id",
type: "statement"
}
],
type: "table"
},
{
fileName: "definitions/test_assertion.sqlx",
hermeticity: "HERMETIC",
target: {
database: "dataform-open-source",
name: "test_assertion",
schema: "dataform_assertions"
},
tasks: [],
type: "assertion"
},
{
fileName: "definitions/example_table.sqlx",
hermeticity: "HERMETIC",
target: {
database: "dataform-open-source",
name: "dataform_example_table_assertions_uniqueKey_0",
schema: "dataform_assertions"
},
tasks: [],
type: "assertion"
}
],
projectConfig: {
assertionSchema: "dataform_assertions",
defaultDatabase: "dataform-open-source",
defaultLocation: "US",
defaultSchema: "dataform",
warehouse: "bigquery"
},
runConfig: {
fullRefresh: false
},
warehouseState: {}
});
});
});
2 changes: 1 addition & 1 deletion core/actions/assertion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ export class Assertion extends ActionBuilder<dataform.Assertion> {
if (config.hermetic) {
this.hermetic(config.hermetic);
}
if (config.disabled) {
if (config.disabled || session?.disableAssertions) {
this.disabled();
}
if (config.tags) {
Expand Down
Loading