wcp-library 1.2.5__py3-none-any.whl → 1.2.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.
- wcp_library/async_sql/oracle.py +22 -8
- wcp_library/async_sql/postgres.py +22 -0
- wcp_library/sql/oracle.py +22 -8
- wcp_library/sql/postgres.py +24 -9
- {wcp_library-1.2.5.dist-info → wcp_library-1.2.7.dist-info}/METADATA +1 -1
- {wcp_library-1.2.5.dist-info → wcp_library-1.2.7.dist-info}/RECORD +7 -7
- {wcp_library-1.2.5.dist-info → wcp_library-1.2.7.dist-info}/WHEEL +0 -0
wcp_library/async_sql/oracle.py
CHANGED
@@ -187,6 +187,28 @@ class AsyncOracleConnection(object):
|
|
187
187
|
rows = await cursor.fetchall()
|
188
188
|
return rows
|
189
189
|
|
190
|
+
@retry
|
191
|
+
async def remove_matching_data(self, dfObj: pd.DataFrame, outputTableName: str, match_cols: list) -> None:
|
192
|
+
"""
|
193
|
+
Remove matching data from the warehouse
|
194
|
+
|
195
|
+
:param dfObj: DataFrame
|
196
|
+
:param outputTableName: output table name
|
197
|
+
:param match_cols: list of columns
|
198
|
+
:return: None
|
199
|
+
"""
|
200
|
+
|
201
|
+
df = dfObj[match_cols]
|
202
|
+
match_cols = ', '.join(match_cols)
|
203
|
+
param_list = []
|
204
|
+
for column in match_cols:
|
205
|
+
param_list.append(f"{column} = :{column}")
|
206
|
+
params = ' AND '.join(param_list)
|
207
|
+
|
208
|
+
main_dict = df.to_dict('records')
|
209
|
+
query = f"""DELETE FROM {outputTableName} WHERE {params}"""
|
210
|
+
await self.execute_many(query, main_dict)
|
211
|
+
|
190
212
|
@retry
|
191
213
|
async def export_DF_to_warehouse(self, dfObj: pd.DataFrame, outputTableName: str, columns: list, remove_nan=False) -> None:
|
192
214
|
"""
|
@@ -209,14 +231,6 @@ class AsyncOracleConnection(object):
|
|
209
231
|
dfObj = dfObj.replace({np.nan: None})
|
210
232
|
main_dict = dfObj.to_dict('records')
|
211
233
|
|
212
|
-
# if remove_nan:
|
213
|
-
# for val, item in enumerate(main_dict):
|
214
|
-
# for sub_item, value in item.items():
|
215
|
-
# if pd.isna(value):
|
216
|
-
# main_dict[val][sub_item] = None
|
217
|
-
# else:
|
218
|
-
# main_dict[val][sub_item] = value
|
219
|
-
|
220
234
|
query = """INSERT INTO {} ({}) VALUES ({})""".format(outputTableName, col, bind)
|
221
235
|
await self.execute_many(query, main_dict)
|
222
236
|
|
@@ -170,6 +170,28 @@ class AsyncPostgresConnection(object):
|
|
170
170
|
rows = await cursor.fetchall()
|
171
171
|
return rows
|
172
172
|
|
173
|
+
@retry
|
174
|
+
async def remove_matching_data(self, dfObj: pd.DataFrame, outputTableName: str, match_cols: list) -> None:
|
175
|
+
"""
|
176
|
+
Remove matching data from the warehouse
|
177
|
+
|
178
|
+
:param dfObj: DataFrame
|
179
|
+
:param outputTableName: output table name
|
180
|
+
:param match_cols: list of columns
|
181
|
+
:return: None
|
182
|
+
"""
|
183
|
+
|
184
|
+
df = dfObj[match_cols]
|
185
|
+
match_cols = ', '.join(match_cols)
|
186
|
+
param_list = []
|
187
|
+
for column in match_cols:
|
188
|
+
param_list.append(f"{column} = %({column})s")
|
189
|
+
params = ' AND '.join(param_list)
|
190
|
+
|
191
|
+
main_dict = df.to_dict('records')
|
192
|
+
query = """DELETE FROM {} WHERE {}""".format(outputTableName, params)
|
193
|
+
await self.execute_many(query, main_dict)
|
194
|
+
|
173
195
|
@retry
|
174
196
|
async def export_DF_to_warehouse(self, dfObj: pd.DataFrame, outputTableName: str, columns: list, remove_nan=False) -> None:
|
175
197
|
"""
|
wcp_library/sql/oracle.py
CHANGED
@@ -191,6 +191,28 @@ class OracleConnection(object):
|
|
191
191
|
self._session_pool.release(connection)
|
192
192
|
return rows
|
193
193
|
|
194
|
+
@retry
|
195
|
+
def remove_matching_data(self, dfObj: pd.DataFrame, outputTableName: str, match_cols: list) -> None:
|
196
|
+
"""
|
197
|
+
Remove matching data from the warehouse
|
198
|
+
|
199
|
+
:param dfObj: DataFrame
|
200
|
+
:param outputTableName: output table name
|
201
|
+
:param match_cols: list of columns
|
202
|
+
:return: None
|
203
|
+
"""
|
204
|
+
|
205
|
+
df = dfObj[match_cols]
|
206
|
+
match_cols = ', '.join(match_cols)
|
207
|
+
param_list = []
|
208
|
+
for column in match_cols:
|
209
|
+
param_list.append(f"{column} = :{column}")
|
210
|
+
params = ' AND '.join(param_list)
|
211
|
+
|
212
|
+
main_dict = df.to_dict('records')
|
213
|
+
query = f"""DELETE FROM {outputTableName} WHERE {params}"""
|
214
|
+
self.execute_many(query, main_dict)
|
215
|
+
|
194
216
|
@retry
|
195
217
|
def export_DF_to_warehouse(self, dfObj: pd.DataFrame, outputTableName: str, columns: list, remove_nan=False) -> None:
|
196
218
|
"""
|
@@ -213,14 +235,6 @@ class OracleConnection(object):
|
|
213
235
|
dfObj = dfObj.replace({np.nan: None})
|
214
236
|
main_dict = dfObj.to_dict('records')
|
215
237
|
|
216
|
-
# if remove_nan:
|
217
|
-
# for val, item in enumerate(main_dict):
|
218
|
-
# for sub_item, value in item.items():
|
219
|
-
# if pd.isna(value):
|
220
|
-
# main_dict[val][sub_item] = None
|
221
|
-
# else:
|
222
|
-
# main_dict[val][sub_item] = value
|
223
|
-
|
224
238
|
query = """INSERT INTO {} ({}) VALUES ({})""".format(outputTableName, col, bind)
|
225
239
|
self.execute_many(query, main_dict)
|
226
240
|
|
wcp_library/sql/postgres.py
CHANGED
@@ -149,7 +149,8 @@ class PostgresConnection(object):
|
|
149
149
|
"""
|
150
150
|
|
151
151
|
with self._session_pool.connection() as connection:
|
152
|
-
connection.
|
152
|
+
cursor = connection.cursor()
|
153
|
+
cursor.executemany(query, dictionary)
|
153
154
|
|
154
155
|
@retry
|
155
156
|
def fetch_data(self, query: SQL | str, packed_data=None):
|
@@ -170,6 +171,28 @@ class PostgresConnection(object):
|
|
170
171
|
rows = cursor.fetchall()
|
171
172
|
return rows
|
172
173
|
|
174
|
+
@retry
|
175
|
+
def remove_matching_data(self, dfObj: pd.DataFrame, outputTableName: str, match_cols: list) -> None:
|
176
|
+
"""
|
177
|
+
Remove matching data from the warehouse
|
178
|
+
|
179
|
+
:param dfObj: DataFrame
|
180
|
+
:param outputTableName: output table name
|
181
|
+
:param match_cols: list of columns
|
182
|
+
:return: None
|
183
|
+
"""
|
184
|
+
|
185
|
+
df = dfObj[match_cols]
|
186
|
+
match_cols = ', '.join(match_cols)
|
187
|
+
param_list = []
|
188
|
+
for column in match_cols:
|
189
|
+
param_list.append(f"{column} = %({column})s")
|
190
|
+
params = ' AND '.join(param_list)
|
191
|
+
|
192
|
+
main_dict = df.to_dict('records')
|
193
|
+
query = """DELETE FROM {} WHERE {}""".format(outputTableName, params)
|
194
|
+
self.execute_many(query, main_dict)
|
195
|
+
|
173
196
|
@retry
|
174
197
|
def export_DF_to_warehouse(self, dfObj: pd.DataFrame, outputTableName: str, columns: list, remove_nan=False) -> None:
|
175
198
|
"""
|
@@ -192,14 +215,6 @@ class PostgresConnection(object):
|
|
192
215
|
dfObj = dfObj.replace({np.nan: None})
|
193
216
|
main_dict = dfObj.to_dict('records')
|
194
217
|
|
195
|
-
# if remove_nan:
|
196
|
-
# for val, item in enumerate(main_dict):
|
197
|
-
# for sub_item, value in item.items():
|
198
|
-
# if pd.isna(value):
|
199
|
-
# main_dict[val][sub_item] = None
|
200
|
-
# else:
|
201
|
-
# main_dict[val][sub_item] = value
|
202
|
-
|
203
218
|
query = """INSERT INTO {} ({}) VALUES ({})""".format(outputTableName, col, params)
|
204
219
|
self.execute_many(query, main_dict)
|
205
220
|
|
@@ -4,8 +4,8 @@ wcp_library/async_credentials/api.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZ
|
|
4
4
|
wcp_library/async_credentials/oracle.py,sha256=MvC7wsHnSyAyPGnRVlH0dvvW2xk5ap_IAByoHX4rUWY,5436
|
5
5
|
wcp_library/async_credentials/postgres.py,sha256=3wjqtLH0Nc-U80iscYnz5DV-9M2X4IjPW51C5MI2_tI,5297
|
6
6
|
wcp_library/async_sql/__init__.py,sha256=m4eWmUGYUEDomhhOp1ScB2uSIXFsNUNO589o5RwWdyM,1035
|
7
|
-
wcp_library/async_sql/oracle.py,sha256=
|
8
|
-
wcp_library/async_sql/postgres.py,sha256=
|
7
|
+
wcp_library/async_sql/oracle.py,sha256=TyKiArqbAR3b2cd2933UuH_EhnOx6he90yVVsQnrtjU,7923
|
8
|
+
wcp_library/async_sql/postgres.py,sha256=HTCyJUvGHedmU_KKh756MSMZxzsxe8GLCrJpWITDaQU,7451
|
9
9
|
wcp_library/credentials/__init__.py,sha256=HRmg7mqcATeclIz3lZQjSR4nmK6aY6MK9-QXEYZoFrw,1857
|
10
10
|
wcp_library/credentials/ftp.py,sha256=FRxKVWifz7olQIrSjDgkTqk7rmc7Zdwmkfq7b62DQY8,4965
|
11
11
|
wcp_library/credentials/oracle.py,sha256=IJVGd10LH5LUNKUSFAbApi0sjR1AbloMJRHTuR9zFrQ,5095
|
@@ -18,8 +18,8 @@ wcp_library/informatica.py,sha256=IXZtk_9X1XLbOEwFrsyOwTgajQKvtXgANBHmuTOP3Kk,40
|
|
18
18
|
wcp_library/logging.py,sha256=e6gG7HFgUrMajUZs4Gs0atFfOJJmdmxN0GerfynNWlY,2061
|
19
19
|
wcp_library/selenium_helper.py,sha256=rlphTXsUgnbaXZknY5nfQqxFhnc7UmrpzhV3hQ-cv7k,2509
|
20
20
|
wcp_library/sql/__init__.py,sha256=CLlBEBrWVAwE79bUxuQiwikSrYH8m9QRYSJ2l0-ofsY,1003
|
21
|
-
wcp_library/sql/oracle.py,sha256=
|
22
|
-
wcp_library/sql/postgres.py,sha256=
|
23
|
-
wcp_library-1.2.
|
24
|
-
wcp_library-1.2.
|
25
|
-
wcp_library-1.2.
|
21
|
+
wcp_library/sql/oracle.py,sha256=hAnjn6lBYVjH10LI4x7KMd7dVmPONOHa9PQx6tvhc1U,7744
|
22
|
+
wcp_library/sql/postgres.py,sha256=jHI7auaB2BYzaL1ztauFwIJP79M7ox6UyYJgqo73GDw,7048
|
23
|
+
wcp_library-1.2.7.dist-info/METADATA,sha256=mo5dHBapD5bG3q5b16fU5JYLOGOwKnJvTuXZBt6vqmY,1513
|
24
|
+
wcp_library-1.2.7.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
|
25
|
+
wcp_library-1.2.7.dist-info/RECORD,,
|
File without changes
|