Skip to content

Commit

Permalink
Fix issue #357 (P1) (#368)
Browse files Browse the repository at this point in the history
* Fix issue #357 (P1)

* Address Ben's comments
  • Loading branch information
kennethkenneth authored Aug 14, 2019
1 parent 0ffcc88 commit b834ea6
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 2 deletions.
8 changes: 8 additions & 0 deletions core/assertion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export interface AConfig {
dependencies?: string | string[];
tags?: string[];
description?: string;
schema?: string;
}

export class Assertion {
Expand All @@ -28,6 +29,9 @@ export class Assertion {
if (config.description) {
this.description(config.description);
}
if (config.schema) {
this.schema(config.schema);
}
return this;
}

Expand Down Expand Up @@ -61,6 +65,10 @@ export class Assertion {
return this;
}

public schema(schema: string) {
this.proto.target = this.session.target(schema, this.session.config.assertionSchema);
}

public compile() {
const context = new AssertionContext(this);

Expand Down
8 changes: 8 additions & 0 deletions core/operation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export interface OConfig {
description?: string;
columns?: IColumnsDescriptor;
hasOutput?: boolean;
schema?: string;
}

export class Operation {
Expand Down Expand Up @@ -36,6 +37,9 @@ export class Operation {
if (config.columns) {
this.columns(config.columns);
}
if (config.schema) {
this.schema(config.schema);
}
return this;
}

Expand Down Expand Up @@ -85,6 +89,10 @@ export class Operation {
return this;
}

public schema(schema: string) {
this.proto.target = this.session.target(schema);
}

public compile() {
if (
this.proto.actionDescriptor &&
Expand Down
1 change: 0 additions & 1 deletion core/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ interface IActionProto {

interface ISqlxConfig extends table.TConfig, AConfig, OConfig, test.TConfig {
type: "view" | "table" | "inline" | "incremental" | "assertion" | "operations" | "test";
schema?: string;
name: string;
}

Expand Down
8 changes: 8 additions & 0 deletions core/table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export interface TConfig {
redshift?: dataform.IRedshiftOptions;
bigquery?: dataform.IBigQueryOptions;
sqldatawarehouse?: dataform.ISQLDataWarehouseOptions;
schema?: string;
}

export class Table {
Expand Down Expand Up @@ -93,6 +94,9 @@ export class Table {
if (config.columns) {
this.columns(config.columns);
}
if (config.schema) {
this.schema(config.schema);
}

return this;
}
Expand Down Expand Up @@ -181,6 +185,10 @@ export class Table {
return this;
}

public schema(schema: string) {
this.proto.target = this.session.target(schema);
}

public compile() {
const context = new TableContext(this);

Expand Down
12 changes: 12 additions & 0 deletions tests/core/core.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,18 @@ describe("@dataform/core", () => {
});
expect(t.preOps).deep.equals(["pre_op"]);
expect(t.postOps).deep.equals(["post_op"]);

const t2 = session
.publish("my_table", {
type: "table",
schema: "test_schema"
})
.query(_ => "SELECT 1 as one")
.compile();
expect(t2.name).equals("my_table");
expect((t2.target.name = "my_table"));
expect((t2.target.schema = "test_schema"));
expect(t2.type).equals("table");
});

it("config_context", () => {
Expand Down
2 changes: 1 addition & 1 deletion version.bzl
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# NOTE: If you change the format of this line, you must change the bash command
# in /scripts/publish to extract the version string correctly.
DF_VERSION = "1.2.2"
DF_VERSION = "1.2.3"

0 comments on commit b834ea6

Please sign in to comment.