Skip to content

Commit

Permalink
Populate warehouse as BigQuery by default (dataform-co#1591)
Browse files Browse the repository at this point in the history
* Populate warehouse as BigQuery by default, update tests

* Remove log

* Add tslint ignore for no string literal
  • Loading branch information
Ekrekr authored Nov 27, 2023
1 parent 6264b04 commit be9f0e4
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 113 deletions.
52 changes: 0 additions & 52 deletions cli/api/commands/compile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,6 @@ import { decode64 } from "df/common/protos";
import { setOrValidateTableEnumType } from "df/core/utils";
import { dataform } from "df/protos/ts";

// Project config properties that are required.
const mandatoryProps: Array<keyof dataform.IProjectConfig> = ["warehouse", "defaultSchema"];

// Project config properties that require alphanumeric characters, hyphens or underscores.
const simpleCheckProps: Array<keyof dataform.IProjectConfig> = [
"assertionSchema",
"databaseSuffix",
"schemaSuffix",
"tablePrefix",
"defaultSchema"
];

export class CompilationTimeoutError extends Error {}

export async function compile(
Expand All @@ -30,18 +18,6 @@ export async function compile(
// Resolve the path in case it hasn't been resolved already.
path.resolve(compileConfig.projectDir);

try {
// check dataformJson is valid before we try to compile
const dataformJson = fs.readFileSync(`${compileConfig.projectDir}/dataform.json`, "utf8");
const projectConfig = JSON.parse(dataformJson);
checkDataformJsonValidity(deepmerge(projectConfig, compileConfig.projectConfigOverride || {}));
} catch (e) {
throw new ErrorWithCause(
`Compilation failed. ProjectConfig ('dataform.json') is invalid: ${e.message}`,
e
);
}

const result = await CompileChildProcess.forkProcess().compile(compileConfig);

const decodedResult = decode64(dataform.CoreExecutionResponse, result);
Expand Down Expand Up @@ -116,31 +92,3 @@ export class CompileChildProcess {
}
}
}

export const checkDataformJsonValidity = (dataformJsonParsed: { [prop: string]: any }) => {
const invalidWarehouseProp = () => {
return dataformJsonParsed.warehouse && !validWarehouses.includes(dataformJsonParsed.warehouse)
? `Invalid value on property warehouse: ${
dataformJsonParsed.warehouse
}. Should be one of: ${validWarehouses.join(", ")}.`
: null;
};
const invalidProp = () => {
const invProp = simpleCheckProps.find(prop => {
return prop in dataformJsonParsed && !/^[a-zA-Z_0-9\-]*$/.test(dataformJsonParsed[prop]);
});
return invProp
? `Invalid value on property ${invProp}: ${dataformJsonParsed[invProp]}. Should only contain alphanumeric characters, underscores and/or hyphens.`
: null;
};
const missingMandatoryProp = () => {
const missMandatoryProp = mandatoryProps.find(prop => {
return !(prop in dataformJsonParsed);
});
return missMandatoryProp ? `Missing mandatory property: ${missMandatoryProp}.` : null;
};
const message = invalidWarehouseProp() || invalidProp() || missingMandatoryProp();
if (message) {
throw new Error(message);
}
};
1 change: 0 additions & 1 deletion core/main_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import { TmpDirFixture } from "df/testing/fixtures";
import { asPlainObject } from "df/tests/utils";

const VALID_WORKFLOW_SETTINGS_YAML = `
warehouse: bigquery
defaultDatabase: dataform
`;

Expand Down
9 changes: 8 additions & 1 deletion core/workflow_settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export function readWorkflowSettings(): dataform.ProjectConfig {
throw Error("Failed to resolve workflow_settings.yaml");
}

function verifyWorkflowSettingsAsJson(workflowSettingsAsJson: object) {
function verifyWorkflowSettingsAsJson(workflowSettingsAsJson: object): { [key: string]: any } {
try {
verifyObjectMatchesProto(dataform.ProjectConfig, workflowSettingsAsJson);
} catch (e) {
Expand All @@ -42,6 +42,13 @@ function verifyWorkflowSettingsAsJson(workflowSettingsAsJson: object) {
}
throw e;
}
const verifiedWorkflowSettings = workflowSettingsAsJson as { [key: string]: any };
// tslint:disable-next-line: no-string-literal
if (!verifiedWorkflowSettings["warehouse"]) {
// tslint:disable-next-line: no-string-literal
verifiedWorkflowSettings["warehouse"] = "bigquery";
}
return verifiedWorkflowSettings;
}

function maybeRequire(file: string): any {
Expand Down
7 changes: 0 additions & 7 deletions examples/stackoverflow_reporter/dataform.json

This file was deleted.

4 changes: 4 additions & 0 deletions examples/stackoverflow_reporter/workflow_settings.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
defaultDatabase: "dataform-demos"
defaultLocation: "us"
defaultSchema: "dataform"
assertionSchema: "dataform_assertions"
52 changes: 0 additions & 52 deletions tests/api/validate.spec.ts

This file was deleted.

0 comments on commit be9f0e4

Please sign in to comment.