Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

Dataform: How to get an unqualified table name?

mdale9
New Member

I am new to dataform and am migrating some ETL activities that involve Pivot and Unpivot.

I have created a config {type: "operations"} etc but in the query string that I am building for Execute Immediate I am extracting the column names from the schema:

select column_name from `myProject.myDataset`.INFORMATION_SCHEMA.COLUMNS where TABLE_NAME = ${ref("myTable")}
 
but ${ref("myTable")} returns the fully qualified `myProject.myDataset.myTable` and causes an error.  How can I get just the table name from ${ref()}?
 
Similarly, how can I get just the `myProject.myDataset` part of the qualified name?
Solved Solved
0 1 36
1 ACCEPTED SOLUTION

mdale9
New Member

Found the solution - https://cloud.google.com/dataform/docs/reference/dataform-core-reference#commoncontext

It's the simplest thing but it is not made clear in any of the examples.

  SELECT
    column_name
  FROM
    `${database()}.${schema()}`.INFORMATION_SCHEMA.COLUMNS
  WHERE
    TABLE_NAME = '${name()}'

View solution in original post

1 REPLY 1

mdale9
New Member

Found the solution - https://cloud.google.com/dataform/docs/reference/dataform-core-reference#commoncontext

It's the simplest thing but it is not made clear in any of the examples.

  SELECT
    column_name
  FROM
    `${database()}.${schema()}`.INFORMATION_SCHEMA.COLUMNS
  WHERE
    TABLE_NAME = '${name()}'