Skip to content

Commit 2531b12

Browse files
authored
Update output for Data Preparation processing (#1808)
* Updated data preparation proto to only carry binary encoded data preparation contents after processing the data preparation definition. * Addressed PR Comments. * Addressed final PR comments * Fixed compilation issue.
1 parent ae85965 commit 2531b12

File tree

3 files changed

+30
-66
lines changed

3 files changed

+30
-66
lines changed

core/actions/data_preparation.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ export class DataPreparation extends ActionBuilder<dataform.DataPreparation> {
3434
}
3535

3636
config.filename = resolveActionsConfigFilename(config.filename, configPath);
37-
const dataPreparationContents = nativeRequire(config.filename).asJson;
38-
const dataPreparationDefinition = parseDataPreparationDefinitionJson(dataPreparationContents);
39-
this.proto.dataPreparation = dataPreparationDefinition;
37+
const dataPreparationAsJson = nativeRequire(config.filename).asJson;
38+
const dataPreparationDefinition = parseDataPreparationDefinitionJson(dataPreparationAsJson);
39+
this.proto.dataPreparationContents = dataform.DataPreparationDefinition.encode(dataPreparationDefinition).finish();
4040

4141
// Find targets
4242
const targets = getTargets(dataPreparationDefinition);

core/main_test.ts

+23-61
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
// tslint:disable tsr-detect-non-literal-fs-filename
22
import { expect } from "chai";
33
import * as fs from "fs-extra";
4-
import { dump as dumpYaml } from "js-yaml";
4+
import { dump as dumpYaml, load as loadYaml } from "js-yaml";
55
import * as path from "path";
66
import { CompilerFunction, NodeVM } from "vm2";
77

8-
import { decode64, encode64 } from "df/common/protos";
8+
import { decode64, encode64, verifyObjectMatchesProto } from "df/common/protos";
99
import { compile } from "df/core/compilers";
1010
import { version } from "df/core/version";
1111
import { dataform } from "df/protos/ts";
1212
import { asPlainObject, suite, test } from "df/testing";
1313
import { TmpDirFixture } from "df/testing/fixtures";
1414

15+
1516
const SOURCE_EXTENSIONS = ["js", "sql", "sqlx", "yaml", "ipynb"];
1617

1718
const VALID_WORKFLOW_SETTINGS_YAML = `
@@ -877,9 +878,7 @@ actions:
877878

878879
test(`data preparations can be loaded via an actions config file`, () => {
879880
const projectDir = createSimpleDataPreparationProject();
880-
fs.writeFileSync(
881-
path.join(projectDir, "definitions/data_preparation.yaml"),
882-
`
881+
const dataPreparationYaml = `
883882
nodes:
884883
- id: node1
885884
source:
@@ -912,6 +911,23 @@ nodes:
912911
type: STRING
913912
mode: NULLABLE
914913
`
914+
915+
fs.writeFileSync(
916+
path.join(projectDir, "definitions/data_preparation.yaml"),
917+
dataPreparationYaml
918+
);
919+
920+
// Generate Base64 encoded representation of the YAML.
921+
const dataPreparationAsObject = loadYaml(dataPreparationYaml);
922+
const dataPreparationDefinition = verifyObjectMatchesProto(
923+
dataform.DataPreparationDefinition,
924+
dataPreparationAsObject as {
925+
[key: string]: any;
926+
}
927+
);
928+
const base64encodedContents = encode64(
929+
dataform.DataPreparationDefinition,
930+
dataPreparationDefinition
915931
);
916932

917933
const result = runMainInVm(coreExecutionRequestFromPath(projectDir));
@@ -945,62 +961,8 @@ nodes:
945961
}
946962
],
947963
fileName: "definitions/data_preparation.yaml",
948-
dataPreparation: {
949-
nodes: [
950-
{
951-
id: "node1",
952-
source: {
953-
table: {
954-
dataset: "ds",
955-
project: "prj",
956-
table: "src"
957-
}
958-
},
959-
destination: {
960-
table: {
961-
dataset: "ds",
962-
project: "prj",
963-
table: "dest"
964-
}
965-
},
966-
generated: {
967-
destinationGenerated: {
968-
schema: {
969-
field: [
970-
{
971-
mode: "NULLABLE",
972-
name: "a",
973-
type: "STRING"
974-
}
975-
]
976-
}
977-
},
978-
outputSchema: {
979-
field: [
980-
{
981-
mode: "NULLABLE",
982-
name: "a",
983-
type: "INT64"
984-
}
985-
]
986-
},
987-
sourceGenerated: {
988-
sourceSchema: {
989-
tableSchema: {
990-
field: [
991-
{
992-
mode: "NULLABLE",
993-
name: "a",
994-
type: "STRING"
995-
}
996-
]
997-
}
998-
}
999-
}
1000-
}
1001-
}
1002-
]
1003-
}
964+
// Base64 encoded representation of the data preparation definition proto.
965+
dataPreparationContents: base64encodedContents
1004966
}
1005967
])
1006968
);

protos/core.proto

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
syntax = "proto3";
2-
import "data_preparation.proto";
32

43
package dataform;
54

@@ -268,7 +267,10 @@ message DataPreparation {
268267

269268
bool disabled = 6;
270269

271-
DataPreparationDefinition data_preparation = 7;
270+
// Binary encoded contents of the Data preparation proto
271+
bytes data_preparation_contents = 10;
272+
273+
reserved 7;
272274
}
273275

274276
message CompiledGraph {

0 commit comments

Comments
 (0)