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

Add tests for column descriptors in action configs #1764

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
34 changes: 15 additions & 19 deletions core/actions/declaration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,27 +95,23 @@ export class Declaration extends ActionBuilder<dataform.Declaration> {
private verifyConfig(
unverifiedConfig: ILegacyDeclarationConfig
): dataform.ActionConfig.DeclarationConfig {
if (unverifiedConfig.database) {
unverifiedConfig.project = unverifiedConfig.database;
delete unverifiedConfig.database;
}
if (unverifiedConfig.schema) {
unverifiedConfig.dataset = unverifiedConfig.schema;
delete unverifiedConfig.schema;
}
if (unverifiedConfig.columns) {
// TODO(ekrekr) columns in their current config format are a difficult structure to represent
// as protos. They are nested, and use the object keys as the names. Consider a forced
// migration to the proto style column names.
unverifiedConfig.columns = ColumnDescriptors.mapLegacyObjectToConfigProto(
unverifiedConfig.columns as any
);
}

// TODO(ekrekr): consider moving this to a shared location after all action builders have proto
// config verifiers.
// The "type" field only exists on legacy declaration configs. Here we convert them to the new
// format.
if (unverifiedConfig.type) {
delete unverifiedConfig.type;
if (unverifiedConfig.database) {
unverifiedConfig.project = unverifiedConfig.database;
delete unverifiedConfig.database;
}
if (unverifiedConfig.schema) {
unverifiedConfig.dataset = unverifiedConfig.schema;
delete unverifiedConfig.schema;
}
if (unverifiedConfig.columns) {
unverifiedConfig.columns = ColumnDescriptors.mapLegacyObjectToConfigProto(
unverifiedConfig.columns as any
);
}
}

return verifyObjectMatchesProto(
Expand Down
69 changes: 55 additions & 14 deletions core/main_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2069,6 +2069,46 @@ SELECT 1`
});

suite("action config options", () => {
const exampleActionDescriptor = {
inputActionConfigBlock: `
columns:
- path:
- column1Key
description: column1Val
- path:
- column2Key
tags:
- tag3
- tag4
bigqueryPolicyTags:
- bigqueryPolicyTag1
- bigqueryPolicyTag2
description: description
- path:
- column2Key
- nestedColumnKey
description: nestedColumnVal`,
outputActionDescriptor: {
columns: [
{
description: "column1Val",
path: ["column1Key"]
},
{
bigqueryPolicyTags: ["bigqueryPolicyTag1", "bigqueryPolicyTag2"],
description: "description",
path: ["column2Key"],
tags: ["tag3", "tag4"]
},
{
description: "nestedColumnVal",
path: ["column2Key", "nestedColumnKey"]
}
],
description: "description"
}
};

const exampleBuiltInAssertions = {
inputActionConfigBlock: `
assertions:
Expand Down Expand Up @@ -2230,7 +2270,7 @@ actions:
dataset: dataset
project: project
description: description
`
${exampleActionDescriptor.inputActionConfigBlock}`
);

const result = runMainInVm(coreExecutionRequestFromPath(projectDir));
Expand All @@ -2250,7 +2290,7 @@ actions:
name: "name"
},
actionDescriptor: {
description: "description"
...exampleActionDescriptor.outputActionDescriptor
}
}
])
Expand All @@ -2266,7 +2306,7 @@ actions:
fs.mkdirSync(path.join(projectDir, "definitions"));
fs.writeFileSync(path.join(projectDir, "definitions/operation.sqlx"), "SELECT 1");
fs.writeFileSync(path.join(projectDir, "definitions/filename.sql"), "SELECT 1");
// TODO(ekrekr): add support for columns.
// TODO(ekrekr): add support for columns once table is its own unique action constructor.
fs.writeFileSync(
path.join(projectDir, "definitions/actions.yaml"),
`
Expand Down Expand Up @@ -2344,10 +2384,10 @@ ${exampleBuiltInAssertions.inputActionConfigBlock}
fileName: "definitions/filename.sql",
query: "SELECT 1",
actionDescriptor: {
description: "description",
bigqueryLabels: {
key: "val"
},
description: "description"
}
}
}
]);
Expand All @@ -2365,7 +2405,6 @@ ${exampleBuiltInAssertions.inputActionConfigBlock}
fs.mkdirSync(path.join(projectDir, "definitions"));
fs.writeFileSync(path.join(projectDir, "definitions/operation.sqlx"), "SELECT 1");
fs.writeFileSync(path.join(projectDir, "definitions/filename.sql"), "SELECT 1");
// TODO(ekrekr): add support for columns.
fs.writeFileSync(
path.join(projectDir, "definitions/actions.yaml"),
`
Expand All @@ -2383,15 +2422,15 @@ actions:
disabled: true
materialized: true
description: description
${exampleActionDescriptor.inputActionConfigBlock}
labels:
key: val
additionalOptions:
option1Key: option1
option2Key: option2
dependOnDependencyAssertions: true
${exampleBuiltInAssertions.inputActionConfigBlock}
hermetic: true
`
hermetic: true`
);

const result = runMainInVm(coreExecutionRequestFromPath(projectDir));
Expand Down Expand Up @@ -2435,10 +2474,10 @@ ${exampleBuiltInAssertions.inputActionConfigBlock}
fileName: "definitions/filename.sql",
query: "SELECT 1",
actionDescriptor: {
...exampleActionDescriptor.outputActionDescriptor,
bigqueryLabels: {
key: "val"
},
description: "description"
}
},
materialized: true
}
Expand Down Expand Up @@ -2478,6 +2517,7 @@ actions:
- key1
- key2
description: description
${exampleActionDescriptor.inputActionConfigBlock}
partitionBy: partitionBy
partitionExpirationDays: 1
requirePartitionFilter: true
Expand All @@ -2492,7 +2532,7 @@ actions:
dependOnDependencyAssertions: true
${exampleBuiltInAssertions.inputActionConfigBlock}
hermetic: true
`
`
);

const result = runMainInVm(coreExecutionRequestFromPath(projectDir));
Expand Down Expand Up @@ -2542,6 +2582,7 @@ ${exampleBuiltInAssertions.inputActionConfigBlock}
query: "SELECT 1",
incrementalQuery: "SELECT 1",
actionDescriptor: {
...exampleActionDescriptor.outputActionDescriptor,
bigqueryLabels: {
key: "val"
},
Expand Down Expand Up @@ -2584,9 +2625,9 @@ actions:
disabled: true
hasOutput: true
description: description
${exampleActionDescriptor.inputActionConfigBlock}
dependOnDependencyAssertions: true
hermetic: true
`
hermetic: true`
);

const result = runMainInVm(coreExecutionRequestFromPath(projectDir));
Expand Down Expand Up @@ -2619,7 +2660,7 @@ actions:
tags: ["tagA", "tagB"],
queries: ["SELECT 1"],
actionDescriptor: {
description: "description"
...exampleActionDescriptor.outputActionDescriptor
}
}
])
Expand Down