meerschaum 2.4.5__py3-none-any.whl → 2.4.7__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- meerschaum/_internal/docs/index.py +1 -0
- meerschaum/actions/show.py +2 -1
- meerschaum/actions/sql.py +11 -11
- meerschaum/api/dash/pipes.py +4 -2
- meerschaum/api/routes/_pipes.py +3 -8
- meerschaum/config/_version.py +1 -1
- meerschaum/connectors/api/_pipes.py +4 -4
- meerschaum/connectors/sql/_SQLConnector.py +12 -2
- meerschaum/connectors/sql/_create_engine.py +13 -6
- meerschaum/connectors/sql/_pipes.py +81 -65
- meerschaum/connectors/sql/_sql.py +194 -106
- meerschaum/connectors/valkey/_ValkeyConnector.py +2 -5
- meerschaum/core/Pipe/__init__.py +1 -0
- meerschaum/core/Pipe/_attributes.py +1 -1
- meerschaum/core/Pipe/_data.py +16 -16
- meerschaum/core/Pipe/_deduplicate.py +27 -27
- meerschaum/core/Pipe/_sync.py +26 -1
- meerschaum/core/Pipe/_verify.py +5 -5
- meerschaum/utils/dataframe.py +127 -8
- meerschaum/utils/dtypes/__init__.py +26 -4
- meerschaum/utils/dtypes/sql.py +30 -0
- meerschaum/utils/misc.py +1 -1
- meerschaum/utils/sql.py +100 -64
- meerschaum/utils/yaml.py +3 -6
- {meerschaum-2.4.5.dist-info → meerschaum-2.4.7.dist-info}/METADATA +1 -1
- {meerschaum-2.4.5.dist-info → meerschaum-2.4.7.dist-info}/RECORD +32 -32
- {meerschaum-2.4.5.dist-info → meerschaum-2.4.7.dist-info}/LICENSE +0 -0
- {meerschaum-2.4.5.dist-info → meerschaum-2.4.7.dist-info}/NOTICE +0 -0
- {meerschaum-2.4.5.dist-info → meerschaum-2.4.7.dist-info}/WHEEL +0 -0
- {meerschaum-2.4.5.dist-info → meerschaum-2.4.7.dist-info}/entry_points.txt +0 -0
- {meerschaum-2.4.5.dist-info → meerschaum-2.4.7.dist-info}/top_level.txt +0 -0
- {meerschaum-2.4.5.dist-info → meerschaum-2.4.7.dist-info}/zip-safe +0 -0
@@ -545,6 +545,7 @@ def init_dash(dash_app):
|
|
545
545
|
<li><code>meerschaum.utils.dataframe.get_unhashable_cols()</code></li>
|
546
546
|
<li><code>meerschaum.utils.dataframe.parse_df_datetimes()</code></li>
|
547
547
|
<li><code>meerschaum.utils.dataframe.query_df()</code></li>
|
548
|
+
<li><code>meerschaum.utils.dataframe.to_json()</code></li>
|
548
549
|
</ul>
|
549
550
|
</details>
|
550
551
|
</ul>
|
meerschaum/actions/show.py
CHANGED
@@ -309,6 +309,7 @@ def _show_data(
|
|
309
309
|
from meerschaum.utils.packages import attempt_import, import_pandas
|
310
310
|
from meerschaum.utils.warnings import warn, info
|
311
311
|
from meerschaum.utils.formatting import pprint
|
312
|
+
from meerschaum.utils.dataframe import to_json
|
312
313
|
pd = import_pandas()
|
313
314
|
|
314
315
|
if action is None:
|
@@ -372,7 +373,7 @@ def _show_data(
|
|
372
373
|
info(info_msg)
|
373
374
|
else:
|
374
375
|
print(json.dumps(p.__getstate__()))
|
375
|
-
df =
|
376
|
+
df = to_json(df, orient='columns')
|
376
377
|
|
377
378
|
pprint(df, nopretty=nopretty)
|
378
379
|
|
meerschaum/actions/sql.py
CHANGED
@@ -15,12 +15,12 @@ exec_methods = {
|
|
15
15
|
}
|
16
16
|
|
17
17
|
def sql(
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
18
|
+
action: Optional[List[str]] = None,
|
19
|
+
gui: bool = False,
|
20
|
+
nopretty: bool = False,
|
21
|
+
debug: bool = False,
|
22
|
+
**kw: Any
|
23
|
+
):
|
24
24
|
"""Execute a SQL query or launch an interactive CLI. All positional arguments are optional.
|
25
25
|
|
26
26
|
Usage:
|
@@ -59,6 +59,7 @@ def sql(
|
|
59
59
|
- `sql local exec "INSERT INTO table (id) VALUES (1)"
|
60
60
|
Execute the above query on `sql:local`.
|
61
61
|
"""
|
62
|
+
from meerschaum.utils.dataframe impor to_json
|
62
63
|
|
63
64
|
if action is None:
|
64
65
|
action = []
|
@@ -135,11 +136,10 @@ def sql(
|
|
135
136
|
pprint(result)
|
136
137
|
else:
|
137
138
|
print(
|
138
|
-
|
139
|
-
|
140
|
-
orient
|
141
|
-
index
|
142
|
-
date_unit = 'us'
|
139
|
+
to_json(
|
140
|
+
result,
|
141
|
+
orient='split',
|
142
|
+
index=False,
|
143
143
|
)
|
144
144
|
)
|
145
145
|
|
meerschaum/api/dash/pipes.py
CHANGED
@@ -18,6 +18,7 @@ from meerschaum.utils.misc import string_to_dict
|
|
18
18
|
from meerschaum.utils.packages import attempt_import, import_dcc, import_html, import_pandas
|
19
19
|
from meerschaum.utils.sql import get_pd_type
|
20
20
|
from meerschaum.utils.yaml import yaml
|
21
|
+
from meerschaum.utils.dataframe import to_json
|
21
22
|
from meerschaum.connectors.sql._fetch import get_pipe_query
|
22
23
|
from meerschaum.api import CHECK_UPDATE
|
23
24
|
from meerschaum.api.dash import debug, _get_pipes
|
@@ -563,12 +564,13 @@ def accordion_items_from_pipe(
|
|
563
564
|
if 'sync-data' in active_items:
|
564
565
|
backtrack_df = pipe.get_backtrack_data(debug=debug, limit=1)
|
565
566
|
try:
|
566
|
-
json_text =
|
567
|
+
json_text = to_json(
|
568
|
+
backtrack_df,
|
567
569
|
orient='records',
|
568
570
|
date_format='iso',
|
569
571
|
force_ascii=False,
|
570
572
|
indent=4,
|
571
|
-
date_unit='
|
573
|
+
date_unit='us',
|
572
574
|
) if backtrack_df is not None else '[]'
|
573
575
|
except Exception as e:
|
574
576
|
warn(e)
|
meerschaum/api/routes/_pipes.py
CHANGED
@@ -27,7 +27,7 @@ from decimal import Decimal
|
|
27
27
|
from meerschaum import Pipe
|
28
28
|
from meerschaum.api.models import MetaPipe
|
29
29
|
from meerschaum.utils.packages import attempt_import, import_pandas
|
30
|
-
from meerschaum.utils.dataframe import get_numeric_cols
|
30
|
+
from meerschaum.utils.dataframe import get_numeric_cols, to_json
|
31
31
|
from meerschaum.utils.misc import (
|
32
32
|
is_pipe_registered, round_time, is_int, parse_df_datetimes,
|
33
33
|
replace_pipes_in_dict,
|
@@ -473,15 +473,10 @@ def get_pipe_data(
|
|
473
473
|
for col in numeric_cols:
|
474
474
|
df[col] = df[col].apply(lambda x: f'{x:f}' if isinstance(x, Decimal) else x)
|
475
475
|
|
476
|
-
json_content =
|
477
|
-
date_format='iso',
|
478
|
-
orient='records',
|
479
|
-
date_unit='us',
|
480
|
-
)
|
481
|
-
|
476
|
+
json_content = to_json(df)
|
482
477
|
return fastapi.Response(
|
483
478
|
json_content,
|
484
|
-
media_type
|
479
|
+
media_type='application/json',
|
485
480
|
)
|
486
481
|
|
487
482
|
|
meerschaum/config/_version.py
CHANGED
@@ -171,8 +171,8 @@ def sync_pipe(
|
|
171
171
|
from meerschaum.utils.debug import dprint
|
172
172
|
from meerschaum.utils.misc import json_serialize_datetime, items_str
|
173
173
|
from meerschaum.config import get_config
|
174
|
-
from meerschaum.utils.packages import attempt_import
|
175
|
-
from meerschaum.utils.dataframe import get_numeric_cols
|
174
|
+
from meerschaum.utils.packages import attempt_import
|
175
|
+
from meerschaum.utils.dataframe import get_numeric_cols, to_json
|
176
176
|
begin = time.time()
|
177
177
|
more_itertools = attempt_import('more_itertools')
|
178
178
|
if df is None:
|
@@ -183,8 +183,7 @@ def sync_pipe(
|
|
183
183
|
### allow syncing dict or JSON without needing to import pandas (for IOT devices)
|
184
184
|
if isinstance(c, (dict, list)):
|
185
185
|
return json.dumps(c, default=json_serialize_datetime)
|
186
|
-
|
187
|
-
return c.fillna(pd.NA).to_json(date_format='iso', date_unit='ns')
|
186
|
+
return to_json(c, orient='columns')
|
188
187
|
|
189
188
|
df = json.loads(df) if isinstance(df, str) else df
|
190
189
|
|
@@ -202,6 +201,7 @@ def sync_pipe(
|
|
202
201
|
if not is_dask
|
203
202
|
else [partition.compute() for partition in df.partitions]
|
204
203
|
)
|
204
|
+
|
205
205
|
numeric_cols = get_numeric_cols(df)
|
206
206
|
if numeric_cols:
|
207
207
|
for col in numeric_cols:
|
@@ -13,6 +13,7 @@ from meerschaum.utils.typing import Optional, Any, Union
|
|
13
13
|
from meerschaum.connectors import Connector
|
14
14
|
from meerschaum.utils.warnings import error
|
15
15
|
|
16
|
+
|
16
17
|
class SQLConnector(Connector):
|
17
18
|
"""
|
18
19
|
Connect to SQL databases via `sqlalchemy`.
|
@@ -26,7 +27,16 @@ class SQLConnector(Connector):
|
|
26
27
|
IS_INSTANCE: bool = True
|
27
28
|
|
28
29
|
from ._create_engine import flavor_configs, create_engine
|
29
|
-
from ._sql import
|
30
|
+
from ._sql import (
|
31
|
+
read,
|
32
|
+
value,
|
33
|
+
exec,
|
34
|
+
execute,
|
35
|
+
to_sql,
|
36
|
+
exec_queries,
|
37
|
+
get_connection,
|
38
|
+
_cleanup_connections,
|
39
|
+
)
|
30
40
|
from meerschaum.utils.sql import test_connection
|
31
41
|
from ._fetch import fetch, get_pipe_metadef
|
32
42
|
from ._cli import cli, _cli_exit
|
@@ -85,7 +95,7 @@ class SQLConnector(Connector):
|
|
85
95
|
_drop_temporary_tables,
|
86
96
|
_drop_old_temporary_tables,
|
87
97
|
)
|
88
|
-
|
98
|
+
|
89
99
|
def __init__(
|
90
100
|
self,
|
91
101
|
label: Optional[str] = None,
|
@@ -71,7 +71,13 @@ flavor_configs = {
|
|
71
71
|
'requirements': default_requirements,
|
72
72
|
'defaults': {
|
73
73
|
'port': 1433,
|
74
|
-
'options':
|
74
|
+
'options': (
|
75
|
+
"driver=ODBC Driver 18 for SQL Server"
|
76
|
+
"&UseFMTONLY=Yes"
|
77
|
+
"&TrustServerCertificate=yes"
|
78
|
+
"&Encrypt=no"
|
79
|
+
"&MARS_Connection=yes"
|
80
|
+
),
|
75
81
|
},
|
76
82
|
},
|
77
83
|
'mysql': {
|
@@ -167,12 +173,13 @@ flavor_dialects = {
|
|
167
173
|
'duckdb': ('duckdb', 'duckdb_engine', 'Dialect'),
|
168
174
|
}
|
169
175
|
|
176
|
+
|
170
177
|
def create_engine(
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
178
|
+
self,
|
179
|
+
include_uri: bool = False,
|
180
|
+
debug: bool = False,
|
181
|
+
**kw
|
182
|
+
) -> 'sqlalchemy.engine.Engine':
|
176
183
|
"""Create a sqlalchemy engine by building the engine string."""
|
177
184
|
from meerschaum.utils.packages import attempt_import
|
178
185
|
from meerschaum.utils.warnings import error, warn
|
@@ -11,9 +11,10 @@ import meerschaum as mrsm
|
|
11
11
|
from meerschaum.utils.typing import (
|
12
12
|
Union, Any, SuccessTuple, Tuple, Dict, Optional, List
|
13
13
|
)
|
14
|
-
from meerschaum.utils.warnings import warn, error
|
14
|
+
from meerschaum.utils.warnings import warn, error
|
15
15
|
from meerschaum.utils.debug import dprint
|
16
16
|
|
17
|
+
|
17
18
|
def register_pipe(
|
18
19
|
self,
|
19
20
|
pipe: mrsm.Pipe,
|
@@ -73,12 +74,12 @@ def register_pipe(
|
|
73
74
|
|
74
75
|
|
75
76
|
def edit_pipe(
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
77
|
+
self,
|
78
|
+
pipe : mrsm.Pipe = None,
|
79
|
+
patch: bool = False,
|
80
|
+
debug: bool = False,
|
81
|
+
**kw : Any
|
82
|
+
) -> SuccessTuple:
|
82
83
|
"""
|
83
84
|
Persist a Pipe's parameters to its database.
|
84
85
|
|
@@ -307,11 +308,11 @@ def fetch_pipes_keys(
|
|
307
308
|
|
308
309
|
|
309
310
|
def create_indices(
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
311
|
+
self,
|
312
|
+
pipe: mrsm.Pipe,
|
313
|
+
indices: Optional[List[str]] = None,
|
314
|
+
debug: bool = False
|
315
|
+
) -> bool:
|
315
316
|
"""
|
316
317
|
Create a pipe's indices.
|
317
318
|
"""
|
@@ -339,11 +340,11 @@ def create_indices(
|
|
339
340
|
|
340
341
|
|
341
342
|
def drop_indices(
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
343
|
+
self,
|
344
|
+
pipe: mrsm.Pipe,
|
345
|
+
indices: Optional[List[str]] = None,
|
346
|
+
debug: bool = False
|
347
|
+
) -> bool:
|
347
348
|
"""
|
348
349
|
Drop a pipe's indices.
|
349
350
|
"""
|
@@ -369,10 +370,10 @@ def drop_indices(
|
|
369
370
|
|
370
371
|
|
371
372
|
def get_create_index_queries(
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
373
|
+
self,
|
374
|
+
pipe: mrsm.Pipe,
|
375
|
+
debug: bool = False,
|
376
|
+
) -> Dict[str, List[str]]:
|
376
377
|
"""
|
377
378
|
Return a dictionary mapping columns to a `CREATE INDEX` or equivalent query.
|
378
379
|
|
@@ -541,10 +542,10 @@ def get_create_index_queries(
|
|
541
542
|
|
542
543
|
|
543
544
|
def get_drop_index_queries(
|
544
|
-
|
545
|
-
|
546
|
-
|
547
|
-
|
545
|
+
self,
|
546
|
+
pipe: mrsm.Pipe,
|
547
|
+
debug: bool = False,
|
548
|
+
) -> Dict[str, List[str]]:
|
548
549
|
"""
|
549
550
|
Return a dictionary mapping columns to a `DROP INDEX` or equivalent query.
|
550
551
|
|
@@ -607,10 +608,10 @@ def get_drop_index_queries(
|
|
607
608
|
|
608
609
|
|
609
610
|
def delete_pipe(
|
610
|
-
|
611
|
-
|
612
|
-
|
613
|
-
|
611
|
+
self,
|
612
|
+
pipe: mrsm.Pipe,
|
613
|
+
debug: bool = False,
|
614
|
+
) -> SuccessTuple:
|
614
615
|
"""
|
615
616
|
Delete a Pipe's registration.
|
616
617
|
"""
|
@@ -701,7 +702,7 @@ def get_pipe_data(
|
|
701
702
|
from meerschaum.utils.sql import sql_item_name
|
702
703
|
from meerschaum.utils.misc import parse_df_datetimes, to_pandas_dtype
|
703
704
|
from meerschaum.utils.packages import import_pandas
|
704
|
-
from meerschaum.utils.dtypes import attempt_cast_to_numeric
|
705
|
+
from meerschaum.utils.dtypes import attempt_cast_to_numeric, attempt_cast_to_uuid
|
705
706
|
pd = import_pandas()
|
706
707
|
is_dask = 'dask' in pd.__name__
|
707
708
|
|
@@ -768,6 +769,12 @@ def get_pipe_data(
|
|
768
769
|
for col, typ in pipe.dtypes.items()
|
769
770
|
if typ == 'numeric' and col in dtypes
|
770
771
|
]
|
772
|
+
uuid_columns = [
|
773
|
+
col
|
774
|
+
for col, typ in pipe.dtypes.items()
|
775
|
+
if typ == 'uuid' and col in dtypes
|
776
|
+
]
|
777
|
+
|
771
778
|
kw['coerce_float'] = kw.get('coerce_float', (len(numeric_columns) == 0))
|
772
779
|
|
773
780
|
df = self.read(
|
@@ -781,6 +788,11 @@ def get_pipe_data(
|
|
781
788
|
continue
|
782
789
|
df[col] = df[col].apply(attempt_cast_to_numeric)
|
783
790
|
|
791
|
+
for col in uuid_columns:
|
792
|
+
if col not in df.columns:
|
793
|
+
continue
|
794
|
+
df[col] = df[col].apply(attempt_cast_to_uuid)
|
795
|
+
|
784
796
|
if self.flavor == 'sqlite':
|
785
797
|
ignore_dt_cols = [
|
786
798
|
col
|
@@ -1036,10 +1048,10 @@ def get_pipe_data_query(
|
|
1036
1048
|
|
1037
1049
|
|
1038
1050
|
def get_pipe_id(
|
1039
|
-
|
1040
|
-
|
1041
|
-
|
1042
|
-
|
1051
|
+
self,
|
1052
|
+
pipe: mrsm.Pipe,
|
1053
|
+
debug: bool = False,
|
1054
|
+
) -> Any:
|
1043
1055
|
"""
|
1044
1056
|
Get a Pipe's ID from the pipes table.
|
1045
1057
|
"""
|
@@ -1066,10 +1078,10 @@ def get_pipe_id(
|
|
1066
1078
|
|
1067
1079
|
|
1068
1080
|
def get_pipe_attributes(
|
1069
|
-
|
1070
|
-
|
1071
|
-
|
1072
|
-
|
1081
|
+
self,
|
1082
|
+
pipe: mrsm.Pipe,
|
1083
|
+
debug: bool = False,
|
1084
|
+
) -> Dict[str, Any]:
|
1073
1085
|
"""
|
1074
1086
|
Get a Pipe's attributes dictionary.
|
1075
1087
|
"""
|
@@ -1236,7 +1248,7 @@ def sync_pipe(
|
|
1236
1248
|
}
|
1237
1249
|
pipe_dtypes.update(new_bool_cols)
|
1238
1250
|
pipe.dtypes = pipe_dtypes
|
1239
|
-
if not pipe.temporary:
|
1251
|
+
if new_bool_cols and not pipe.temporary:
|
1240
1252
|
infer_bool_success, infer_bool_msg = pipe.edit(debug=debug)
|
1241
1253
|
if not infer_bool_success:
|
1242
1254
|
return infer_bool_success, infer_bool_msg
|
@@ -1468,7 +1480,7 @@ def sync_pipe_inplace(
|
|
1468
1480
|
|
1469
1481
|
transact_id = generate_password(3)
|
1470
1482
|
def get_temp_table_name(label: str) -> str:
|
1471
|
-
return '
|
1483
|
+
return '##' + transact_id + '_' + label + '_' + pipe.target
|
1472
1484
|
|
1473
1485
|
internal_schema = self.internal_schema
|
1474
1486
|
temp_table_roots = ['backtrack', 'new', 'delta', 'joined', 'unseen', 'update']
|
@@ -1486,11 +1498,11 @@ def sync_pipe_inplace(
|
|
1486
1498
|
}
|
1487
1499
|
metadef = self.get_pipe_metadef(
|
1488
1500
|
pipe,
|
1489
|
-
params
|
1490
|
-
begin
|
1491
|
-
end
|
1492
|
-
check_existing
|
1493
|
-
debug
|
1501
|
+
params=params,
|
1502
|
+
begin=begin,
|
1503
|
+
end=end,
|
1504
|
+
check_existing=check_existing,
|
1505
|
+
debug=debug,
|
1494
1506
|
)
|
1495
1507
|
pipe_name = sql_item_name(pipe.target, self.flavor, self.get_pipe_schema(pipe))
|
1496
1508
|
upsert = pipe.parameters.get('upsert', False) and f'{self.flavor}-upsert' in update_queries
|
@@ -1502,15 +1514,15 @@ def sync_pipe_inplace(
|
|
1502
1514
|
table
|
1503
1515
|
for table in temp_tables.values()
|
1504
1516
|
] if not upsert else [temp_tables['update']],
|
1505
|
-
ready_to_drop
|
1506
|
-
create
|
1507
|
-
debug
|
1517
|
+
ready_to_drop=ready_to_drop,
|
1518
|
+
create=(not pipe.temporary),
|
1519
|
+
debug=debug,
|
1508
1520
|
)
|
1509
1521
|
if not log_success:
|
1510
1522
|
warn(log_msg)
|
1511
1523
|
drop_stale_success, drop_stale_msg = self._drop_old_temporary_tables(
|
1512
|
-
refresh
|
1513
|
-
debug
|
1524
|
+
refresh=False,
|
1525
|
+
debug=debug,
|
1514
1526
|
)
|
1515
1527
|
if not drop_stale_success:
|
1516
1528
|
warn(drop_stale_msg)
|
@@ -1522,7 +1534,7 @@ def sync_pipe_inplace(
|
|
1522
1534
|
metadef,
|
1523
1535
|
pipe.target,
|
1524
1536
|
self.flavor,
|
1525
|
-
schema
|
1537
|
+
schema=self.get_pipe_schema(pipe),
|
1526
1538
|
)
|
1527
1539
|
result = self.exec(create_pipe_query, debug=debug)
|
1528
1540
|
if result is None:
|
@@ -1543,13 +1555,13 @@ def sync_pipe_inplace(
|
|
1543
1555
|
metadef,
|
1544
1556
|
temp_tables[('new') if not upsert else 'update'],
|
1545
1557
|
self.flavor,
|
1546
|
-
schema
|
1558
|
+
schema=internal_schema,
|
1547
1559
|
)
|
1548
1560
|
(create_new_success, create_new_msg), create_new_results = session_execute(
|
1549
1561
|
session,
|
1550
1562
|
create_new_query,
|
1551
|
-
with_results
|
1552
|
-
debug
|
1563
|
+
with_results=True,
|
1564
|
+
debug=debug,
|
1553
1565
|
)
|
1554
1566
|
if not create_new_success:
|
1555
1567
|
_ = clean_up_temp_tables()
|
@@ -1558,11 +1570,11 @@ def sync_pipe_inplace(
|
|
1558
1570
|
|
1559
1571
|
new_cols_types = get_table_cols_types(
|
1560
1572
|
temp_tables[('new' if not upsert else 'update')],
|
1561
|
-
connectable
|
1562
|
-
flavor
|
1563
|
-
schema
|
1564
|
-
database
|
1565
|
-
debug
|
1573
|
+
connectable=connectable,
|
1574
|
+
flavor=self.flavor,
|
1575
|
+
schema=internal_schema,
|
1576
|
+
database=database,
|
1577
|
+
debug=debug,
|
1566
1578
|
)
|
1567
1579
|
if not new_cols_types:
|
1568
1580
|
return False, f"Failed to get new columns for {pipe}."
|
@@ -2389,6 +2401,7 @@ def get_add_columns_queries(
|
|
2389
2401
|
self,
|
2390
2402
|
pipe: mrsm.Pipe,
|
2391
2403
|
df: Union[pd.DataFrame, Dict[str, str]],
|
2404
|
+
_is_db_types: bool = False,
|
2392
2405
|
debug: bool = False,
|
2393
2406
|
) -> List[str]:
|
2394
2407
|
"""
|
@@ -2403,6 +2416,9 @@ def get_add_columns_queries(
|
|
2403
2416
|
The pandas DataFrame which contains new columns.
|
2404
2417
|
If a dictionary is provided, assume it maps columns to Pandas data types.
|
2405
2418
|
|
2419
|
+
_is_db_types: bool, default False
|
2420
|
+
If `True`, assume `df` is a dictionary mapping columns to SQL native dtypes.
|
2421
|
+
|
2406
2422
|
Returns
|
2407
2423
|
-------
|
2408
2424
|
A list of the `ALTER TABLE` SQL query or queries to be executed on the provided connector.
|
@@ -2495,11 +2511,11 @@ def get_add_columns_queries(
|
|
2495
2511
|
|
2496
2512
|
|
2497
2513
|
def get_alter_columns_queries(
|
2498
|
-
|
2499
|
-
|
2500
|
-
|
2501
|
-
|
2502
|
-
|
2514
|
+
self,
|
2515
|
+
pipe: mrsm.Pipe,
|
2516
|
+
df: Union[pd.DataFrame, Dict[str, str]],
|
2517
|
+
debug: bool = False,
|
2518
|
+
) -> List[str]:
|
2503
2519
|
"""
|
2504
2520
|
If we encounter a column of a different type, set the entire column to text.
|
2505
2521
|
If the altered columns are numeric, alter to numeric instead.
|
@@ -2556,6 +2572,7 @@ def get_alter_columns_queries(
|
|
2556
2572
|
'int': 'bool',
|
2557
2573
|
'float': 'bool',
|
2558
2574
|
'numeric': 'bool',
|
2575
|
+
'guid': 'object',
|
2559
2576
|
}
|
2560
2577
|
if self.flavor == 'oracle':
|
2561
2578
|
pd_db_df_aliases['int'] = 'numeric'
|
@@ -2609,7 +2626,6 @@ def get_alter_columns_queries(
|
|
2609
2626
|
else:
|
2610
2627
|
numeric_cols.extend([col for col, typ in pipe.dtypes.items() if typ == 'numeric'])
|
2611
2628
|
|
2612
|
-
pipe_dtypes = pipe.dtypes
|
2613
2629
|
numeric_type = get_db_type_from_pd_type('numeric', self.flavor, as_sqlalchemy=False)
|
2614
2630
|
text_type = get_db_type_from_pd_type('str', self.flavor, as_sqlalchemy=False)
|
2615
2631
|
altered_cols_types = {
|