Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Configuration variables
VERSION=1.1.1
VERSION=1.1.2rc1
PROJ_DIR?=$(shell pwd)
VENV_DIR?=${PROJ_DIR}/.bldenv
BUILD_DIR=${PROJ_DIR}/build
Expand Down
1 change: 1 addition & 0 deletions dbt/adapters/oracle/column.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@


from dbt.adapters.base.column import Column
from dbt.adapters.oracle.keyword_catalog import KEYWORDS


@dataclass
Expand Down
65 changes: 64 additions & 1 deletion dbt/adapters/oracle/impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
)
from itertools import chain

import agate

import dbt.exceptions
from dbt.adapters.base.relation import BaseRelation, InformationSchema
from dbt.adapters.base.impl import GET_CATALOG_MACRO_NAME
Expand All @@ -28,12 +30,15 @@
from dbt.adapters.oracle.column import OracleColumn
from dbt.adapters.oracle.relation import OracleRelation
from dbt.contracts.graph.manifest import Manifest
from dbt.events import AdapterLogger

from dbt.exceptions import raise_compiler_error
from dbt.utils import filter_null_values

from dbt.adapters.oracle.keyword_catalog import KEYWORDS

logger = AdapterLogger("oracle")

import agate

COLUMNS_EQUAL_SQL = '''
with diff_count as (
Expand Down Expand Up @@ -232,13 +237,71 @@ def list_relations_without_caching(
))
return relations

@staticmethod
def is_valid_identifier(identifier) -> bool:
"""Returns True if an identifier is valid

An identifier is considered valid if the following conditions are True

1. First character is alphabetic
2. Rest of the characters is either alphanumeric or any one of the literals '#', '$', '_'

"""
# The first character should be alphabetic
if not identifier[0].isalpha():
return False
# Rest of the characters is either alphanumeric or any one of the literals '#', '$', '_'
idx = 1
while idx < len(identifier):
identifier_chr = identifier[idx]
if not identifier_chr.isalnum() and identifier_chr not in ('#', '$', '_'):
return False
idx += 1
return True

@available
def should_identifier_be_quoted(self,
identifier,
models_column_dict=None) -> bool:
"""Returns True if identifier should be quoted else False

An identifier should be quoted in the following 3 cases:

- 1. Identifier is an Oracle keyword

- 2. Identifier is not valid according to the following rules
- First character is alphabetic
- Rest of the characters is either alphanumeric or any one of the literals '#', '$', '_'

- 3. User has enabled quoting for the column in the model configuration

"""
if identifier.upper() in KEYWORDS:
return True
elif not self.is_valid_identifier(identifier):
return True
elif models_column_dict and identifier in models_column_dict:
return models_column_dict[identifier].get('quote', False)
elif models_column_dict and self.quote(identifier) in models_column_dict:
return models_column_dict[self.quote(identifier)].get('quote', False)
return False

@available
def check_and_quote_identifier(self, identifier, models_column_dict=None) -> str:
if self.should_identifier_be_quoted(identifier, models_column_dict):
return self.quote(identifier)
else:
return identifier

@available
def quote_seed_column(
self, column: str, quote_config: Optional[bool]
) -> str:
quote_columns: bool = False
if isinstance(quote_config, bool):
quote_columns = quote_config
elif self.should_identifier_be_quoted(column):
quote_columns = True
elif quote_config is None:
pass
else:
Expand Down
Loading