Skip to content

Commit

Permalink
Add tests for bigquery label sanitize helper.
Browse files Browse the repository at this point in the history
  • Loading branch information
jmcarp committed Mar 8, 2021
1 parent 82cca95 commit f3f2f72
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion plugins/bigquery/dbt/adapters/bigquery/connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -598,5 +598,5 @@ def _sanitize_label(value: str, max_length: int = 63) -> str:
"""Return a legal value for a BigQuery label."""
value = value.lower()
value = _SANITIZE_LABEL_PATTERN.sub("_", value)
value = value[: max_length - 1]
value = value[: max_length]
return value
14 changes: 14 additions & 0 deletions test/unit/test_bigquery_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@
from dbt.adapters.bigquery import BigQueryRelation
from dbt.adapters.bigquery import Plugin as BigQueryPlugin
from dbt.adapters.bigquery.connections import BigQueryConnectionManager
from dbt.adapters.bigquery.connections import _sanitize_label
from dbt.adapters.base.query_headers import MacroQueryStringSetter
from dbt.clients import agate_helper
import dbt.exceptions
from dbt.logger import GLOBAL_LOGGER as logger # noqa
from dbt.context.providers import RuntimeConfigObject

import pytest
import google.cloud.bigquery

from .utils import config_from_parts_or_dicts, inject_adapter, TestAdapterConversions
Expand Down Expand Up @@ -939,3 +941,15 @@ def test_convert_time_type(self):
expected = ['time', 'time', 'time']
for col_idx, expect in enumerate(expected):
assert BigQueryAdapter.convert_time_type(agate_table, col_idx) == expect


@pytest.mark.parametrize(
["input", "output"],
[
("a" * 64, "a" * 63),
("ABC", "abc"),
("a c", "a_c"),
],
)
def test_sanitize_label(input, output):
assert _sanitize_label(input) == output

0 comments on commit f3f2f72

Please sign in to comment.