Skip to content

Commit 7c0987b

Browse files
JiT SQLX support
1 parent d07fdb1 commit 7c0987b

6 files changed

Lines changed: 666 additions & 7 deletions

File tree

core/actions/incremental_table_test.ts

Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -982,5 +982,161 @@ select \${incremental()} as is_incremental`
982982
expect(result.compile.compiledGraph.graphErrors.compilationErrors.length).greaterThan(0);
983983
expect(result.compile.compiledGraph.graphErrors.compilationErrors.some(e => e.message.includes("Cannot mix AoT and JiT compilation"))).equals(true);
984984
});
985+
986+
test("jit compilation is supported in sqlx", () => {
987+
const projectDir = tmpDirFixture.createNewTmpDir();
988+
fs.writeFileSync(path.join(projectDir, "workflow_settings.yaml"), VALID_WORKFLOW_SETTINGS_YAML);
989+
fs.mkdirSync(path.join(projectDir, "definitions"));
990+
fs.writeFileSync(
991+
path.join(projectDir, "definitions/incremental.sqlx"),
992+
`config { type: "incremental", compilation_mode: "jit" }
993+
js {
994+
const foo = "bar";
995+
}
996+
SELECT 1
997+
\${when(incremental(), "WHERE 1=1")}`
998+
);
999+
1000+
const result = runMainInVm(coreExecutionRequestFromPath(projectDir));
1001+
1002+
expect(result.compile.compiledGraph.graphErrors.compilationErrors).deep.equals([]);
1003+
expect(asPlainObject(result.compile.compiledGraph.tables)).deep.equals([
1004+
{
1005+
target: {
1006+
database: "defaultProject",
1007+
schema: "defaultDataset",
1008+
name: "incremental"
1009+
},
1010+
canonicalTarget: {
1011+
database: "defaultProject",
1012+
schema: "defaultDataset",
1013+
name: "incremental"
1014+
},
1015+
type: "incremental",
1016+
enumType: "INCREMENTAL",
1017+
disabled: false,
1018+
protected: false,
1019+
hermeticity: "NON_HERMETIC",
1020+
onSchemaChange: "IGNORE",
1021+
fileName: "definitions/incremental.sqlx",
1022+
jitCode: `async (jctx) => {
1023+
const self = jctx.self ? jctx.self.bind(jctx) : undefined;
1024+
const ref = jctx.ref ? jctx.ref.bind(jctx) : undefined;
1025+
const resolve = jctx.resolve ? jctx.resolve.bind(jctx) : undefined;
1026+
const name = jctx.name ? jctx.name.bind(jctx) : undefined;
1027+
const when = jctx.when ? jctx.when.bind(jctx) : undefined;
1028+
const incremental = jctx.incremental ? jctx.incremental.bind(jctx) : undefined;
1029+
const schema = jctx.schema ? jctx.schema.bind(jctx) : undefined;
1030+
const database = jctx.database ? jctx.database.bind(jctx) : undefined;
1031+
const adapter = jctx.adapter ? jctx.adapter : undefined;
1032+
const data = jctx.data ? jctx.data : undefined;
1033+
1034+
const foo = "bar";
1035+
1036+
return {
1037+
query: (
1038+
\`
1039+
1040+
SELECT 1
1041+
\${when(incremental(), "WHERE 1=1")}\`
1042+
),
1043+
postOps: (
1044+
undefined
1045+
),
1046+
preOps: (
1047+
undefined
1048+
),
1049+
};
1050+
}`,
1051+
actionDescriptor: {
1052+
compilationMode: "ACTION_COMPILATION_MODE_JIT"
1053+
}
1054+
}
1055+
]);
1056+
});
1057+
1058+
test("jit compilation with pre/post ops is supported in sqlx", () => {
1059+
const projectDir = tmpDirFixture.createNewTmpDir();
1060+
fs.writeFileSync(path.join(projectDir, "workflow_settings.yaml"), VALID_WORKFLOW_SETTINGS_YAML);
1061+
fs.mkdirSync(path.join(projectDir, "definitions"));
1062+
fs.writeFileSync(
1063+
path.join(projectDir, "definitions/incremental.sqlx"),
1064+
`config { type: "incremental", compilation_mode: "jit" }
1065+
js {
1066+
const foo = "bar";
1067+
}
1068+
SELECT 1
1069+
\${when(incremental(), "WHERE 1=1")};
1070+
pre_operations {
1071+
SELECT 10;
1072+
}
1073+
post_operations {
1074+
SELECT 20;
1075+
}`
1076+
);
1077+
1078+
const result = runMainInVm(coreExecutionRequestFromPath(projectDir));
1079+
1080+
expect(result.compile.compiledGraph.graphErrors.compilationErrors).deep.equals([]);
1081+
expect(asPlainObject(result.compile.compiledGraph.tables)).deep.equals([
1082+
{
1083+
target: {
1084+
database: "defaultProject",
1085+
schema: "defaultDataset",
1086+
name: "incremental"
1087+
},
1088+
canonicalTarget: {
1089+
database: "defaultProject",
1090+
schema: "defaultDataset",
1091+
name: "incremental"
1092+
},
1093+
type: "incremental",
1094+
enumType: "INCREMENTAL",
1095+
disabled: false,
1096+
protected: false,
1097+
hermeticity: "NON_HERMETIC",
1098+
onSchemaChange: "IGNORE",
1099+
fileName: "definitions/incremental.sqlx",
1100+
jitCode: `async (jctx) => {
1101+
const self = jctx.self ? jctx.self.bind(jctx) : undefined;
1102+
const ref = jctx.ref ? jctx.ref.bind(jctx) : undefined;
1103+
const resolve = jctx.resolve ? jctx.resolve.bind(jctx) : undefined;
1104+
const name = jctx.name ? jctx.name.bind(jctx) : undefined;
1105+
const when = jctx.when ? jctx.when.bind(jctx) : undefined;
1106+
const incremental = jctx.incremental ? jctx.incremental.bind(jctx) : undefined;
1107+
const schema = jctx.schema ? jctx.schema.bind(jctx) : undefined;
1108+
const database = jctx.database ? jctx.database.bind(jctx) : undefined;
1109+
const adapter = jctx.adapter ? jctx.adapter : undefined;
1110+
const data = jctx.data ? jctx.data : undefined;
1111+
1112+
const foo = "bar";
1113+
1114+
return {
1115+
query: (
1116+
\`
1117+
1118+
SELECT 1
1119+
\${when(incremental(), "WHERE 1=1")};
1120+
1121+
\`
1122+
),
1123+
postOps: (
1124+
[\`
1125+
SELECT 20;
1126+
\`]
1127+
),
1128+
preOps: (
1129+
[\`
1130+
SELECT 10;
1131+
\`]
1132+
),
1133+
};
1134+
}`,
1135+
actionDescriptor: {
1136+
compilationMode: "ACTION_COMPILATION_MODE_JIT"
1137+
}
1138+
}
1139+
]);
1140+
});
9851141
});
9861142
});

core/actions/operation_test.ts

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,5 +255,68 @@ actions:
255255
expect(result.compile.compiledGraph.graphErrors.compilationErrors.length).greaterThan(0);
256256
expect(result.compile.compiledGraph.graphErrors.compilationErrors.some(e => e.message.includes("Cannot mix AoT and JiT compilation"))).equals(true);
257257
});
258+
259+
test("jit compilation is supported in sqlx", () => {
260+
const projectDir = tmpDirFixture.createNewTmpDir();
261+
fs.writeFileSync(path.join(projectDir, "workflow_settings.yaml"), VALID_WORKFLOW_SETTINGS_YAML);
262+
fs.mkdirSync(path.join(projectDir, "definitions"));
263+
fs.writeFileSync(
264+
path.join(projectDir, "definitions/op.sqlx"),
265+
`config { type: "operations", compilation_mode: "jit" }
266+
js {
267+
const foo = "bar";
268+
}
269+
SELECT 1
270+
---
271+
SELECT 2`
272+
);
273+
274+
const result = runMainInVm(coreExecutionRequestFromPath(projectDir));
275+
276+
expect(result.compile.compiledGraph.graphErrors.compilationErrors).deep.equals([]);
277+
expect(asPlainObject(result.compile.compiledGraph.operations)).deep.equals([
278+
{
279+
target: {
280+
database: "defaultProject",
281+
schema: "defaultDataset",
282+
name: "op"
283+
},
284+
canonicalTarget: {
285+
database: "defaultProject",
286+
schema: "defaultDataset",
287+
name: "op"
288+
},
289+
hermeticity: "NON_HERMETIC",
290+
fileName: "definitions/op.sqlx",
291+
jitCode: `async (jctx) => {
292+
const self = jctx.self ? jctx.self.bind(jctx) : undefined;
293+
const ref = jctx.ref ? jctx.ref.bind(jctx) : undefined;
294+
const resolve = jctx.resolve ? jctx.resolve.bind(jctx) : undefined;
295+
const name = jctx.name ? jctx.name.bind(jctx) : undefined;
296+
const when = jctx.when ? jctx.when.bind(jctx) : undefined;
297+
const incremental = jctx.incremental ? jctx.incremental.bind(jctx) : undefined;
298+
const schema = jctx.schema ? jctx.schema.bind(jctx) : undefined;
299+
const database = jctx.database ? jctx.database.bind(jctx) : undefined;
300+
const adapter = jctx.adapter ? jctx.adapter : undefined;
301+
const data = jctx.data ? jctx.data : undefined;
302+
303+
const foo = "bar";
304+
305+
return {
306+
queries: [
307+
\`
308+
309+
SELECT 1
310+
\`,\`
311+
SELECT 2\`
312+
],
313+
};
314+
}`,
315+
actionDescriptor: {
316+
compilationMode: "ACTION_COMPILATION_MODE_JIT"
317+
}
318+
}
319+
]);
320+
});
258321
});
259322
});

core/actions/table_test.ts

Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -839,5 +839,153 @@ defaultIcebergConfig:
839839
expect(result.compile.compiledGraph.graphErrors.compilationErrors.length).greaterThan(0);
840840
expect(result.compile.compiledGraph.graphErrors.compilationErrors.some(e => e.message.includes("Cannot mix AoT and JiT compilation"))).equals(true);
841841
});
842+
843+
test("jit compilation is supported in sqlx", () => {
844+
const projectDir = tmpDirFixture.createNewTmpDir();
845+
fs.writeFileSync(path.join(projectDir, "workflow_settings.yaml"), VALID_WORKFLOW_SETTINGS_YAML);
846+
fs.mkdirSync(path.join(projectDir, "definitions"));
847+
fs.writeFileSync(
848+
path.join(projectDir, "definitions/table.sqlx"),
849+
`config { type: "table", compilation_mode: "jit" }
850+
js {
851+
const foo = "bar";
852+
}
853+
SELECT 1`
854+
);
855+
856+
const result = runMainInVm(coreExecutionRequestFromPath(projectDir));
857+
858+
expect(result.compile.compiledGraph.graphErrors.compilationErrors).deep.equals([]);
859+
expect(asPlainObject(result.compile.compiledGraph.tables)).deep.equals([
860+
{
861+
target: {
862+
database: "defaultProject",
863+
schema: "defaultDataset",
864+
name: "table"
865+
},
866+
canonicalTarget: {
867+
database: "defaultProject",
868+
schema: "defaultDataset",
869+
name: "table"
870+
},
871+
type: "table",
872+
enumType: "TABLE",
873+
disabled: false,
874+
hermeticity: "NON_HERMETIC",
875+
fileName: "definitions/table.sqlx",
876+
jitCode: `async (jctx) => {
877+
const self = jctx.self ? jctx.self.bind(jctx) : undefined;
878+
const ref = jctx.ref ? jctx.ref.bind(jctx) : undefined;
879+
const resolve = jctx.resolve ? jctx.resolve.bind(jctx) : undefined;
880+
const name = jctx.name ? jctx.name.bind(jctx) : undefined;
881+
const when = jctx.when ? jctx.when.bind(jctx) : undefined;
882+
const incremental = jctx.incremental ? jctx.incremental.bind(jctx) : undefined;
883+
const schema = jctx.schema ? jctx.schema.bind(jctx) : undefined;
884+
const database = jctx.database ? jctx.database.bind(jctx) : undefined;
885+
const adapter = jctx.adapter ? jctx.adapter : undefined;
886+
const data = jctx.data ? jctx.data : undefined;
887+
888+
const foo = "bar";
889+
890+
return {
891+
query: (
892+
\`
893+
894+
SELECT 1\`
895+
),
896+
postOps: (
897+
undefined
898+
),
899+
preOps: (
900+
undefined
901+
),
902+
};
903+
}`,
904+
actionDescriptor: {
905+
compilationMode: "ACTION_COMPILATION_MODE_JIT"
906+
}
907+
}
908+
]);
909+
});
910+
911+
test("jit compilation with pre/post ops is supported in sqlx", () => {
912+
const projectDir = tmpDirFixture.createNewTmpDir();
913+
fs.writeFileSync(path.join(projectDir, "workflow_settings.yaml"), VALID_WORKFLOW_SETTINGS_YAML);
914+
fs.mkdirSync(path.join(projectDir, "definitions"));
915+
fs.writeFileSync(
916+
path.join(projectDir, "definitions/table.sqlx"),
917+
`config { type: "table", compilation_mode: "jit" }
918+
js {
919+
const foo = "bar";
920+
}
921+
SELECT 1
922+
pre_operations {
923+
SELECT 10;
924+
}
925+
post_operations {
926+
SELECT 20;
927+
}`
928+
);
929+
930+
const result = runMainInVm(coreExecutionRequestFromPath(projectDir));
931+
932+
expect(result.compile.compiledGraph.graphErrors.compilationErrors).deep.equals([]);
933+
expect(asPlainObject(result.compile.compiledGraph.tables)).deep.equals([
934+
{
935+
target: {
936+
database: "defaultProject",
937+
schema: "defaultDataset",
938+
name: "table"
939+
},
940+
canonicalTarget: {
941+
database: "defaultProject",
942+
schema: "defaultDataset",
943+
name: "table"
944+
},
945+
type: "table",
946+
enumType: "TABLE",
947+
disabled: false,
948+
hermeticity: "NON_HERMETIC",
949+
fileName: "definitions/table.sqlx",
950+
jitCode: `async (jctx) => {
951+
const self = jctx.self ? jctx.self.bind(jctx) : undefined;
952+
const ref = jctx.ref ? jctx.ref.bind(jctx) : undefined;
953+
const resolve = jctx.resolve ? jctx.resolve.bind(jctx) : undefined;
954+
const name = jctx.name ? jctx.name.bind(jctx) : undefined;
955+
const when = jctx.when ? jctx.when.bind(jctx) : undefined;
956+
const incremental = jctx.incremental ? jctx.incremental.bind(jctx) : undefined;
957+
const schema = jctx.schema ? jctx.schema.bind(jctx) : undefined;
958+
const database = jctx.database ? jctx.database.bind(jctx) : undefined;
959+
const adapter = jctx.adapter ? jctx.adapter : undefined;
960+
const data = jctx.data ? jctx.data : undefined;
961+
962+
const foo = "bar";
963+
964+
return {
965+
query: (
966+
\`
967+
968+
SELECT 1
969+
970+
\`
971+
),
972+
postOps: (
973+
[\`
974+
SELECT 20;
975+
\`]
976+
),
977+
preOps: (
978+
[\`
979+
SELECT 10;
980+
\`]
981+
),
982+
};
983+
}`,
984+
actionDescriptor: {
985+
compilationMode: "ACTION_COMPILATION_MODE_JIT"
986+
}
987+
}
988+
]);
989+
});
842990
});
843991
});

0 commit comments

Comments
 (0)