Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
6642a03
ISSUE-2103 Handle trailing and trailing statement comments
spatel11 Mar 9, 2026
a71284a
Merge branch 'main' into iss-2103
spatel11 May 12, 2026
4fb904f
Merge branch 'main' into iss-2103
spatel11 May 20, 2026
237a5ee
Bump vm2 from 3.10.2 to 3.11.3 (#2168)
dependabot[bot] May 21, 2026
60b69bf
Bump DF_VERSION from 3.0.56 to 3.0.57 (#2173)
rafal-hawrylak May 22, 2026
f1bfb2e
Support onSchemaChange for incremental tables (#2101)
SuchodolskiEdvin May 25, 2026
c8d5d6a
feat: implement .jitCode() support for Assertion actions (#2170)
rafal-hawrylak May 26, 2026
bbbc192
fix: Resolve presubmit failure introduced by PR #2101
SuchodolskiEdvin May 26, 2026
62b18ba
Bump DF_VERSION from 3.0.57 to 3.0.58 (#2176)
rafal-hawrylak May 26, 2026
8d43204
Guard workflow_settings.yaml and dataform.json require with existence…
rafal-hawrylak May 26, 2026
3226940
Refactor CompileChildProcess to use BaseWorker (#2179)
rafal-hawrylak May 28, 2026
b50f212
Rename worker timeout error to "Compilation timed out" (#2186)
rafal-hawrylak May 28, 2026
f2c8431
Extract task creation into executionSql helpers (#2180)
rafal-hawrylak May 28, 2026
a2f8d70
Add JiT compilation support for assertion actions (#2193)
rafal-hawrylak Jun 2, 2026
4ad875e
Fix caller-file error (#2177) and enforce Core/CLI version match (#2191)
rafal-hawrylak Jun 2, 2026
00b33a3
Raise default compile timeout to 60s and improve timeout error messag…
rafal-hawrylak Jun 2, 2026
c8f0b29
Bump DF_VERSION from 3.0.58 to 3.0.59 (#2194)
rafal-hawrylak Jun 2, 2026
5ab292f
Bump vm2 from 3.11.3 to 3.11.4 (#2188)
dependabot[bot] Jun 4, 2026
97a4c22
Extract BigQueryClientProvider for injectable BQ clients (#2181)
rafal-hawrylak Jun 5, 2026
1730f58
Bump protobufjs from 7.5.5 to 7.5.8 (#2172)
dependabot[bot] Jun 7, 2026
c6c226c
Add go_package option to db_adapter.proto and jit.proto (#2197)
kolina Jun 8, 2026
320af99
Migrate to bazel 7.3.2 (#2187)
ikholopov-omni Jun 16, 2026
9d9f48b
Update gcloud to 572.0.0 (#2207)
ikholopov-omni Jun 17, 2026
c4af15e
Add metadata field to AssertionConfig (#2208)
rafal-hawrylak Jun 17, 2026
5afdeb4
Bump DF_VERSION from 3.0.59 to 3.0.60 (#2209)
rafal-hawrylak Jun 23, 2026
45a6aba
Ignore trailing positional arguments in the global flag parser (#2199)
aicayzer Jun 23, 2026
bcd3716
Bump protobufjs-cli from 1.0.0 to 1.3.3 (#2202)
dependabot[bot] Jun 23, 2026
a8cd8f3
Bump js-yaml from 4.1.1 to 4.2.0 (#2205)
dependabot[bot] Jun 25, 2026
2276440
feat: add getContents() for reading external markdown files into tabl…
AmmanuelT Jun 26, 2026
3da6b13
Bump protobufjs from 7.5.8 to 7.6.3 (#2204)
dependabot[bot] Jun 27, 2026
427ebba
feat(gcloud): support client certificate environment in gcloud action…
kolina Jun 27, 2026
e7444f9
Prevent .sqlx files in actions.yaml configs with a clear error (#2189)
aicayzer Jun 27, 2026
cce5b9f
Bump tmp from 0.2.4 to 0.2.7 (#2183)
dependabot[bot] Jun 27, 2026
6da16ea
Bump @tootallnate/once from 2.0.0 to 2.0.1 (#2171)
dependabot[bot] Jun 27, 2026
7b4c045
Bump fast-uri from 3.0.6 to 3.1.2 (#2161)
dependabot[bot] Jun 27, 2026
ed868f0
Merge branch 'main' into iss-2103
spatel11 Jul 8, 2026
aaefb9d
remove extra utils_test.ts from api build
spatel11 Jul 8, 2026
6b3fd34
allow pbts command to run on mac
spatel11 Jul 8, 2026
5c4d7c5
refactor concatenateQueries to be a bit more readable
spatel11 Jul 8, 2026
60bfef3
update on_schema_change tests to reflect the new format
spatel11 Jul 8, 2026
585f786
update format for api spec
spatel11 Jul 8, 2026
3c7bbbc
replace drop table in statement comment test because it was causing a…
spatel11 Jul 8, 2026
59a5ebd
add new tests for comments within a query
spatel11 Jul 8, 2026
4ceac97
update test count in bigquery spec
spatel11 Jul 8, 2026
c19998f
multi line comment tests
spatel11 Jul 8, 2026
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
3 changes: 2 additions & 1 deletion cli/api/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,11 @@ node_modules(
ts_test_suite(
name = "tests",
srcs = [
"tasks_test.ts",
"utils_test.ts",
"commands/jit/rpc_test.ts",
"dbadapters/bigquery_test.ts",
"execution_sql_test.ts",
"utils_test.ts",
],
data = [
":node_modules",
Expand Down
53 changes: 45 additions & 8 deletions cli/api/dbadapters/tasks.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,53 @@
import { dataform } from "df/protos/ts";

function formatStatement(
statement: string,
isLast: boolean,
modifier?: (mod: string) => string
) {
// Only treat a comment as trailing if it lives on the statement's last line.
// Searching from the last newline avoids misreading an interior comment (e.g.
// inside a multi-line procedure body) as a trailing comment.
const lastLineStart = statement.lastIndexOf("\n") + 1;
const commentIndex = statement.indexOf("--", lastLineStart);

let code: string;
let comment: string;

if (commentIndex === 0) {
code = "";
comment = statement;
} else if (commentIndex > 0) {
code = statement.substring(0, commentIndex).trimEnd();
comment = statement.substring(commentIndex);
} else {
code = statement;
comment = "";
}

if (modifier && code.length > 0) {
code = modifier(code);
}

if (!isLast && code.length > 0 && !code.endsWith(";")) {
code = code + ";";
}

if (code.length > 0 && comment.length > 0) {
return code + " " + comment;
}
return code || comment;
}

export function concatenateQueries(statements: string[], modifier?: (mod: string) => string) {
Comment thread
kolina marked this conversation as resolved.
return statements
const processed = statements
.filter(statement => !!statement)
.map(statement => statement.trim())
.map(statement =>
statement.length > 0 && statement.charAt(statement.length - 1) === ";"
? statement.substring(0, statement.length - 1)
: statement
)
.map(statement => (!!modifier ? modifier(statement) : statement))
.join("\n;\n");
.filter(statement => statement.length > 0);
const formattedStatements = processed.map((statement, index) =>
formatStatement(statement, index === processed.length - 1, modifier)
);
return formattedStatements.join("\n");
}

export class Tasks {
Expand Down
6 changes: 2 additions & 4 deletions cli/api/goldens/on_schema_change_extend.sql
Original file line number Diff line number Diff line change
Expand Up @@ -61,17 +61,15 @@ END IF;
-- Cleanup temporary tables.
DROP TABLE IF EXISTS `project-id.dataset-id.incremental_on_schema_change_df_temp_test_uuid_empty`;

END
;
END;
BEGIN
CALL `project-id.dataset-id.df_osc_test_uuid`();
EXCEPTION WHEN ERROR THEN
DROP TABLE IF EXISTS `project-id.dataset-id.incremental_on_schema_change_df_temp_test_uuid_empty`;
DROP PROCEDURE IF EXISTS `project-id.dataset-id.df_osc_test_uuid`;
RAISE;
END;
DROP PROCEDURE IF EXISTS `project-id.dataset-id.df_osc_test_uuid`
;
DROP PROCEDURE IF EXISTS `project-id.dataset-id.df_osc_test_uuid`;
insert into `project-id.dataset-id.incremental_on_schema_change`
(`id`,`field1`)
select `id`,`field1`
Expand Down
6 changes: 2 additions & 4 deletions cli/api/goldens/on_schema_change_fail.sql
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,15 @@ END IF;
-- Cleanup temporary tables.
DROP TABLE IF EXISTS `project-id.dataset-id.incremental_on_schema_change_df_temp_test_uuid_empty`;

END
;
END;
BEGIN
CALL `project-id.dataset-id.df_osc_test_uuid`();
EXCEPTION WHEN ERROR THEN
DROP TABLE IF EXISTS `project-id.dataset-id.incremental_on_schema_change_df_temp_test_uuid_empty`;
DROP PROCEDURE IF EXISTS `project-id.dataset-id.df_osc_test_uuid`;
RAISE;
END;
DROP PROCEDURE IF EXISTS `project-id.dataset-id.df_osc_test_uuid`
;
DROP PROCEDURE IF EXISTS `project-id.dataset-id.df_osc_test_uuid`;
insert into `project-id.dataset-id.incremental_on_schema_change`
(`id`,`field1`)
select `id`,`field1`
Expand Down
6 changes: 2 additions & 4 deletions cli/api/goldens/on_schema_change_synchronize.sql
Original file line number Diff line number Diff line change
Expand Up @@ -76,17 +76,15 @@ END IF;
-- Cleanup temporary tables.
DROP TABLE IF EXISTS `project-id.dataset-id.incremental_on_schema_change_df_temp_test_uuid_empty`;

END
;
END;
BEGIN
CALL `project-id.dataset-id.df_osc_test_uuid`();
EXCEPTION WHEN ERROR THEN
DROP TABLE IF EXISTS `project-id.dataset-id.incremental_on_schema_change_df_temp_test_uuid_empty`;
DROP PROCEDURE IF EXISTS `project-id.dataset-id.df_osc_test_uuid`;
RAISE;
END;
DROP PROCEDURE IF EXISTS `project-id.dataset-id.df_osc_test_uuid`
;
DROP PROCEDURE IF EXISTS `project-id.dataset-id.df_osc_test_uuid`;
merge `project-id.dataset-id.incremental_on_schema_change` T
using (select 1 as id, 'a' as field1, 'new' as field2
) S
Expand Down
89 changes: 89 additions & 0 deletions cli/api/tasks_test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
import { expect } from "chai";

import { concatenateQueries } from "df/cli/api/dbadapters/tasks";
import { suite, test } from "df/testing";

suite("concatenateQueries", () => {
test("adds semicolons to non-last statements and joins with newlines", () => {
expect(concatenateQueries(["SELECT 1", "SELECT 2"])).deep.equals(
"SELECT 1;\nSELECT 2"
);
});

test("does not add semicolon to the last statement", () => {
expect(concatenateQueries(["SELECT 1", "SELECT 2", "SELECT 3"])).deep.equals(
"SELECT 1;\nSELECT 2;\nSELECT 3"
);
});

test("preserves existing semicolons on non-last statements", () => {
expect(concatenateQueries(["SELECT 1;", "SELECT 2"])).deep.equals(
"SELECT 1;\nSELECT 2"
);
});

test("preserves existing semicolons on last statement", () => {
expect(concatenateQueries(["SELECT 1;", "SELECT 2;"])).deep.equals(
"SELECT 1;\nSELECT 2;"
);
});

test("adds semicolon before trailing comment if necessary, verifies fix for https://github.com/dataform-co/dataform/issues/1231", () => {
expect(concatenateQueries(["SELECT 1 -- blah", "drop table foo; -- baz", "SELECT 2"])).deep.equals(
"SELECT 1; -- blah\ndrop table foo; -- baz\nSELECT 2"
);
});

test("preserves comment-only lines, verifies fix for https://github.com/dataform-co/dataform/issues/2103", () => {
expect(concatenateQueries(["SELECT 1;", "--drop table foo", "SELECT 2", "--baz"])).deep.equals(
"SELECT 1;\n--drop table foo\nSELECT 2;\n--baz"
);
});

test("preserves single line comments within a query", () => {
expect(concatenateQueries(["SELECT 1\n--test\nFROM UNNEST([]);"])).deep.equals(
"SELECT 1\n--test\nFROM UNNEST([]);"
);
});

test("preserves multi line comments within a query", () => {
expect(concatenateQueries(["SELECT 1\n\*multi\nline\ncomment\n*/\nFROM UNNEST([]);"])).deep.equals(
"SELECT 1\n\*multi\nline\ncomment\n*/\nFROM UNNEST([]);"
);
});

test("trims whitespace from statements", () => {
expect(concatenateQueries([" SELECT 1 ", " SELECT 2 ", " SELECT 3 -- blah"])).deep.equals(
"SELECT 1;\nSELECT 2;\nSELECT 3 -- blah"
);
});

test("filters out empty and falsy statements", () => {
expect(concatenateQueries(["SELECT 1", "", "SELECT 2"])).deep.equals(
"SELECT 1;\nSELECT 2"
);
expect(concatenateQueries(["SELECT 1", undefined, "SELECT 2"])).deep.equals(
"SELECT 1;\nSELECT 2"
);
});

test("returns empty string for empty input", () => {
expect(concatenateQueries([])).deep.equals("");
});

test("returns single statement without semicolon", () => {
expect(concatenateQueries(["SELECT 1"])).deep.equals("SELECT 1");
});

test("applies modifier to code portion of each statement", () => {
expect(
concatenateQueries(["SELECT 1", "SELECT 2"], stmt => `(${stmt})`)
).deep.equals("(SELECT 1);\n(SELECT 2)");
});

test("applies modifier only to code portion, not comment", () => {
expect(
concatenateQueries(["SELECT 1 --comment", "SELECT 2"], stmt => `(${stmt})`)
).deep.equals("(SELECT 1); --comment\n(SELECT 2)");
});
});
4 changes: 2 additions & 2 deletions tests/api/api.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ suite("@dataform/api", () => {
expect(action.tasks).eql([
dataform.ExecutionTask.create({
type: "statement",
statement: "preOp\n;\ncreate or replace table `schema.a` as foo\n;\npostOp"
statement: "preOp;\ncreate or replace table `schema.a` as foo;\npostOp"
})
]);
});
Expand All @@ -242,7 +242,7 @@ suite("@dataform/api", () => {
dataform.ExecutionTask.create({
type: "statement",
statement:
"incremental preOp\n;\ndrop view if exists `schema.a`\n;\ninsert into `schema.a`\t\n()\t\nselect \t\nfrom (incremental foo) as insertions\n;\nincremental postOp"
"incremental preOp;\ndrop view if exists `schema.a`;\ninsert into `schema.a`\t\n()\t\nselect \t\nfrom (incremental foo) as insertions;\nincremental postOp"
})
]);
});
Expand Down
6 changes: 3 additions & 3 deletions tests/integration/bigquery.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ suite("@dataform/integration/bigquery", { parallel: true }, ({ before, after })
const executedGraph = await dfapi.run(dbadapter, executionGraph).result();

const actionMap = keyBy(executedGraph.actions, v => targetAsReadableString(v.target));
expect(Object.keys(actionMap).length).eql(17);
expect(Object.keys(actionMap).length).eql(20);

// Check the status of action execution.
const expectedFailedActions = [
Expand Down Expand Up @@ -384,7 +384,7 @@ suite("@dataform/integration/bigquery", { parallel: true }, ({ before, after })
const bqadapter = new ExecutionSql({ warehouse: "bigquery" }, "1.4.8");

const refresh = bqadapter.publishTasks(table, { fullRefresh: true }, { fields: [] }).build();
const splitRefresh = refresh[0].statement.split("\n;\n");
const splitRefresh = refresh[0].statement.split("\n");
expect([...splitRefresh.slice(0, 2), ...splitRefresh.slice(-2)]).to.eql([
...table.preOps,
...table.postOps
Expand All @@ -394,7 +394,7 @@ suite("@dataform/integration/bigquery", { parallel: true }, ({ before, after })
.publishTasks(table, { fullRefresh: false }, { fields: [] })
.build();

const splitIncrement = increment[0].statement.split("\n;\n");
const splitIncrement = increment[0].statement.split("\n");
expect([...splitIncrement.slice(0, 2), ...splitIncrement.slice(-2)]).to.eql([
...table.preOps,
...table.postOps
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
config {
type: "table",
description: "Verifies fix for https://github.com/dataform-co/dataform/issues/1231"
}

post_operations {
select *
-- single line comment
/*
multi
line
comment
*/
from ${self()}
}

select 1 as col1
-- single line comment
/*
multi
line
comment
*/
FROM UNNEST([])
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
config {
"type": "table",
"description": "Verifies fix for https://github.com/dataform-co/dataform/issues/2103"
}

SELECT 1 AS foo

pre_operations {

DECLARE bar DATE DEFAULT DATE_TRUNC(CURRENT_DATE(), WEEK(MONDAY));

-- DECLARE bar DATE DEFAULT DATE_TRUNC(DATE('2026-01-01'), WEEK(MONDAY))
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
config {
type: "table",
schema: "test",
name: "testtab",
description: "Verifies fix for https://github.com/dataform-co/dataform/issues/1231"
}

post_operations {
select * from ${self()}
}

select 1 as col1 -- test comment
2 changes: 1 addition & 1 deletion tools/ts_proto_library.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def _run_pbts(actions, executable, js_file):
#
# Run pbts and then patch 'import Long = require("long");' to 'import Long from "long";'
# to avoid syntax errors in older rollup-plugin-dts.
command = "{pbts} --out {out} {input} && sed -i 's/import Long = require(\"long\");/import Long from \"long\";/g' {out}".format(
command = "{pbts} --out {out} {input} && sed 's/import Long = require(\"long\");/import Long from \"long\";/g' {out} > {out}.tmp && mv {out}.tmp {out}".format(
Comment thread
kolina marked this conversation as resolved.
pbts = executable._pbts.path,
out = ts_file.path,
input = js_file.path
Expand Down
Loading