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

Feature: dependent assertions as dependencies #1720

Merged
merged 12 commits into from
May 7, 2024
11 changes: 6 additions & 5 deletions .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ build --test_output=errors --action_env="GTEST_COLOR=1"
# TODO: Fix all the underlying issues here.
build --incompatible_py3_is_default=false

# TODO(ekrekr): explore re-enabling these, if open source development is too slow.
# The following flags enable the remote cache so action results can be shared
# across machines, developers, and workspaces.
build:remote-cache --remote_cache=grpcs://remotebuildexecution.googleapis.com
build:remote-cache --remote_instance_name=projects/dataform-corp/instances/dataform-co
build:remote-cache --remote_timeout=3600
build:remote-cache --auth_enabled=true
build:remote-cache --google_default_credentials=true
# build:remote-cache --remote_cache=grpcs://remotebuildexecution.googleapis.com
# build:remote-cache --remote_instance_name=projects/dataform-open-source/instances/dataform-co
# build:remote-cache --remote_timeout=3600
# build:remote-cache --auth_enabled=true
# build:remote-cache --google_default_credentials=true
3 changes: 2 additions & 1 deletion cli/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ ts_test_suite(
data = [
":node_modules",
"//packages/@dataform/core:package_tar",
"//test_credentials:bigquery.json",
# TODO(ekrekr): re-add these once we have working BQ credentials.
# "//test_credentials:bigquery.json",
"@nodejs//:node",
"@nodejs//:npm",
],
Expand Down
126 changes: 61 additions & 65 deletions cli/index_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,13 +154,7 @@ defaultAssertionDataset: dataform_assertions

// Initialize a project using the CLI, don't install packages.
await getProcessResult(
execFile(nodePath, [
cliEntryPointPath,
"init",
projectDir,
"dataform-integration-tests",
"US"
])
execFile(nodePath, [cliEntryPointPath, "init", projectDir, "dataform-open-source", "US"])
);

// Install packages manually to get around bazel read-only sandbox issues.
Expand Down Expand Up @@ -219,14 +213,14 @@ select 1 as \${dataform.projectConfig.vars.testVar2}
type: "table",
enumType: "TABLE",
target: {
database: "dataform-integration-tests",
database: "dataform-open-source",
schema: "dataform_test_schema_suffix",
name: "example"
},
canonicalTarget: {
schema: "dataform",
name: "example",
database: "dataform-integration-tests"
database: "dataform-open-source"
},
query: "\n\nselect 1 as testValue2\n",
disabled: false,
Expand All @@ -238,7 +232,7 @@ select 1 as \${dataform.projectConfig.vars.testVar2}
warehouse: "bigquery",
defaultSchema: "dataform",
assertionSchema: "dataform_assertions",
defaultDatabase: "dataform-integration-tests",
defaultDatabase: "dataform-open-source",
defaultLocation: "US",
vars: {
testVar1: "testValue1",
Expand All @@ -250,69 +244,71 @@ select 1 as \${dataform.projectConfig.vars.testVar2}
dataformCoreVersion: version,
targets: [
{
database: "dataform-integration-tests",
database: "dataform-open-source",
schema: "dataform",
name: "example"
}
]
});

// Dry run the project.
const runResult = await getProcessResult(
execFile(nodePath, [
cliEntryPointPath,
"run",
projectDir,
"--credentials",
path.resolve(process.env.RUNFILES, "df/test_credentials/bigquery.json"),
"--dry-run",
"--json",
"--vars=testVar1=testValue1,testVar2=testValue2",
"--default-location=europe",
"--tags=someTag,someOtherTag"
])
);
// TODO(ekrekr): re-enable this part of the test once we have working BQ credentials.

expect(runResult.exitCode).equals(0);
// // Dry run the project.
// const runResult = await getProcessResult(
// execFile(nodePath, [
// cliEntryPointPath,
// "run",
// projectDir,
// "--credentials",
// path.resolve(process.env.RUNFILES, "df/test_credentials/bigquery.json"),
// "--dry-run",
// "--json",
// "--vars=testVar1=testValue1,testVar2=testValue2",
// "--default-location=europe",
// "--tags=someTag,someOtherTag"
// ])
// );

expect(JSON.parse(runResult.stdout)).deep.equals({
actions: [
{
fileName: "definitions/example.sqlx",
hermeticity: "HERMETIC",
tableType: "table",
target: {
database: "dataform-integration-tests",
name: "example",
schema: "dataform"
},
tasks: [
{
statement:
"create or replace table `dataform-integration-tests.dataform.example` as \n\nselect 1 as testValue2",
type: "statement"
}
],
type: "table"
}
],
projectConfig: {
assertionSchema: "dataform_assertions",
defaultDatabase: "dataform-integration-tests",
defaultLocation: "europe",
defaultSchema: "dataform",
warehouse: "bigquery",
vars: {
testVar1: "testValue1",
testVar2: "testValue2"
}
},
runConfig: {
fullRefresh: false,
tags: ["someTag", "someOtherTag"]
},
warehouseState: {}
});
// expect(runResult.exitCode).equals(0);

// expect(JSON.parse(runResult.stdout)).deep.equals({
// actions: [
// {
// fileName: "definitions/example.sqlx",
// hermeticity: "HERMETIC",
// tableType: "table",
// target: {
// database: "dataform-open-source",
// name: "example",
// schema: "dataform"
// },
// tasks: [
// {
// statement:
// "create or replace table `dataform-open-source.dataform.example` as \n\nselect 1 as testValue2",
// type: "statement"
// }
// ],
// type: "table"
// }
// ],
// projectConfig: {
// assertionSchema: "dataform_assertions",
// defaultDatabase: "dataform-open-source",
// defaultLocation: "europe",
// defaultSchema: "dataform",
// warehouse: "bigquery",
// vars: {
// testVar1: "testValue1",
// testVar2: "testValue2"
// }
// },
// runConfig: {
// fullRefresh: false,
// tags: ["someTag", "someOtherTag"]
// },
// warehouseState: {}
// });
});
});

Expand Down
13 changes: 0 additions & 13 deletions cloudbuild-test.json

This file was deleted.

8 changes: 8 additions & 0 deletions cloudbuild.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
steps:
- name: gcr.io/cloud-builders/bazel:5.4.0
entrypoint: bash
args:
- ./scripts/run_tests
options:
machineType: E2_HIGHCPU_8
timeout: 3600s
7 changes: 5 additions & 2 deletions core/actions/assertion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ export const IAssertionConfigProperties = strictKeysOf<IAssertionConfig>()([
"name",
"schema",
"tags",
"type"
"type",
"dependOnDependencyAssertions"
Tuseeq1 marked this conversation as resolved.
Show resolved Hide resolved
]);

/**
Expand Down Expand Up @@ -151,7 +152,9 @@ export class Assertion extends ActionBuilder<dataform.Assertion> {
public dependencies(value: Resolvable | Resolvable[]) {
const newDependencies = Array.isArray(value) ? value : [value];
newDependencies.forEach(resolvable => {
this.proto.dependencyTargets.push(resolvableAsTarget(resolvable));
const resolvableTarget = resolvableAsTarget(resolvable);
this.session.actionAssertionMap.set(resolvableTarget, this);
this.proto.dependencyTargets.push(resolvableTarget);
});
return this;
}
Expand Down
1 change: 1 addition & 0 deletions core/actions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export type SqlxConfig = (

export abstract class ActionBuilder<T> {
public session: Session;
public includeAssertionsForDependency: Map<string, boolean> = new Map();

constructor(session?: Session) {
this.session = session;
Expand Down
19 changes: 16 additions & 3 deletions core/actions/notebook.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { verifyObjectMatchesProto } from "df/common/protos";
import { ActionBuilder } from "df/core/actions";
import { Resolvable } from "df/core/common";
import * as Path from "df/core/path";
import { Session } from "df/core/session";
import {
actionConfigToCompiledGraphTarget,
addDependenciesToActionDependencyTargets,
nativeRequire,
resolveActionsConfigFilename
} from "df/core/utils";
Expand All @@ -18,6 +20,9 @@ export class Notebook extends ActionBuilder<dataform.Notebook> {
// TODO: make this field private, to enforce proto update logic to happen in this class.
public proto: dataform.INotebook = dataform.Notebook.create();

// If true, adds the inline assertions of dependencies as direct dependencies for this action.
public dependOnDependencyAssertions: boolean = false;

constructor(
session?: Session,
config?: dataform.ActionConfig.NotebookConfig,
Expand All @@ -35,9 +40,8 @@ export class Notebook extends ActionBuilder<dataform.Notebook> {
this.proto.target = this.applySessionToTarget(target, config.filename);
this.proto.canonicalTarget = this.applySessionCanonicallyToTarget(target);
this.proto.tags = config.tags;
this.proto.dependencyTargets = config.dependencyTargets.map(dependencyTarget =>
actionConfigToCompiledGraphTarget(dataform.ActionConfig.Target.create(dependencyTarget))
);
this.dependOnDependencyAssertions = config.dependOnDependencyAssertions;
this.dependencies(config.dependencyTargets);
this.proto.fileName = config.filename;
if (config.disabled) {
this.proto.disabled = config.disabled;
Expand All @@ -61,6 +65,15 @@ export class Notebook extends ActionBuilder<dataform.Notebook> {
return this;
}

/**
* @hidden
*/
public dependencies(value: Resolvable | Resolvable[]) {
const newDependencies = Array.isArray(value) ? value : [value];
newDependencies.forEach(resolvable => addDependenciesToActionDependencyTargets(this, resolvable));
return this;
}

/**
* @hidden
*/
Expand Down
32 changes: 22 additions & 10 deletions core/actions/operation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@ import * as Path from "df/core/path";
import { Session } from "df/core/session";
import {
actionConfigToCompiledGraphTarget,
addDependenciesToActionDependencyTargets,
checkExcessProperties,
nativeRequire,
resolvableAsTarget,
resolveActionsConfigFilename,
setNameAndTarget,
strictKeysOf,
toResolvable
toResolvable,
} from "df/core/utils";
import { dataform } from "df/protos/ts";

Expand All @@ -31,10 +32,10 @@ import { dataform } from "df/protos/ts";
*/
export interface IOperationConfig
extends IActionConfig,
IDependenciesConfig,
IDocumentableConfig,
INamedConfig,
ITargetableConfig {
IDependenciesConfig,
IDocumentableConfig,
INamedConfig,
ITargetableConfig {
/**
* Declares that this `operations` action creates a dataset which should be referenceable using the `ref` function.
*
Expand All @@ -59,7 +60,8 @@ export const IIOperationConfigProperties = strictKeysOf<IOperationConfig>()([
"name",
"schema",
"tags",
"type"
"type",
"dependOnDependencyAssertions"
]);

/**
Expand All @@ -72,6 +74,9 @@ export class Operation extends ActionBuilder<dataform.Operation> {
// Hold a reference to the Session instance.
public session: Session;

// If true, adds the inline assertions of dependencies as direct dependencies for this action.
public dependOnDependencyAssertions: boolean = false;

// We delay contextification until the final compile step, so hold these here for now.
private contextableQueries: Contextable<ICommonContext, string | string[]>;

Expand Down Expand Up @@ -105,7 +110,8 @@ export class Operation extends ActionBuilder<dataform.Operation> {
tags: config.tags,
disabled: config.disabled,
hasOutput: config.hasOutput,
description: config.description
description: config.description,
dependOnDependencyAssertions: config.dependOnDependencyAssertions
});

this.queries(nativeRequire(config.filename).query);
Expand All @@ -118,6 +124,9 @@ export class Operation extends ActionBuilder<dataform.Operation> {
IIOperationConfigProperties,
"operation config"
);
if (config.dependOnDependencyAssertions) {
this.setDependOnDependencyAssertions(config.dependOnDependencyAssertions);
}
if (config.dependencies) {
this.dependencies(config.dependencies);
}
Expand Down Expand Up @@ -155,9 +164,7 @@ export class Operation extends ActionBuilder<dataform.Operation> {

public dependencies(value: Resolvable | Resolvable[]) {
const newDependencies = Array.isArray(value) ? value : [value];
newDependencies.forEach(resolvable => {
this.proto.dependencyTargets.push(resolvableAsTarget(resolvable));
});
newDependencies.forEach(resolvable => addDependenciesToActionDependencyTargets(this, resolvable));
return this;
}

Expand Down Expand Up @@ -228,6 +235,11 @@ export class Operation extends ActionBuilder<dataform.Operation> {
return this;
}

public setDependOnDependencyAssertions(dependOnDependencyAssertions: boolean) {
this.dependOnDependencyAssertions = dependOnDependencyAssertions;
return this;
}

/**
* @hidden
*/
Expand Down
Loading
Loading