Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion core/actions/assertion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ interface ILegacyAssertionConfig extends dataform.ActionConfig.AssertionConfig {
export type AContextable<T> = T | ((ctx: AssertionContext) => T);

/** JiT compilation stage result for assertions. */
export type JitAssertionResult = string;
export type JitAssertionResult = string | { query: string };

/**
* An assertion is a data quality test query that finds rows that violate one or more conditions
Expand Down
4 changes: 3 additions & 1 deletion core/jit_compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ function jitCompileAssertion(
const jctx: JitContext<IActionContext> = new SqlActionJitContext(
adapter, request,
);
return mainBody(jctx).then(query => dataform.JitAssertionResult.create({ query }));
return mainBody(jctx).then(result =>
typeof result === "string" ? { query: result } : result
);
}

function jitCompileIncrementalTable(
Expand Down
23 changes: 23 additions & 0 deletions core/jit_compiler_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,29 @@ suite("jit_compiler", () => {
const result = await jitCompile(request, rpcCallback);
expect(result.assertion.query).to.equal("SELECT * FROM `db.schema.other` WHERE invalid");
});

test("compiles assertion returning bare object", async () => {
const request = dataform.JitCompilationRequest.create({
jitCode: `async (ctx) => ({ query: "SELECT * FROM t WHERE invalid" })`,
target,
jitData: {},
compilationTargetType: dataform.JitCompilationTargetType.JIT_COMPILATION_TARGET_TYPE_ASSERTION,
});
const result = await jitCompile(request, rpcCallback);
expect(result.assertion.query).to.equal("SELECT * FROM t WHERE invalid");
});

test("compiles assertion returning object with extra fields", async () => {
const request = dataform.JitCompilationRequest.create({
jitCode:
`async (ctx) => ({ query: "SELECT * FROM t WHERE invalid", preOps: [], postOps: [] })`,
target,
jitData: {},
compilationTargetType: dataform.JitCompilationTargetType.JIT_COMPILATION_TARGET_TYPE_ASSERTION,
});
const result = await jitCompile(request, rpcCallback);
expect(result.assertion.query).to.equal("SELECT * FROM t WHERE invalid");
});
});

suite("jitCompileIncrementalTable", () => {
Expand Down
Loading