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
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.proto.target);
this.proto.dependencyTargets.push(resolvableTarget);
});
return this;
}
Expand Down
32 changes: 29 additions & 3 deletions core/actions/operation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ import {
resolveActionsConfigFilename,
setNameAndTarget,
strictKeysOf,
toResolvable
toResolvable,
isSameTarget
} from "df/core/utils";
import { dataform } from "df/protos/ts";

Expand Down Expand Up @@ -59,7 +60,8 @@ export const IIOperationConfigProperties = strictKeysOf<IOperationConfig>()([
"name",
"schema",
"tags",
"type"
"type",
"dependOnDependencyAssertions"
]);

/**
Expand All @@ -75,6 +77,10 @@ export class Operation extends ActionBuilder<dataform.Operation> {
// We delay contextification until the final compile step, so hold these here for now.
private contextableQueries: Contextable<ICommonContext, string | string[]>;

// This is Action level flag. If set to true, we will add assertions from all the depenedncies of
// current action as dependencies.
public dependOnDependencyAssertions: boolean = false;
Ekrekr marked this conversation as resolved.
Show resolved Hide resolved

constructor(
session?: Session,
config?: dataform.ActionConfig.OperationConfig,
Expand Down Expand Up @@ -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 @@ -156,7 +165,19 @@ 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));
let dependencyTarget = resolvableAsTarget(resolvable);
dependencyTarget.includeDependentAssertions = dependencyTarget.includeDependentAssertions===undefined ? this.dependOnDependencyAssertions : dependencyTarget.includeDependentAssertions;
const existingDependencies = this.proto.dependencyTargets.filter(dependency => isSameTarget(dependencyTarget, dependency) && dependency.includeDependentAssertions !== dependencyTarget.includeDependentAssertions)
if (existingDependencies.length !== 0){
this.session.compileError(
`Conflicting "includeDependentAssertions" flag not allowed. Dependency ${dependencyTarget.name} have different value set for this flag.`,
this.proto.fileName,
this.proto.target
)
return this;
}

this.proto.dependencyTargets.push(dependencyTarget);
Ekrekr marked this conversation as resolved.
Show resolved Hide resolved
});
return this;
}
Expand Down Expand Up @@ -228,6 +249,11 @@ export class Operation extends ActionBuilder<dataform.Operation> {
return this;
}

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

/**
* @hidden
*/
Expand Down
32 changes: 29 additions & 3 deletions core/actions/table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ import {
strictKeysOf,
tableTypeStringToEnum,
toResolvable,
validateQueryString
validateQueryString,
isSameTarget
} from "df/core/utils";
import { dataform } from "df/protos/ts";

Expand Down Expand Up @@ -221,7 +222,8 @@ export const ITableConfigProperties = () =>
"database",
"columns",
"description",
"materialized"
"materialized",
"dependOnDependencyAssertions"
]);

/**
Expand Down Expand Up @@ -265,6 +267,10 @@ export class Table extends ActionBuilder<dataform.Table> {
private uniqueKeyAssertions: Assertion[] = [];
private rowConditionsAssertion: Assertion;

// This is Action level flag. If set to true, we will add assertions from all the depenedncies of
// current action as dependencies.
public dependOnDependencyAssertions: boolean = false;

constructor(
session?: Session,
tableTypeConfig?:
Expand Down Expand Up @@ -444,6 +450,9 @@ export class Table extends ActionBuilder<dataform.Table> {
if (config.type) {
this.type(config.type);
}
if (config.dependOnDependencyAssertions) {
this.setDependOnDependencyAssertions(config.dependOnDependencyAssertions);
}
if (config.dependencies) {
this.dependencies(config.dependencies);
}
Expand Down Expand Up @@ -553,7 +562,19 @@ export class Table extends ActionBuilder<dataform.Table> {
public dependencies(value: Resolvable | Resolvable[]) {
const newDependencies = Array.isArray(value) ? value : [value];
newDependencies.forEach(resolvable => {
this.proto.dependencyTargets.push(resolvableAsTarget(resolvable));
let dependencyTarget = resolvableAsTarget(resolvable);
dependencyTarget.includeDependentAssertions = dependencyTarget.includeDependentAssertions===undefined ? this.dependOnDependencyAssertions : dependencyTarget.includeDependentAssertions;
Ekrekr marked this conversation as resolved.
Show resolved Hide resolved
const existingDependencies = this.proto.dependencyTargets.filter(dependency => isSameTarget(dependencyTarget, dependency) && dependency.includeDependentAssertions !== dependencyTarget.includeDependentAssertions)
Ekrekr marked this conversation as resolved.
Show resolved Hide resolved
if (existingDependencies.length !== 0){
this.session.compileError(
`Conflicting "includeDependentAssertions" flag not allowed. Dependency ${dependencyTarget.name} have different value set for this flag.`,
this.proto.fileName,
this.proto.target
)
return this;
}

this.proto.dependencyTargets.push(dependencyTarget);
});

return this;
Expand Down Expand Up @@ -676,6 +697,11 @@ export class Table extends ActionBuilder<dataform.Table> {
return this;
}

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

/**
* @hidden
*/
Expand Down
7 changes: 7 additions & 0 deletions core/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,11 @@ export interface IDependenciesConfig {
* dependencies, then it should be set to `true`.
*/
hermetic?: boolean;

/**
* If this flag is set to true, assertions depenedent upon any of the dependencies are added as depenedencies as well.
*/
dependOnDependencyAssertions?: boolean;
Tuseeq1 marked this conversation as resolved.
Show resolved Hide resolved
}

/**
Expand Down Expand Up @@ -219,6 +224,8 @@ export interface ITarget {
schema?: string;

name?: string;

IncludeDependentAssertions?: boolean;
Ekrekr marked this conversation as resolved.
Show resolved Hide resolved
}

/**
Expand Down
Loading
Loading