mostlyai 5.4.2__tar.gz → 5.5.0__tar.gz
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.
- {mostlyai-5.4.2 → mostlyai-5.5.0}/PKG-INFO +3 -3
- {mostlyai-5.4.2 → mostlyai-5.5.0}/mostlyai/sdk/__init__.py +1 -1
- {mostlyai-5.4.2 → mostlyai-5.5.0}/mostlyai/sdk/_data/db/base.py +45 -32
- {mostlyai-5.4.2 → mostlyai-5.5.0}/mostlyai/sdk/_data/db/bigquery.py +1 -1
- {mostlyai-5.4.2 → mostlyai-5.5.0}/mostlyai/sdk/_data/db/databricks.py +9 -9
- {mostlyai-5.4.2 → mostlyai-5.5.0}/mostlyai/sdk/_data/db/redshift.py +3 -3
- {mostlyai-5.4.2 → mostlyai-5.5.0}/mostlyai/sdk/_data/non_context.py +244 -237
- {mostlyai-5.4.2 → mostlyai-5.5.0}/mostlyai/sdk/_local/execution/jobs.py +7 -1
- {mostlyai-5.4.2 → mostlyai-5.5.0}/mostlyai/sdk/_local/execution/plan.py +12 -2
- {mostlyai-5.4.2 → mostlyai-5.5.0}/mostlyai/sdk/_local/execution/step_finalize_generation.py +78 -98
- {mostlyai-5.4.2 → mostlyai-5.5.0}/mostlyai/sdk/_local/execution/step_finalize_training.py +49 -30
- {mostlyai-5.4.2 → mostlyai-5.5.0}/mostlyai/sdk/_local/execution/step_pull_training_data.py +5 -1
- {mostlyai-5.4.2 → mostlyai-5.5.0}/mostlyai/sdk/_local/generators.py +11 -9
- {mostlyai-5.4.2 → mostlyai-5.5.0}/mostlyai/sdk/client/api.py +6 -3
- {mostlyai-5.4.2 → mostlyai-5.5.0}/pyproject.toml +3 -3
- {mostlyai-5.4.2 → mostlyai-5.5.0}/.gitignore +0 -0
- {mostlyai-5.4.2 → mostlyai-5.5.0}/LICENSE +0 -0
- {mostlyai-5.4.2 → mostlyai-5.5.0}/README.md +0 -0
- {mostlyai-5.4.2 → mostlyai-5.5.0}/mostlyai/sdk/_data/__init__.py +0 -0
- {mostlyai-5.4.2 → mostlyai-5.5.0}/mostlyai/sdk/_data/auto_detect.py +0 -0
- {mostlyai-5.4.2 → mostlyai-5.5.0}/mostlyai/sdk/_data/base.py +0 -0
- {mostlyai-5.4.2 → mostlyai-5.5.0}/mostlyai/sdk/_data/context.py +0 -0
- {mostlyai-5.4.2 → mostlyai-5.5.0}/mostlyai/sdk/_data/conversions.py +0 -0
- {mostlyai-5.4.2 → mostlyai-5.5.0}/mostlyai/sdk/_data/db/__init__.py +0 -0
- {mostlyai-5.4.2 → mostlyai-5.5.0}/mostlyai/sdk/_data/db/hive.py +0 -0
- {mostlyai-5.4.2 → mostlyai-5.5.0}/mostlyai/sdk/_data/db/mssql.py +0 -0
- {mostlyai-5.4.2 → mostlyai-5.5.0}/mostlyai/sdk/_data/db/mysql.py +0 -0
- {mostlyai-5.4.2 → mostlyai-5.5.0}/mostlyai/sdk/_data/db/oracle.py +0 -0
- {mostlyai-5.4.2 → mostlyai-5.5.0}/mostlyai/sdk/_data/db/postgresql.py +0 -0
- {mostlyai-5.4.2 → mostlyai-5.5.0}/mostlyai/sdk/_data/db/snowflake.py +0 -0
- {mostlyai-5.4.2 → mostlyai-5.5.0}/mostlyai/sdk/_data/db/sqlite.py +0 -0
- {mostlyai-5.4.2 → mostlyai-5.5.0}/mostlyai/sdk/_data/db/types_coercion.py +0 -0
- {mostlyai-5.4.2 → mostlyai-5.5.0}/mostlyai/sdk/_data/dtype.py +0 -0
- {mostlyai-5.4.2 → mostlyai-5.5.0}/mostlyai/sdk/_data/exceptions.py +0 -0
- {mostlyai-5.4.2 → mostlyai-5.5.0}/mostlyai/sdk/_data/file/__init__.py +0 -0
- {mostlyai-5.4.2 → mostlyai-5.5.0}/mostlyai/sdk/_data/file/base.py +0 -0
- {mostlyai-5.4.2 → mostlyai-5.5.0}/mostlyai/sdk/_data/file/container/__init__.py +0 -0
- {mostlyai-5.4.2 → mostlyai-5.5.0}/mostlyai/sdk/_data/file/container/aws.py +0 -0
- {mostlyai-5.4.2 → mostlyai-5.5.0}/mostlyai/sdk/_data/file/container/azure.py +0 -0
- {mostlyai-5.4.2 → mostlyai-5.5.0}/mostlyai/sdk/_data/file/container/bucket_based.py +0 -0
- {mostlyai-5.4.2 → mostlyai-5.5.0}/mostlyai/sdk/_data/file/container/gcs.py +0 -0
- {mostlyai-5.4.2 → mostlyai-5.5.0}/mostlyai/sdk/_data/file/container/minio.py +0 -0
- {mostlyai-5.4.2 → mostlyai-5.5.0}/mostlyai/sdk/_data/file/table/__init__.py +0 -0
- {mostlyai-5.4.2 → mostlyai-5.5.0}/mostlyai/sdk/_data/file/table/csv.py +0 -0
- {mostlyai-5.4.2 → mostlyai-5.5.0}/mostlyai/sdk/_data/file/table/feather.py +0 -0
- {mostlyai-5.4.2 → mostlyai-5.5.0}/mostlyai/sdk/_data/file/table/json.py +0 -0
- {mostlyai-5.4.2 → mostlyai-5.5.0}/mostlyai/sdk/_data/file/table/parquet.py +0 -0
- {mostlyai-5.4.2 → mostlyai-5.5.0}/mostlyai/sdk/_data/file/utils.py +0 -0
- {mostlyai-5.4.2 → mostlyai-5.5.0}/mostlyai/sdk/_data/language_model.py +0 -0
- {mostlyai-5.4.2 → mostlyai-5.5.0}/mostlyai/sdk/_data/metadata_objects.py +0 -0
- {mostlyai-5.4.2 → mostlyai-5.5.0}/mostlyai/sdk/_data/progress_callback.py +0 -0
- {mostlyai-5.4.2 → mostlyai-5.5.0}/mostlyai/sdk/_data/pull.py +0 -0
- {mostlyai-5.4.2 → mostlyai-5.5.0}/mostlyai/sdk/_data/pull_context.py +0 -0
- {mostlyai-5.4.2 → mostlyai-5.5.0}/mostlyai/sdk/_data/pull_utils.py +0 -0
- {mostlyai-5.4.2 → mostlyai-5.5.0}/mostlyai/sdk/_data/push.py +0 -0
- {mostlyai-5.4.2 → mostlyai-5.5.0}/mostlyai/sdk/_data/util/__init__.py +0 -0
- {mostlyai-5.4.2 → mostlyai-5.5.0}/mostlyai/sdk/_data/util/common.py +0 -0
- {mostlyai-5.4.2 → mostlyai-5.5.0}/mostlyai/sdk/_data/util/kerberos.py +0 -0
- {mostlyai-5.4.2 → mostlyai-5.5.0}/mostlyai/sdk/_local/__init__.py +0 -0
- {mostlyai-5.4.2 → mostlyai-5.5.0}/mostlyai/sdk/_local/cli.py +0 -0
- {mostlyai-5.4.2 → mostlyai-5.5.0}/mostlyai/sdk/_local/connectors.py +0 -0
- {mostlyai-5.4.2 → mostlyai-5.5.0}/mostlyai/sdk/_local/execution/__init__.py +0 -0
- {mostlyai-5.4.2 → mostlyai-5.5.0}/mostlyai/sdk/_local/execution/migration.py +0 -0
- {mostlyai-5.4.2 → mostlyai-5.5.0}/mostlyai/sdk/_local/execution/step_analyze_training_data.py +0 -0
- {mostlyai-5.4.2 → mostlyai-5.5.0}/mostlyai/sdk/_local/execution/step_create_data_report.py +0 -0
- {mostlyai-5.4.2 → mostlyai-5.5.0}/mostlyai/sdk/_local/execution/step_create_model_report.py +0 -0
- {mostlyai-5.4.2 → mostlyai-5.5.0}/mostlyai/sdk/_local/execution/step_deliver_data.py +0 -0
- {mostlyai-5.4.2 → mostlyai-5.5.0}/mostlyai/sdk/_local/execution/step_encode_training_data.py +0 -0
- {mostlyai-5.4.2 → mostlyai-5.5.0}/mostlyai/sdk/_local/execution/step_generate_data.py +0 -0
- {mostlyai-5.4.2 → mostlyai-5.5.0}/mostlyai/sdk/_local/execution/step_generate_model_report_data.py +0 -0
- {mostlyai-5.4.2 → mostlyai-5.5.0}/mostlyai/sdk/_local/execution/step_train_model.py +0 -0
- {mostlyai-5.4.2 → mostlyai-5.5.0}/mostlyai/sdk/_local/progress.py +0 -0
- {mostlyai-5.4.2 → mostlyai-5.5.0}/mostlyai/sdk/_local/routes.py +0 -0
- {mostlyai-5.4.2 → mostlyai-5.5.0}/mostlyai/sdk/_local/server.py +0 -0
- {mostlyai-5.4.2 → mostlyai-5.5.0}/mostlyai/sdk/_local/storage.py +0 -0
- {mostlyai-5.4.2 → mostlyai-5.5.0}/mostlyai/sdk/_local/synthetic_datasets.py +0 -0
- {mostlyai-5.4.2 → mostlyai-5.5.0}/mostlyai/sdk/client/__init__.py +0 -0
- {mostlyai-5.4.2 → mostlyai-5.5.0}/mostlyai/sdk/client/_base_utils.py +0 -0
- {mostlyai-5.4.2 → mostlyai-5.5.0}/mostlyai/sdk/client/_naming_conventions.py +0 -0
- {mostlyai-5.4.2 → mostlyai-5.5.0}/mostlyai/sdk/client/_utils.py +0 -0
- {mostlyai-5.4.2 → mostlyai-5.5.0}/mostlyai/sdk/client/artifacts.py +0 -0
- {mostlyai-5.4.2 → mostlyai-5.5.0}/mostlyai/sdk/client/base.py +0 -0
- {mostlyai-5.4.2 → mostlyai-5.5.0}/mostlyai/sdk/client/connectors.py +0 -0
- {mostlyai-5.4.2 → mostlyai-5.5.0}/mostlyai/sdk/client/datasets.py +0 -0
- {mostlyai-5.4.2 → mostlyai-5.5.0}/mostlyai/sdk/client/exceptions.py +0 -0
- {mostlyai-5.4.2 → mostlyai-5.5.0}/mostlyai/sdk/client/generators.py +0 -0
- {mostlyai-5.4.2 → mostlyai-5.5.0}/mostlyai/sdk/client/synthetic_datasets.py +0 -0
- {mostlyai-5.4.2 → mostlyai-5.5.0}/mostlyai/sdk/domain.py +0 -0
- {mostlyai-5.4.2 → mostlyai-5.5.0}/mostlyai/sdk/py.typed +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: mostlyai
|
|
3
|
-
Version: 5.
|
|
3
|
+
Version: 5.5.0
|
|
4
4
|
Summary: Synthetic Data SDK
|
|
5
5
|
Project-URL: homepage, https://app.mostly.ai/
|
|
6
6
|
Project-URL: repository, https://github.com/mostly-ai/mostlyai
|
|
@@ -60,7 +60,7 @@ Requires-Dist: fastapi<0.116,>=0.115.6; extra == 'local'
|
|
|
60
60
|
Requires-Dist: filelock>=3.16.1; extra == 'local'
|
|
61
61
|
Requires-Dist: gcsfs>=2023.1.0; extra == 'local'
|
|
62
62
|
Requires-Dist: joblib>=1.4.2; extra == 'local'
|
|
63
|
-
Requires-Dist: mostlyai-engine==1.
|
|
63
|
+
Requires-Dist: mostlyai-engine==1.7.0; extra == 'local'
|
|
64
64
|
Requires-Dist: mostlyai-qa==1.9.8; extra == 'local'
|
|
65
65
|
Requires-Dist: networkx<4,>=3.0; extra == 'local'
|
|
66
66
|
Requires-Dist: openpyxl>=3.1.5; extra == 'local'
|
|
@@ -82,7 +82,7 @@ Requires-Dist: fastapi<0.116,>=0.115.6; extra == 'local-gpu'
|
|
|
82
82
|
Requires-Dist: filelock>=3.16.1; extra == 'local-gpu'
|
|
83
83
|
Requires-Dist: gcsfs>=2023.1.0; extra == 'local-gpu'
|
|
84
84
|
Requires-Dist: joblib>=1.4.2; extra == 'local-gpu'
|
|
85
|
-
Requires-Dist: mostlyai-engine[gpu]==1.
|
|
85
|
+
Requires-Dist: mostlyai-engine[gpu]==1.7.0; extra == 'local-gpu'
|
|
86
86
|
Requires-Dist: mostlyai-qa==1.9.8; extra == 'local-gpu'
|
|
87
87
|
Requires-Dist: networkx<4,>=3.0; extra == 'local-gpu'
|
|
88
88
|
Requires-Dist: openpyxl>=3.1.5; extra == 'local-gpu'
|
|
@@ -49,4 +49,4 @@ For more information, visit: https://mostly-ai.github.io/mostlyai/
|
|
|
49
49
|
from mostlyai.sdk.client.api import MostlyAI
|
|
50
50
|
|
|
51
51
|
__all__ = ["MostlyAI"]
|
|
52
|
-
__version__ = "5.
|
|
52
|
+
__version__ = "5.5.0" # Do not set this manually. Use poetry version [params].
|
|
@@ -877,6 +877,7 @@ class SqlAlchemyTable(DBTable, abc.ABC):
|
|
|
877
877
|
def __init__(self, *args, **kwargs):
|
|
878
878
|
self.is_view = kwargs.get("is_view", False)
|
|
879
879
|
self.lazy_fetch_primary_key = kwargs.get("lazy_fetch_primary_key", True)
|
|
880
|
+
self.name_in_db = kwargs.get("name_in_db") # actual db table name, may differ from self.name
|
|
880
881
|
super().__init__(*args, **kwargs)
|
|
881
882
|
|
|
882
883
|
def __repr__(self):
|
|
@@ -896,11 +897,16 @@ class SqlAlchemyTable(DBTable, abc.ABC):
|
|
|
896
897
|
|
|
897
898
|
#################### READ QUERY BUILDING & UTILS ####################
|
|
898
899
|
|
|
900
|
+
@property
|
|
901
|
+
def db_table_name(self) -> str:
|
|
902
|
+
# use name_in_db (actual db table name) if set, otherwise fall back to self.name
|
|
903
|
+
return self.name_in_db or self.name
|
|
904
|
+
|
|
899
905
|
@property
|
|
900
906
|
def _sa_table(self):
|
|
901
907
|
with self.container.use_sa_engine() as sa_engine:
|
|
902
908
|
return sa.Table(
|
|
903
|
-
self.
|
|
909
|
+
self.db_table_name,
|
|
904
910
|
self.container.sa_metadata,
|
|
905
911
|
autoload_with=sa_engine,
|
|
906
912
|
)
|
|
@@ -1129,34 +1135,41 @@ class SqlAlchemyTable(DBTable, abc.ABC):
|
|
|
1129
1135
|
chunk_idx = 0
|
|
1130
1136
|
total_time = 0
|
|
1131
1137
|
session = sessionmaker(bind=sa_engine)()
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1138
|
+
results_generator = None
|
|
1139
|
+
try:
|
|
1140
|
+
conn = session.connection()
|
|
1141
|
+
results_generator = pd.read_sql_query(stmt, conn, dtype_backend="pyarrow", chunksize=fetch_chunk_size)
|
|
1142
|
+
chunks_df = pd.DataFrame()
|
|
1143
|
+
for chunk_df in results_generator:
|
|
1144
|
+
t0 = time.time()
|
|
1145
|
+
if where is not None:
|
|
1146
|
+
where_column, where_values = next(iter(where.items()))
|
|
1147
|
+
chunk_df = chunk_df[chunk_df[where_column].isin(where_values)]
|
|
1148
|
+
if do_coerce_dtypes:
|
|
1149
|
+
chunk_df = coerce_dtypes_by_encoding(chunk_df, self.encoding_types)
|
|
1150
|
+
# accumulate chunks
|
|
1151
|
+
chunks_df = pd.concat([chunks_df, chunk_df], ignore_index=True)
|
|
1152
|
+
if len(chunks_df) >= yield_chunk_size:
|
|
1153
|
+
# yield data once it reaches the yield_chunk_size
|
|
1154
|
+
yield chunks_df
|
|
1155
|
+
chunks_df = pd.DataFrame()
|
|
1156
|
+
chunk_idx += 1
|
|
1157
|
+
total_time += time.time() - t0
|
|
1158
|
+
if chunk_idx % 10 == 0:
|
|
1159
|
+
_LOG.info(f"processed {chunk_idx} chunks in {total_time:.2f}s")
|
|
1160
|
+
if len(chunks_df) > 0 or len(chunks_df.columns) > 0:
|
|
1161
|
+
# yield the remaining data
|
|
1146
1162
|
yield chunks_df
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
if
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
# yield the remaining data
|
|
1154
|
-
yield chunks_df
|
|
1155
|
-
_LOG.info(f"finished reading {chunk_idx} chunks in {time.time() - t00:.2f}s (strategy=scan)")
|
|
1163
|
+
_LOG.info(f"finished reading {chunk_idx} chunks in {time.time() - t00:.2f}s (strategy=scan)")
|
|
1164
|
+
finally:
|
|
1165
|
+
# explicitly close resources to prevent connection leaks
|
|
1166
|
+
if results_generator is not None:
|
|
1167
|
+
results_generator.close()
|
|
1168
|
+
session.close()
|
|
1156
1169
|
|
|
1157
1170
|
def is_column_indexed(self, column: str) -> bool:
|
|
1158
1171
|
with self.container.use_sa_engine() as sa_engine:
|
|
1159
|
-
indexes = sa.inspect(sa_engine).get_indexes(table_name=self.
|
|
1172
|
+
indexes = sa.inspect(sa_engine).get_indexes(table_name=self.db_table_name, schema=self.container.dbschema)
|
|
1160
1173
|
for index in indexes:
|
|
1161
1174
|
if column in index.get("column_names", []):
|
|
1162
1175
|
return True
|
|
@@ -1214,7 +1227,7 @@ class SqlAlchemyTable(DBTable, abc.ABC):
|
|
|
1214
1227
|
do_coerce_dtypes: bool | None = False,
|
|
1215
1228
|
) -> pd.DataFrame:
|
|
1216
1229
|
t0 = time.time()
|
|
1217
|
-
_LOG.info(f"read from table `{self.
|
|
1230
|
+
_LOG.info(f"read from table `{self.db_table_name}` started")
|
|
1218
1231
|
columns = columns if columns is not None else self.columns
|
|
1219
1232
|
stmt = self._sa_select(columns)
|
|
1220
1233
|
stmts = self._sa_where(stmt, where)
|
|
@@ -1232,7 +1245,7 @@ class SqlAlchemyTable(DBTable, abc.ABC):
|
|
|
1232
1245
|
df = self._df_limit(df, limit)
|
|
1233
1246
|
if do_coerce_dtypes:
|
|
1234
1247
|
df = coerce_dtypes_by_encoding(df, self.encoding_types)
|
|
1235
|
-
_LOG.info(f"read DB data `{self.
|
|
1248
|
+
_LOG.info(f"read DB data `{self.db_table_name}` {df.shape} in {time.time() - t0:.2f}s")
|
|
1236
1249
|
return df
|
|
1237
1250
|
|
|
1238
1251
|
def create_table(self, df: pd.DataFrame | None = None, **kwargs) -> None:
|
|
@@ -1245,7 +1258,7 @@ class SqlAlchemyTable(DBTable, abc.ABC):
|
|
|
1245
1258
|
with self.container.use_sa_engine(mode="write_data") as sa_engine:
|
|
1246
1259
|
try:
|
|
1247
1260
|
df.head(0).to_sql(
|
|
1248
|
-
name=self.
|
|
1261
|
+
name=self.db_table_name,
|
|
1249
1262
|
con=sa_engine,
|
|
1250
1263
|
schema=self.container.dbschema,
|
|
1251
1264
|
index=False,
|
|
@@ -1257,7 +1270,7 @@ class SqlAlchemyTable(DBTable, abc.ABC):
|
|
|
1257
1270
|
raise
|
|
1258
1271
|
|
|
1259
1272
|
dtypes_msg = f"with dtypes=`{kwargs['dtype']}`" if "dtype" in kwargs else ""
|
|
1260
|
-
_LOG.info(f"Successfully created table `{self.
|
|
1273
|
+
_LOG.info(f"Successfully created table `{self.db_table_name}` schema {dtypes_msg}")
|
|
1261
1274
|
|
|
1262
1275
|
def write_chunks(self, chunks: Iterable[pd.DataFrame], dtypes: dict[str, Any], **kwargs) -> None:
|
|
1263
1276
|
_LOG.info(f"write data in {len(chunks)} chunks (n_jobs={self.WRITE_CHUNKS_N_JOBS})")
|
|
@@ -1269,7 +1282,7 @@ class SqlAlchemyTable(DBTable, abc.ABC):
|
|
|
1269
1282
|
sa_create_engine_kwargs=self.container.sa_create_engine_kwargs,
|
|
1270
1283
|
sa_create_engine_connect_kwargs=self.container.sa_engine_connection_kwargs,
|
|
1271
1284
|
sa_multiple_inserts=self.SA_MULTIPLE_INSERTS,
|
|
1272
|
-
table_name=self.
|
|
1285
|
+
table_name=self.db_table_name,
|
|
1273
1286
|
table_schema=self.container.dbschema,
|
|
1274
1287
|
table_dtypes=dtypes,
|
|
1275
1288
|
chunk_init=self.INIT_WRITE_CHUNK,
|
|
@@ -1289,7 +1302,7 @@ class SqlAlchemyTable(DBTable, abc.ABC):
|
|
|
1289
1302
|
) -> None:
|
|
1290
1303
|
t0 = time.time()
|
|
1291
1304
|
assert self.is_output
|
|
1292
|
-
_LOG.info(f"write data {df.shape} to table `{self.
|
|
1305
|
+
_LOG.info(f"write data {df.shape} to table `{self.db_table_name}` started")
|
|
1293
1306
|
|
|
1294
1307
|
df = _normalize_for_sql(df)
|
|
1295
1308
|
|
|
@@ -1306,7 +1319,7 @@ class SqlAlchemyTable(DBTable, abc.ABC):
|
|
|
1306
1319
|
chunks = [df[i : i + write_chunk_size] for i in range(0, len(df), write_chunk_size)]
|
|
1307
1320
|
self.write_chunks(chunks, dtypes)
|
|
1308
1321
|
|
|
1309
|
-
_LOG.info(f"write to table `{self.
|
|
1322
|
+
_LOG.info(f"write to table `{self.db_table_name}` finished in {time.time() - t0:.2f}s")
|
|
1310
1323
|
|
|
1311
1324
|
def has_child(self) -> bool:
|
|
1312
1325
|
return len(self.container.schema.get_relations_from_table(str(self.name))) > 0
|
|
@@ -211,7 +211,7 @@ class BigQueryTable(SqlAlchemyTable):
|
|
|
211
211
|
_write_chunk,
|
|
212
212
|
credentials_info=self.container.sa_create_engine_kwargs["credentials_info"],
|
|
213
213
|
dataframe=chunk,
|
|
214
|
-
table_id=f"{self.container.dbschema}.{self.
|
|
214
|
+
table_id=f"{self.container.dbschema}.{self.db_table_name}",
|
|
215
215
|
if_exists=True,
|
|
216
216
|
)
|
|
217
217
|
|
|
@@ -282,7 +282,7 @@ class DatabricksTable(SqlAlchemyTable):
|
|
|
282
282
|
if_exists = kwargs.get("if_exists", "append")
|
|
283
283
|
with self.container.init_sa_connection() as connection:
|
|
284
284
|
cursor = connection.connection.cursor()
|
|
285
|
-
cursor.columns(schema_name=self.container.dbschema, table_name=self.
|
|
285
|
+
cursor.columns(schema_name=self.container.dbschema, table_name=self.db_table_name)
|
|
286
286
|
result = cursor.fetchall()
|
|
287
287
|
if result: # the table already exists
|
|
288
288
|
if if_exists == "replace":
|
|
@@ -291,9 +291,9 @@ class DatabricksTable(SqlAlchemyTable):
|
|
|
291
291
|
elif if_exists == "fail":
|
|
292
292
|
raise MostlyDataException("Destination location already exists.")
|
|
293
293
|
# create an empty table without schema
|
|
294
|
-
query = f"CREATE TABLE IF NOT EXISTS {self.container.dbname}.{self.container.dbschema}.{self.
|
|
294
|
+
query = f"CREATE TABLE IF NOT EXISTS {self.container.dbname}.{self.container.dbschema}.{self.db_table_name}"
|
|
295
295
|
cursor.execute(query)
|
|
296
|
-
_LOG.info(f"created table `{self.
|
|
296
|
+
_LOG.info(f"created table `{self.db_table_name}` under schema `{self.container.dbschema}`")
|
|
297
297
|
|
|
298
298
|
def create_volume(self, volume_name) -> None:
|
|
299
299
|
self.drop_volume_if_exists(volume_name)
|
|
@@ -307,20 +307,20 @@ class DatabricksTable(SqlAlchemyTable):
|
|
|
307
307
|
_LOG.info(f"dropped temporary volume `{volume_name}` if existed")
|
|
308
308
|
|
|
309
309
|
def drop_table_if_exists(self) -> None:
|
|
310
|
-
query = f"DROP TABLE IF EXISTS {self.container.dbname}.{self.container.dbschema}.{self.
|
|
310
|
+
query = f"DROP TABLE IF EXISTS {self.container.dbname}.{self.container.dbschema}.{self.db_table_name};"
|
|
311
311
|
self._execute(query)
|
|
312
|
-
_LOG.info(f"dropped table `{self.
|
|
312
|
+
_LOG.info(f"dropped table `{self.db_table_name}` if existed")
|
|
313
313
|
|
|
314
314
|
def copy_data_from_volume_to_table(self, volume_name: str) -> None:
|
|
315
315
|
query = (
|
|
316
|
-
f"COPY INTO {self.container.dbname}.{self.container.dbschema}.{self.
|
|
316
|
+
f"COPY INTO {self.container.dbname}.{self.container.dbschema}.{self.db_table_name} "
|
|
317
317
|
f"FROM '/Volumes/{self.container.dbname}/{self.container.dbschema}/{volume_name}/' "
|
|
318
318
|
"FILEFORMAT = PARQUET "
|
|
319
319
|
"FORMAT_OPTIONS ('inferSchema' = 'true') "
|
|
320
320
|
"COPY_OPTIONS ('mergeSchema' = 'true');"
|
|
321
321
|
)
|
|
322
322
|
self._execute(query)
|
|
323
|
-
_LOG.info(f"copied data from volume `{volume_name}` to table `{self.
|
|
323
|
+
_LOG.info(f"copied data from volume `{volume_name}` to table `{self.db_table_name}`")
|
|
324
324
|
|
|
325
325
|
def write_data(
|
|
326
326
|
self,
|
|
@@ -330,7 +330,7 @@ class DatabricksTable(SqlAlchemyTable):
|
|
|
330
330
|
) -> None:
|
|
331
331
|
t0 = time.time()
|
|
332
332
|
assert self.is_output
|
|
333
|
-
_LOG.info(f"write data {df.shape} to table `{self.
|
|
333
|
+
_LOG.info(f"write data {df.shape} to table `{self.db_table_name}` started")
|
|
334
334
|
# include a unique timestamp in the volume name to avoid conflicts
|
|
335
335
|
volume_name = f"{self.name}_temp_{time.time_ns()}"
|
|
336
336
|
try:
|
|
@@ -340,7 +340,7 @@ class DatabricksTable(SqlAlchemyTable):
|
|
|
340
340
|
self.write_data_to_volume(df=df, volume_name=volume_name)
|
|
341
341
|
self.copy_data_from_volume_to_table(volume_name)
|
|
342
342
|
|
|
343
|
-
_LOG.info(f"write to table `{self.
|
|
343
|
+
_LOG.info(f"write to table `{self.db_table_name}` finished in {time.time() - t0:.2f}s")
|
|
344
344
|
except Exception as e:
|
|
345
345
|
if if_exists != "append":
|
|
346
346
|
self.drop_table_if_exists()
|
|
@@ -379,9 +379,9 @@ class RedshiftTable(PostgresqlTable):
|
|
|
379
379
|
available_tables = inspector.get_table_names(schema=schema)
|
|
380
380
|
|
|
381
381
|
# redshift dialect's has_table is case-insensitive, so match accordingly
|
|
382
|
-
actual_table_name = self.
|
|
382
|
+
actual_table_name = self.db_table_name
|
|
383
383
|
for table in available_tables:
|
|
384
|
-
if table.lower() == self.
|
|
384
|
+
if table.lower() == self.db_table_name.lower():
|
|
385
385
|
actual_table_name = table
|
|
386
386
|
break
|
|
387
387
|
|
|
@@ -407,7 +407,7 @@ class RedshiftTable(PostgresqlTable):
|
|
|
407
407
|
|
|
408
408
|
# find table case-insensitively and drop using sqlalchemy
|
|
409
409
|
for t in existing_tables:
|
|
410
|
-
if t.lower() == self.
|
|
410
|
+
if t.lower() == self.db_table_name.lower():
|
|
411
411
|
# use sqlalchemy Table object for safe drop operation
|
|
412
412
|
table_to_drop = sa.Table(t, sa.MetaData(), schema=schema)
|
|
413
413
|
table_to_drop.drop(sa_engine, checkfirst=False)
|