Skip to content

Commit

Permalink
Fixes for SQLAlchemy 2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
rad-pat committed Oct 3, 2024
1 parent c921f69 commit 1b17e6c
Show file tree
Hide file tree
Showing 4 changed files with 288 additions and 360 deletions.
285 changes: 146 additions & 139 deletions plaidcloud/utilities/sqlalchemy_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,37 +237,16 @@ def compile_import_cast_databend(element, compiler, **kw):
func.coalesce(
func.try_to_timestamp(col),
func.try_to_timestamp(
func.concat(
# Year
func.cast(
1970 + func.coalesce(
func.cast(
func.nullif(
func.regexp_replace(
func.regexp_substr(
col,
r'(-?\d+)\s*(?:years?|year?|y)\b'
),
r'\D',
'',
),
'',
),
sqlalchemy.Integer,
),
0,
),
sqlalchemy.String,
) + '-' +
# Month
func.lpad(
func.cast(
1 + func.coalesce(
1970 + func.coalesce(
func.cast(
func.nullif(
func.regexp_replace(
func.regexp_substr(
col,
r'(-?\d+)\s*(?:months?|mons?|mon?|mo)\b'
r'(-?\d+)\s*(?:years?|year?|y)\b'
),
r'\D',
'',
Expand All @@ -280,162 +259,190 @@ def compile_import_cast_databend(element, compiler, **kw):
),
sqlalchemy.String,
),
2,
'0',
) + '-' +
# Day
func.lpad(
func.cast(
1 + func.coalesce(
func.cast(
func.nullif(
func.regexp_replace(
func.regexp_substr(
col,
r'(-?\d+)\s*(?:days?|day?|d)\b'
'-',
# Month
func.lpad(
func.cast(
1 + func.coalesce(
func.cast(
func.nullif(
func.regexp_replace(
func.regexp_substr(
col,
r'(-?\d+)\s*(?:months?|mons?|mon?|mo)\b'
),
r'\D',
'',
),
r'\D',
'',
),
'',
sqlalchemy.Integer,
),
sqlalchemy.Integer,
0,
),
0,
sqlalchemy.String,
),
sqlalchemy.String,
2,
'0',
),
2,
'0',
) + ' ' +
# Hours
func.lpad(
func.cast(
func.coalesce(
func.cast(
func.nullif(
func.regexp_replace(
func.regexp_substr(
col,
r'(-?\d+)\s*(?:hours?|hour?|h)\b'
'-',
# Day
func.lpad(
func.cast(
1 + func.coalesce(
func.cast(
func.nullif(
func.regexp_replace(
func.regexp_substr(
col,
r'(-?\d+)\s*(?:days?|day?|d)\b'
),
r'\D',
'',
),
r'\D',
'',
),
'',
sqlalchemy.Integer,
),
sqlalchemy.Integer,
0,
),
0,
) +
func.coalesce(
func.cast(
func.nullif(
func.regexp_substr(
sqlalchemy.String,
),
2,
'0',
),
' ',
# Hours
func.lpad(
func.cast(
func.coalesce(
func.cast(
func.nullif(
func.regexp_replace(
func.regexp_substr(
col,
r'(-?\d+)\s*(?:hours?|hour?|h)\b'
),
r'\D',
'',
),
'',
),
sqlalchemy.Integer,
),
0,
) +
func.coalesce(
func.cast(
func.nullif(
func.regexp_substr(
col,
r'\d{1,2}:\d{1,2}:\d{1,2}(?:\.\d+)?'
func.regexp_substr(
col,
r'\d{1,2}:\d{1,2}:\d{1,2}(?:\.\d+)?'
),
r'\\d{1,2}',
1,
1,
),
r'\\d{1,2}',
1,
1,
'',
),
'',
sqlalchemy.Integer,
),
sqlalchemy.Integer,
0,
),
0,
sqlalchemy.String,
),
sqlalchemy.String,
2,
'0',
),
2,
'0',
) + ':' +
# Minutes
func.lpad(
func.cast(
func.coalesce(
func.cast(
func.nullif(
func.regexp_replace(
func.regexp_substr(
col,
r'(-?\d+)\s*(?:minutes?|mins?|min?|m)\b'
':',
# Minutes
func.lpad(
func.cast(
func.coalesce(
func.cast(
func.nullif(
func.regexp_replace(
func.regexp_substr(
col,
r'(-?\d+)\s*(?:minutes?|mins?|min?|m)\b'
),
r'\D',
'',
),
r'\D',
'',
),
'',
sqlalchemy.Integer,
),
sqlalchemy.Integer,
),
0,
) +
func.coalesce(
func.cast(
func.nullif(
func.regexp_substr(
0,
) +
func.coalesce(
func.cast(
func.nullif(
func.regexp_substr(
col,
r'\d{1,2}:\d{1,2}:\d{1,2}(?:\.\d+)?'
func.regexp_substr(
col,
r'\d{1,2}:\d{1,2}:\d{1,2}(?:\.\d+)?'
),
r'\\d{1,2}',
1,
2,
),
r'\\d{1,2}',
1,
2,
'',
),
'',
sqlalchemy.Integer,
),
sqlalchemy.Integer,
0,
),
0,
sqlalchemy.String,
),
sqlalchemy.String,
2,
'0',
),
2,
'0',
) + ':' +
# Seconds
func.lpad(
func.cast(
func.coalesce(
func.cast(
func.nullif(
func.regexp_replace(
func.regexp_substr(
col,
r'(-?\d+)\s*(?:seconds?|secs?|sec?|s)\b'
':',
# Seconds
func.lpad(
func.cast(
func.coalesce(
func.cast(
func.nullif(
func.regexp_replace(
func.regexp_substr(
col,
r'(-?\d+)\s*(?:seconds?|secs?|sec?|s)\b'
),
r'\D',
'',
),
r'\D',
'',
),
'',
sqlalchemy.Integer,
),
sqlalchemy.Integer,
),
0,
) +
func.coalesce(
func.cast(
func.nullif(
func.regexp_substr(
0,
) +
func.coalesce(
func.cast(
func.nullif(
func.regexp_substr(
col,
r'\d{1,2}:\d{1,2}:\d{1,2}(?:\.\d+)?'
func.regexp_substr(
col,
r'\d{1,2}:\d{1,2}:\d{1,2}(?:\.\d+)?'
),
r'\\d{1,2}',
1,
3,
),
r'\\d{1,2}',
1,
3,
'',
),
'',
sqlalchemy.Integer,
),
sqlalchemy.Integer,
0,
),
0,
sqlalchemy.String,
),
sqlalchemy.String,
2,
'0',
),
2,
'0',
),
),
),
Expand Down
Loading

0 comments on commit 1b17e6c

Please sign in to comment.