Skip to content

Commit

Permalink
feat(bigquery): implement ops.Capitalize
Browse files Browse the repository at this point in the history
  • Loading branch information
krzysztof-kwitt authored and cpcloud committed Jan 4, 2023
1 parent 49414ef commit 5757bb0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
6 changes: 5 additions & 1 deletion ibis/backends/bigquery/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,10 @@ def _array_slice(t, op):
)


def _capitalize(t, op):
return f"CONCAT(UPPER(SUBSTR({t.translate(op.arg)}, 1, 1)), SUBSTR({t.translate(op.arg)}, 2))"


OPERATION_REGISTRY = {
**operation_registry,
# Literal
Expand Down Expand Up @@ -567,6 +571,7 @@ def _array_slice(t, op):
ops.StringFind: _string_find,
ops.Substring: _string_substring,
ops.StrRight: _string_right,
ops.Capitalize: _capitalize,
ops.Repeat: fixed_arity("REPEAT", 2),
ops.RegexSearch: _regex_search,
ops.RegexExtract: _regex_extract,
Expand Down Expand Up @@ -639,7 +644,6 @@ def _array_slice(t, op):
_invalid_operations = {
ops.Translate,
ops.FindInSet,
ops.Capitalize,
ops.DateDiff,
ops.TimestampDiff,
}
Expand Down
2 changes: 1 addition & 1 deletion ibis/backends/tests/test_string.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ def test_string_col_is_unicode(alltypes, df):
lambda t: t.string_col.capitalize(),
lambda t: t.string_col.str.capitalize(),
id='capitalize',
marks=pytest.mark.notimpl(["bigquery", "clickhouse", "duckdb", "mssql"]),
marks=pytest.mark.notimpl(["clickhouse", "duckdb", "mssql"]),
),
param(
lambda t: t.date_string_col.substr(2, 3),
Expand Down

0 comments on commit 5757bb0

Please sign in to comment.