Skip to content

Latest commit

 

History

History
398 lines (252 loc) · 9.52 KB

File metadata and controls

398 lines (252 loc) · 9.52 KB

Dataform Javascript API ReferenceGlobals"core/actions/view"View

Class: View

Views are virtualised tables. They are useful for creating a new structured table without having to copy the original data to it, which can result in significant cost savings for avoiding data processing and storage.

You can create views in the following ways. Available config options are defined in ViewConfig, and are shared across all the following ways of creating tables.

Using a SQLX file:

-- definitions/name.sqlx
config {
  type: "view"
}
SELECT column FROM someTable

Using action configs files:

# definitions/actions.yaml
actions:
- view:
  filename: name.sql
-- definitions/name.sql
SELECT column FROM someTable

Using the Javascript API:

// definitions/file.js
table("name", { type: "view" }).query("SELECT column FROM someTable")

Note: When using the Javascript API, methods in this class can be accessed by the returned value. This is where query comes from.

Hierarchy

  • ActionBuilder‹Table›

    View

Index

Methods

Methods

assertions

assertions(assertions: TableAssertionsConfig): this

deprecated Deprecated in favor of ViewConfig.assertions.

Sets in-line assertions for this view.

Parameters:

Name Type
assertions TableAssertionsConfig

Returns: this


bigquery

bigquery(bigquery: IBigQueryOptions): this

deprecated Deprecated in favor of options available directly on ViewConfig.

Sets bigquery options for the action.

Parameters:

Name Type
bigquery IBigQueryOptions

Returns: this


columns

columns(columns: ColumnDescriptor[]): this

deprecated Deprecated in favor of ViewConfig.columns.

Sets the column descriptors of columns in this view.

Parameters:

Name Type
columns ColumnDescriptor[]

Returns: this


database

database(database: string): this

deprecated Deprecated in favor of ViewConfig.project.

Sets the Sets the database (Google Cloud project ID) in which to create the output of this action.

Parameters:

Name Type
database string

Returns: this


dependencies

dependencies(value: Resolvable | Resolvable[]): this

deprecated Deprecated in favor of ViewConfig.dependencies.

Sets dependencies of the view.

Parameters:

Name Type
value Resolvable | Resolvable[]

Returns: this


description

description(description: string): this

deprecated Deprecated in favor of ViewConfig.description.

Sets the description of this view.

Parameters:

Name Type
description string

Returns: this


disabled

disabled(disabled: boolean): this

deprecated Deprecated in favor of ViewConfig.disabled.

If called with true, this action is not executed. The action can still be depended upon. Useful for temporarily turning off broken actions.

Parameters:

Name Type Default
disabled boolean true

Returns: this


hermetic

hermetic(hermetic: boolean): void

deprecated Deprecated in favor of ViewConfig.hermetic.

If true, this indicates that the action only depends on data from explicitly-declared dependencies. Otherwise if false, it indicates that the action depends on data from a source which has not been declared as a dependency.

Parameters:

Name Type
hermetic boolean

Returns: void


materialized

materialized(materialized: boolean): void

deprecated Deprecated in favor of ViewConfig.materialized.

Applies the materialized view optimization, see https://cloud.google.com/bigquery/docs/materialized-views-intro.

Parameters:

Name Type
materialized boolean

Returns: void


postOps

postOps(posts: ContextableITableContext, string | string[]›): this

Sets a post-operation to run after the query is run. This is often used for revoking temporary permissions granted to access source tables.

Example:

// definitions/file.js
publish("example")
  .preOps(ctx => `GRANT \`roles/bigquery.dataViewer\` ON TABLE ${ctx.ref("other_table")} TO "group:automation@example.com"`)
  .query(ctx => `SELECT * FROM ${ctx.ref("other_table")}`)
  .postOps(ctx => `REVOKE \`roles/bigquery.dataViewer\` ON TABLE ${ctx.ref("other_table")} TO "group:automation@example.com"`)

Parameters:

Name Type
posts ContextableITableContext, string | string[]›

Returns: this


preOps

preOps(pres: ContextableITableContext, string | string[]›): this

Sets a pre-operation to run before the query is run. This is often used for temporarily granting permission to access source tables.

Example:

// definitions/file.js
publish("example")
  .preOps(ctx => `GRANT \`roles/bigquery.dataViewer\` ON TABLE ${ctx.ref("other_table")} TO "group:automation@example.com"`)
  .query(ctx => `SELECT * FROM ${ctx.ref("other_table")}`)
  .postOps(ctx => `REVOKE \`roles/bigquery.dataViewer\` ON TABLE ${ctx.ref("other_table")} TO "group:automation@example.com"`)

Parameters:

Name Type
pres ContextableITableContext, string | string[]›

Returns: this


query

query(query: ContextableITableContext, string›): this

Sets the query to generate the table from.

Parameters:

Name Type
query ContextableITableContext, string›

Returns: this


schema

schema(schema: string): this

deprecated Deprecated in favor of ViewConfig.dataset.

Sets the schema (BigQuery dataset) in which to create the output of this action.

Parameters:

Name Type
schema string

Returns: this


setDependOnDependencyAssertions

setDependOnDependencyAssertions(dependOnDependencyAssertions: boolean): this

deprecated Deprecated in favor of ViewConfig.dependOnDependencyAssertions.

When called with true, assertions dependent upon any dependency will be add as dedpendency to this action.

Parameters:

Name Type
dependOnDependencyAssertions boolean

Returns: this


tags

tags(value: string | string[]): this

deprecated Deprecated in favor of ViewConfig.tags.

Sets a list of user-defined tags applied to this action.

Parameters:

Name Type
value string | string[]

Returns: this


type

type(type: TableType): this

deprecated Deprecated in favor of action type can being set in the configs passed to action constructor functions, for example publish("name", { type: "table" }).

Parameters:

Name Type
type TableType

Returns: this