metricflow
metricflow copied to clipboard
Make SqlTable escaped keyword aware
Describe the Feature Update our table name rendering to properly handle escape characters for sql_table entries involving reserved keywords. This involves figuring out how to make the SqlTable class process and emit properly escaped table names in a generally robust fashion. Note this can be difficult as different engines have different escape characters, and escaped table names can be quite literally anything.
Today the SqlTable class does simple split/join operations on the .
character for differentiating between database, schema, and table sections in a table identifier string.
The issue is any table containing a reserved keyword can be escaped in either of the following ways in SQL:
-- schema is a reserved keyword
SELECT *
FROM "my_database.schema.my_table"
Or:
-- schema is a reserved keyword
SELECT *
FROM my_database."schema".my_table
However, the same is not true of our YAML input. If a user does this:
sql_table: "my_database.schema.my_table"
We will, at some point render a broken FROM clause like FROM schema.my_table"
Since warehouse validation should catch these kind of issues we might not need to deal with this at this level, but if there's a simple way to robustly manage this scenario it might be nice to have it in place.