|
1 | 1 | import { expect } from "chai"; |
| 2 | +import Long from "long"; |
2 | 3 |
|
3 | 4 | import { jitCompile } from "df/core/jit_compiler"; |
4 | 5 | import { dataform } from "df/protos/ts"; |
@@ -121,20 +122,54 @@ suite("jit_compiler", () => { |
121 | 122 |
|
122 | 123 | suite("jitCompileIncrementalTable", () => { |
123 | 124 | test("compiles incremental table", async () => { |
124 | | - const request = dataform.JitCompilationRequest.create({ |
| 125 | + const request = dataform.JitCompilationRequest.create({ |
125 | 126 | jitCode: `async (ctx) => { |
126 | 127 | if (ctx.incremental()) { |
127 | 128 | return { query: "SELECT INC" }; |
128 | 129 | } |
129 | 130 | return { query: "SELECT REG" }; |
130 | 131 | }`, |
131 | 132 | target, |
132 | | - jitData: {}, |
133 | | - compilationTargetType: dataform.JitCompilationTargetType.JIT_COMPILATION_TARGET_TYPE_INCREMENTAL_TABLE, |
| 133 | + jitData: {}, |
| 134 | + compilationTargetType: dataform.JitCompilationTargetType.JIT_COMPILATION_TARGET_TYPE_INCREMENTAL_TABLE, |
134 | 135 | }); |
135 | 136 | const result = await jitCompile(request, rpcCallback); |
136 | 137 | expect(result.incrementalTable.incremental?.query).to.equal("SELECT INC"); |
137 | 138 | expect(result.incrementalTable.regular?.query).to.equal("SELECT REG"); |
138 | 139 | }); |
139 | 140 | }); |
| 141 | + |
| 142 | + suite("jitCompileContext", () => { |
| 143 | + test("can reference self and other tables", async () => { |
| 144 | + const request = dataform.JitCompilationRequest.create({ |
| 145 | + jitCode: `async (jctx) => \`$\{jctx.self()\}\n$\{jctx.ref('other')\}\``, |
| 146 | + target, |
| 147 | + jitData: {}, |
| 148 | + dependencies: [dataform.Target.create({ |
| 149 | + database: "db", |
| 150 | + schema: "schema", |
| 151 | + name: "other", |
| 152 | + })], |
| 153 | + compilationTargetType: dataform.JitCompilationTargetType.JIT_COMPILATION_TARGET_TYPE_TABLE, |
| 154 | + |
| 155 | + }); |
| 156 | + const result = await jitCompile(request, rpcCallback); |
| 157 | + expect(result.table.query).to.equal("`db.schema.name`\n`db.schema.other`"); |
| 158 | + }); |
| 159 | + |
| 160 | + test("can reference execution info data", async () => { |
| 161 | + const request = dataform.JitCompilationRequest.create({ |
| 162 | + jitCode: `async (jctx) => \`$\{jctx.executionData.executionStartTime.seconds\}\n$\{jctx.executionData.executionId\}\``, |
| 163 | + target, |
| 164 | + jitData: {}, |
| 165 | + compilationTargetType: dataform.JitCompilationTargetType.JIT_COMPILATION_TARGET_TYPE_TABLE, |
| 166 | + executionData: { |
| 167 | + executionId: "test-id", |
| 168 | + executionStartTime: {seconds: Long.fromNumber(1774974514), nanos: 481}, |
| 169 | + } |
| 170 | + }); |
| 171 | + const result = await jitCompile(request, rpcCallback); |
| 172 | + expect(result.table.query).to.equal("1774974514\ntest-id"); |
| 173 | + }); |
| 174 | + }); |
140 | 175 | }); |
0 commit comments