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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

馃帀 Base Normalization: quote schema name to allow reserved keywords #14683

Merged
merged 14 commits into from Jul 27, 2022
Merged
4 changes: 2 additions & 2 deletions airbyte-integrations/bases/base-normalization/Dockerfile
Expand Up @@ -28,5 +28,5 @@ WORKDIR /airbyte
ENV AIRBYTE_ENTRYPOINT "/airbyte/entrypoint.sh"
ENTRYPOINT ["/airbyte/entrypoint.sh"]

LABEL io.airbyte.version=0.2.10
LABEL io.airbyte.name=airbyte/normalization
LABEL io.airbyte.version=0.2.11
LABEL io.airbyte.name=airbyte/normalization
Expand Up @@ -181,13 +181,15 @@ def __normalize_identifier_name(
return f"'{result}'"
return result

def apply_quote(self, input: str) -> str:
def apply_quote(self, input: str, literal=True) -> str:
if literal:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure I understand this change - previously all of our quotes were using quote or adapter.quote; why do we need to switch them to just wrapping in single-quote marks?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes I agree not very obvious

before my change this function generated only such output:

adapter.quote('table_name')

as you know on jinja2 "level" it means: pass String literal 'table_name' to jinaj2 function adapter.quote

but I have a new requirement I need to get:

adapter.quote(this.schema)

on jinja2 level it means pass jinja2 variable to jinja2 function.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah that makes sense (also I misread the code, thought it was doing a return f"'{input}'"). So basically this is behaving exactly the same for literal=False.

input = f"'{input}'"
if self.destination_type == DestinationType.ORACLE:
# Oracle dbt lib doesn't implemented adapter quote yet.
return f"quote('{input}')"
edgao marked this conversation as resolved.
Show resolved Hide resolved
return f"quote({input})"
elif self.destination_type == DestinationType.CLICKHOUSE:
return f"quote('{input}')"
return f"adapter.quote('{input}')"
return f"quote({input})"
return f"adapter.quote({input})"

def __normalize_naming_conventions(self, input_name: str, is_column: bool = False) -> str:
result = input_name
Expand Down
Expand Up @@ -1209,7 +1209,10 @@ def add_to_outputs(
quoted_unique_key=self.get_unique_key(in_jinja=True),
active_row_column_name=active_row_column_name,
normalized_at_incremental_clause=self.get_incremental_clause_for_column(
"this.schema + '.' + " + self.name_transformer.apply_quote(final_table_name),
"{} + '.' + {}".format(
self.name_transformer.apply_quote("this.schema", literal=False),
self.name_transformer.apply_quote(final_table_name),
),
self.get_normalized_at(in_jinja=True),
),
unique_key_reference=unique_key_reference,
Expand Down
1 change: 1 addition & 0 deletions docs/understanding-airbyte/basic-normalization.md
Expand Up @@ -353,6 +353,7 @@ Therefore, in order to "upgrade" to the desired normalization version, you need

| Airbyte Version | Normalization Version | Date | Pull Request | Subject |
|:----------------| :--- | :--- | :--- | :--- |
| | 0.2.11 | 2022-07-24 | [\#14683](https://github.com/airbytehq/airbyte/pull/14683) | Quote schema name to allow reserved keywords |
| | 0.2.10 | 2022-07-18 | [\#14792](https://github.com/airbytehq/airbyte/pull/14792) | Add support for key pair auth for snowflake |
| | 0.2.9 | 2022-07-06 | [\#14485](https://github.com/airbytehq/airbyte/pull/14485) | BigQuery partition pruning otimization |
| | 0.2.8 | 2022-07-13 | [\#14522](https://github.com/airbytehq/airbyte/pull/14522) | BigQuery replaces `NULL` array entries with the string value `"NULL"` |
Expand Down