@@ -5,7 +5,7 @@ import { dump as dumpYaml, load as loadYaml } from "js-yaml";
55import * as path from "path" ;
66import { CompilerFunction , NodeVM } from "vm2" ;
77
8- import { decode64 , encode64 , verifyObjectMatchesProto } from "df/common/protos" ;
8+ import { decode64 , encode64 , verifyObjectMatchesProto , VerifyProtoErrorBehaviour } from "df/common/protos" ;
99import { compile } from "df/core/compilers" ;
1010import { version } from "df/core/version" ;
1111import { dataform } from "df/protos/ts" ;
@@ -913,7 +913,7 @@ nodes:
913913`
914914
915915 fs . writeFileSync (
916- path . join ( projectDir , "definitions/data_preparation.yaml" ) ,
916+ path . join ( projectDir , "definitions/data_preparation.yaml" ) ,
917917 dataPreparationYaml
918918 ) ;
919919
@@ -923,7 +923,8 @@ nodes:
923923 dataform . dataprep . DataPreparation ,
924924 dataPreparationAsObject as {
925925 [ key : string ] : any ;
926- }
926+ } ,
927+ VerifyProtoErrorBehaviour . DEFAULT
927928 ) ;
928929 const base64encodedContents = encode64 (
929930 dataform . dataprep . DataPreparation ,
@@ -934,37 +935,200 @@ nodes:
934935
935936 expect ( result . compile . compiledGraph . graphErrors . compilationErrors ) . deep . equals ( [ ] ) ;
936937 expect ( asPlainObject ( result . compile . compiledGraph . dataPreparations ) ) . deep . equals (
937- asPlainObject ( [
938- {
939- target : {
940- database : "prj" ,
941- schema : "ds" ,
942- name : "dest"
943- } ,
944- canonicalTarget : {
945- database : "prj" ,
946- schema : "ds" ,
947- name : "dest"
948- } ,
949- targets : [
950- {
938+ asPlainObject ( [
939+ {
940+ target : {
951941 database : "prj" ,
952942 schema : "ds" ,
953943 name : "dest"
954- }
955- ] ,
956- canonicalTargets : [
957- {
944+ } ,
945+ canonicalTarget : {
958946 database : "prj" ,
959947 schema : "ds" ,
960948 name : "dest"
961- }
962- ] ,
963- fileName : "definitions/data_preparation.yaml" ,
964- // Base64 encoded representation of the data preparation definition proto.
965- dataPreparationContents : base64encodedContents
966- }
967- ] )
949+ } ,
950+ targets : [
951+ {
952+ database : "prj" ,
953+ schema : "ds" ,
954+ name : "dest"
955+ }
956+ ] ,
957+ canonicalTargets : [
958+ {
959+ database : "prj" ,
960+ schema : "ds" ,
961+ name : "dest"
962+ }
963+ ] ,
964+ fileName : "definitions/data_preparation.yaml" ,
965+ // Base64 encoded representation of the data preparation definition proto.
966+ dataPreparationContents : base64encodedContents
967+ }
968+ ] )
969+ ) ;
970+ } ) ;
971+
972+ test ( `data preparations resolves compilation overrides before encoding` , ( ) => {
973+ const projectDir = createSimpleDataPreparationProject ( ) ;
974+ const dataPreparationYaml = `
975+ configuration:
976+ errorTable:
977+ table: error
978+ nodes:
979+ - id: node1
980+ source:
981+ table:
982+ table: src
983+ generated:
984+ sourceGenerated:
985+ sourceSchema:
986+ tableSchema:
987+ field:
988+ - name: a
989+ type: STRING
990+ mode: NULLABLE
991+ outputSchema:
992+ field:
993+ - name: a
994+ type: INT64
995+ mode: NULLABLE
996+ - id: node2
997+ source:
998+ nodeId: node1
999+ destination:
1000+ table:
1001+ table: dest
1002+ generated:
1003+ sourceGenerated:
1004+ sourceSchema:
1005+ nodeSchema:
1006+ field:
1007+ - name: a
1008+ type: STRING
1009+ mode: NULLABLE
1010+ outputSchema:
1011+ field:
1012+ - name: a
1013+ type: INT64
1014+ mode: NULLABLE
1015+ destinationGenerated:
1016+ schema:
1017+ field:
1018+ - name: a
1019+ type: STRING
1020+ mode: NULLABLE
1021+ `
1022+
1023+ fs . writeFileSync (
1024+ path . join ( projectDir , "definitions/data_preparation.yaml" ) ,
1025+ dataPreparationYaml
1026+ ) ;
1027+
1028+ const resolvedYaml = `
1029+ configuration:
1030+ errorTable:
1031+ project: defaultProject
1032+ dataset: defaultDataset
1033+ table: error
1034+ nodes:
1035+ - id: node1
1036+ source:
1037+ table:
1038+ project: defaultProject
1039+ dataset: defaultDataset
1040+ table: src
1041+ generated:
1042+ sourceGenerated:
1043+ sourceSchema:
1044+ tableSchema:
1045+ field:
1046+ - name: a
1047+ type: STRING
1048+ mode: NULLABLE
1049+ outputSchema:
1050+ field:
1051+ - name: a
1052+ type: INT64
1053+ mode: NULLABLE
1054+ - id: node2
1055+ source:
1056+ nodeId: node1
1057+ destination:
1058+ table:
1059+ project: defaultProject
1060+ dataset: defaultDataset
1061+ table: dest
1062+ generated:
1063+ sourceGenerated:
1064+ sourceSchema:
1065+ nodeSchema:
1066+ field:
1067+ - name: a
1068+ type: STRING
1069+ mode: NULLABLE
1070+ outputSchema:
1071+ field:
1072+ - name: a
1073+ type: INT64
1074+ mode: NULLABLE
1075+ destinationGenerated:
1076+ schema:
1077+ field:
1078+ - name: a
1079+ type: STRING
1080+ mode: NULLABLE
1081+ `
1082+
1083+ // Generate Base64 encoded representation of the YAML.
1084+ const dataPreparationAsObject = loadYaml ( resolvedYaml ) ;
1085+ const dataPreparationDefinition = verifyObjectMatchesProto (
1086+ dataform . dataprep . DataPreparation ,
1087+ dataPreparationAsObject as {
1088+ [ key : string ] : any ;
1089+ } ,
1090+ VerifyProtoErrorBehaviour . DEFAULT
1091+ ) ;
1092+ const base64encodedContents = encode64 (
1093+ dataform . dataprep . DataPreparation ,
1094+ dataPreparationDefinition
1095+ ) ;
1096+
1097+ const result = runMainInVm ( coreExecutionRequestFromPath ( projectDir ) ) ;
1098+
1099+ expect ( result . compile . compiledGraph . graphErrors . compilationErrors ) . deep . equals ( [ ] ) ;
1100+ expect ( asPlainObject ( result . compile . compiledGraph . dataPreparations ) ) . deep . equals (
1101+ asPlainObject ( [
1102+ {
1103+ target : {
1104+ database : "defaultProject" ,
1105+ schema : "defaultDataset" ,
1106+ name : "dest"
1107+ } ,
1108+ canonicalTarget : {
1109+ database : "defaultProject" ,
1110+ schema : "defaultDataset" ,
1111+ name : "dest"
1112+ } ,
1113+ targets : [
1114+ {
1115+ database : "defaultProject" ,
1116+ schema : "defaultDataset" ,
1117+ name : "dest"
1118+ }
1119+ ] ,
1120+ canonicalTargets : [
1121+ {
1122+ database : "defaultProject" ,
1123+ schema : "defaultDataset" ,
1124+ name : "dest"
1125+ }
1126+ ] ,
1127+ fileName : "definitions/data_preparation.yaml" ,
1128+ // Base64 encoded representation of the data preparation definition proto.
1129+ dataPreparationContents : base64encodedContents
1130+ }
1131+ ] )
9681132 ) ;
9691133 } ) ;
9701134 } ) ;
0 commit comments