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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Rtrim/Ltrim #207

Merged
merged 1 commit into from
Sep 23, 2024
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
6 changes: 3 additions & 3 deletions plaidcloud/utilities/sqlalchemy_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -943,7 +943,7 @@ def compile_safe_ltrim_databend(element, compiler, **kw):
compiled_args = ', '.join([compiler.process(arg) for arg in args])
return f"TRIM(LEADING {compiled_args} FROM {compiler.process(text)})"

return f"TRIM(LEADING FROM {compiler.process(text)})"
return f"TRIM(LEADING ' ' FROM {compiler.process(text)})"


class safe_rtrim(GenericFunction):
Expand All @@ -970,7 +970,7 @@ def compile_safe_rtrim(element, compiler, **kw):
compiled_args = ', '.join([compiler.process(arg) for arg in args])
return f"TRIM(TRAILING {compiled_args} FROM {compiler.process(text)})"

return f"TRIM(TRAILING FROM {compiler.process(text)})"
return f"TRIM(TRAILING ' ' FROM {compiler.process(text)})"


class safe_trim(GenericFunction):
Expand Down Expand Up @@ -1185,7 +1185,7 @@ def compile_to_char(element, compiler, **kw):
decimal_non_drop_digits = len([ch for ch in right if ch == '0'])
decimal_str = func.to_string(decimal_part)
if decimal_non_drop_digits:
decimal_str = func.rpad(decimal_str, decimal_non_drop_digits)
decimal_str = func.rpad(decimal_str, decimal_non_drop_digits, '0')
final_str = func.concat(integer_str, '.', decimal_str)

return compiler.process(final_str)
Expand Down
6 changes: 3 additions & 3 deletions plaidcloud/utilities/tests/test_sqlalchemy_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@
def test_ltrim_plain(self):
expr = sqlalchemy.func.ltrim('12345', '')
compiled = expr.compile(dialect=self.eng.dialect, compile_kwargs={"render_postcompile": True})
self.assertEqual('TRIM(LEADING FROM CAST(%(ltrim_1)s AS TEXT))', str(compiled))
self.assertEqual('TRIM(LEADING \' \' FROM CAST(%(ltrim_1)s AS TEXT))', str(compiled))
self.assertEqual('12345', compiled.params['ltrim_1'])

def test_ltrim_specific(self):
Expand All @@ -412,7 +412,7 @@
def test_rtrim_plain(self):
expr = sqlalchemy.func.rtrim('12345', '')
compiled = expr.compile(dialect=self.eng.dialect, compile_kwargs={"render_postcompile": True})
self.assertEqual('TRIM(TRAILING FROM CAST(%(rtrim_1)s AS TEXT))', str(compiled))
self.assertEqual('TRIM(TRAILING \' \' FROM CAST(%(rtrim_1)s AS TEXT))', str(compiled))
self.assertEqual('12345', compiled.params['rtrim_1'])

def test_rtrim_specific(self):
Expand Down Expand Up @@ -443,7 +443,7 @@
expr = sqlalchemy.func.to_char(123456.789, 'LFM999,999,999,999D00')
compiled = expr.compile(dialect=self.eng.dialect, compile_kwargs={"render_postcompile": True})
self.assertEqual(
'concat(concat(%(concat_1)s, to_string(truncate(truncate(%(to_char_1)s, %(truncate_1)s), %(truncate_2)s))), %(concat_2)s, rpad(to_string(truncate(%(to_char_1)s, %(truncate_1)s) - truncate(truncate(%(to_char_1)s, %(truncate_1)s), %(truncate_2)s)), %(rpad_1)s))',
'concat(concat(%(concat_1)s, to_string(truncate(truncate(%(to_char_1)s, %(truncate_1)s), %(truncate_2)s))), %(concat_2)s, rpad(to_string(truncate(%(to_char_1)s, %(truncate_1)s) - truncate(truncate(%(to_char_1)s, %(truncate_1)s), %(truncate_2)s)), %(rpad_1)s, %(rpad_2)s))',

Check warning on line 446 in plaidcloud/utilities/tests/test_sqlalchemy_functions.py

View workflow job for this annotation

GitHub Actions / PyLint

[PyLint] plaidcloud/utilities/tests/test_sqlalchemy_functions.py#L446

C0301: Line too long (285/125) (line-too-long)
Raw output
plaidcloud/utilities/tests/test_sqlalchemy_functions.py:446:0: C0301: Line too long (285/125) (line-too-long)
str(compiled),
)
self.assertEqual('$', compiled.params['concat_1'])
Expand Down
Loading