Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge main to v3 #1563

Merged
merged 7 commits into from Nov 1, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion cli/api/BUILD
Expand Up @@ -18,7 +18,7 @@ ts_library(
"//core",
"//protos:ts",
"//cli/vm:compile_loader",
"//sqlx",
"//sqlx:lexer",
"//cli/vm:vm",
"@npm//@google-cloud/bigquery",
"@npm//@types/glob",
Expand Down
2 changes: 1 addition & 1 deletion core/BUILD
Expand Up @@ -26,7 +26,7 @@ ts_library(
"//common/protos",
"//common/strings",
"//protos:ts",
"//sqlx:sqlx",
"//sqlx:lexer",
"@npm//@types/node",
"@npm//@types/semver",
"@npm//protobufjs",
Expand Down
19 changes: 14 additions & 5 deletions core/compilers.ts
Expand Up @@ -32,7 +32,7 @@ function compileTableSql(code: string, path: string) {
);

return `
publish("${utils.baseFilename(path)}").query(ctx => {
publish("${utils.getEscapedFileName(path)}").query(ctx => {
${functionsBindings.join("\n")}
${js}
return \`${sql}\`;
Expand All @@ -46,7 +46,7 @@ function compileOperationSql(code: string, path: string) {
);

return `
operate("${utils.baseFilename(path)}").queries(ctx => {
operate("${utils.getEscapedFileName(path)}").queries(ctx => {
${functionsBindings.join("\n")}
${js}
return \`${sql}\`.split("\\n---\\n");
Expand All @@ -60,7 +60,7 @@ function compileAssertionSql(code: string, path: string) {
);

return `
assert("${utils.baseFilename(path)}").query(ctx => {
assert("${utils.getEscapedFileName(path)}").query(ctx => {
${functionsBindings.join("\n")}
${js}
return \`${sql}\`;
Expand Down Expand Up @@ -122,13 +122,22 @@ function compileSqlx(rootNode: SyntaxTreeNode, path: string) {
rootNode
);

const contextFunctions = ["self", "ref", "resolve", "name", "when", "incremental", "schema", "database"]
const contextFunctions = [
"self",
"ref",
"resolve",
"name",
"when",
"incremental",
"schema",
"database"
]
.map(name => `const ${name} = ctx.${name} ? ctx.${name}.bind(ctx) : undefined;`)
.join("\n");

return `dataform.sqlxAction({
sqlxConfig: {
name: "${utils.baseFilename(path)}",
name: "${utils.getEscapedFileName(path)}",
type: "operations",
...${config || "{}"}
},
Expand Down
5 changes: 5 additions & 0 deletions core/utils.ts
Expand Up @@ -32,6 +32,10 @@ export function baseFilename(fullPath: string) {
.split(".")[0];
}

export function getEscapedFileName(path: string) {
return baseFilename(path).replace(/\\/g, '\\\\')
}

export function matchPatterns(patterns: string[], values: string[]) {
const fullyQualifiedActions: string[] = [];
patterns.forEach(pattern => {
Expand Down Expand Up @@ -262,6 +266,7 @@ export function tableTypeEnumToString(enumType: dataform.TableType) {
return dataform.TableType[enumType].toLowerCase();
}


export function setOrValidateTableEnumType(table: dataform.ITable) {
let enumTypeFromStr: dataform.TableType | null = null;
if (table.type !== "" && table.type !== undefined) {
Expand Down
33 changes: 30 additions & 3 deletions examples/BUILD
@@ -1,8 +1,35 @@
package(default_visibility = ["//visibility:public"])
load("//testing:index.bzl", "ts_test_suite")
load("//tools:node_modules.bzl", "node_modules")

package(default_visibility = ["//visibility:private"])

filegroup(
name = "examples",
name = "all_projects",
srcs = glob([
"**/*.*",
]),
], exclude = ["BUILD", "examples_test.ts"]),
)

ts_test_suite(
name = "tests",
srcs = ["examples_test.ts"],
data = [
":all_projects",
":node_modules",
],
deps = [
"//cli/api",
"//testing",
"//tests/utils",
"@npm//@types/chai",
"@npm//chai",
],
)

node_modules(
name = "node_modules",
deps = [
"//packages/@dataform/core:package_tar",
],
for_subdirectory = "stackoverflow_reporter",
)
6 changes: 0 additions & 6 deletions examples/backwards_compatibility/package.json

This file was deleted.

6 changes: 0 additions & 6 deletions examples/common_v2/package.json

This file was deleted.

11 changes: 11 additions & 0 deletions examples/examples_test.ts
@@ -0,0 +1,11 @@
import { expect } from "chai";

import { compile } from "df/cli/api";
import { suite, test } from "df/testing";

suite("examples", () => {
test("example Dataform projects compile", async () => {
const graph = await compile({ projectDir: "examples/stackoverflow_reporter" });
expect(graph.graphErrors.compilationErrors.length).equals(0);
});
});
6 changes: 0 additions & 6 deletions examples/formatter/dataform.json

This file was deleted.

13 changes: 0 additions & 13 deletions examples/formatter/definitions/bigquery_regexps.sqlx

This file was deleted.

35 changes: 0 additions & 35 deletions examples/formatter/definitions/comments.sqlx

This file was deleted.

8 changes: 0 additions & 8 deletions examples/formatter/definitions/dollar_regex.sqlx

This file was deleted.

25 changes: 0 additions & 25 deletions examples/formatter/definitions/multiple_queries.sqlx

This file was deleted.

3 changes: 0 additions & 3 deletions examples/formatter/definitions/named_arguments.sqlx

This file was deleted.

5 changes: 0 additions & 5 deletions examples/formatter/definitions/qualify.sqlx

This file was deleted.

1 change: 0 additions & 1 deletion examples/formatter/definitions/regex.sqlx

This file was deleted.

11 changes: 0 additions & 11 deletions examples/formatter/definitions/simple.sqlx

This file was deleted.

24 changes: 0 additions & 24 deletions examples/formatter/definitions/triple_quoted.sqlx

This file was deleted.

6 changes: 0 additions & 6 deletions examples/formatter/package.json

This file was deleted.

17 changes: 0 additions & 17 deletions examples/never_finishes_compiling/BUILD

This file was deleted.

6 changes: 0 additions & 6 deletions examples/never_finishes_compiling/package.json

This file was deleted.

7 changes: 7 additions & 0 deletions examples/stackoverflow_reporter/dataform.json
@@ -0,0 +1,7 @@
{
"defaultSchema": "dataform",
"assertionSchema": "dataform_assertions",
"warehouse": "bigquery",
"defaultDatabase": "dataform-demos",
"defaultLocation": "us"
}
@@ -0,0 +1,36 @@
config {
type: "table",
schema: "reporting",
tags: ["daily"],
bigquery: {
partitionBy: "date(created_at)"
},
description: "Combine both questions and answers into a single posts_all table",
assertions: {
uniqueKey: ["post_id"]
}
}

select
post_id,
created_at,
type,
title,
body,
owner_user_id,
parent_id
from
${ref("stg_posts_answers")}

union all

select
post_id,
created_at,
type,
title,
body,
owner_user_id,
parent_id
from
${ref("stg_posts_questions")}