omnata-plugin-runtime 0.3.21a64__py3-none-any.whl → 0.3.23a69__py3-none-any.whl
Sign up to get free protection for your applications and to get access to all the features.
- omnata_plugin_runtime/omnata_plugin.py +52 -20
- {omnata_plugin_runtime-0.3.21a64.dist-info → omnata_plugin_runtime-0.3.23a69.dist-info}/METADATA +1 -1
- {omnata_plugin_runtime-0.3.21a64.dist-info → omnata_plugin_runtime-0.3.23a69.dist-info}/RECORD +5 -5
- {omnata_plugin_runtime-0.3.21a64.dist-info → omnata_plugin_runtime-0.3.23a69.dist-info}/LICENSE +0 -0
- {omnata_plugin_runtime-0.3.21a64.dist-info → omnata_plugin_runtime-0.3.23a69.dist-info}/WHEEL +0 -0
@@ -20,6 +20,7 @@ import json
|
|
20
20
|
import queue
|
21
21
|
import threading
|
22
22
|
import time
|
23
|
+
import hashlib
|
23
24
|
from abc import ABC, abstractmethod
|
24
25
|
from decimal import Decimal
|
25
26
|
from functools import partial, wraps, reduce
|
@@ -1181,29 +1182,50 @@ class InboundSyncRequest(SyncRequest):
|
|
1181
1182
|
else:
|
1182
1183
|
results_df["APP_IDENTIFIER"] = None
|
1183
1184
|
if primary_key_field is not None:
|
1184
|
-
|
1185
|
-
|
1186
|
-
|
1187
|
-
|
1188
|
-
|
1189
|
-
|
1190
|
-
|
1191
|
-
|
1192
|
-
|
1193
|
-
|
1194
|
-
|
1195
|
-
for
|
1196
|
-
)
|
1185
|
+
if isinstance(primary_key_field,list) and len(primary_key_field) == 1:
|
1186
|
+
# don't hash it if it's just a single value
|
1187
|
+
primary_key_field = primary_key_field[0]
|
1188
|
+
if isinstance(primary_key_field,list):
|
1189
|
+
primary_key_fields = cast(List[str],primary_key_field)
|
1190
|
+
primary_key_fields = sorted(primary_key_fields)
|
1191
|
+
# handle the sitation where the primary key is a list of fields
|
1192
|
+
# first, check that all records contain all of the primary key fields
|
1193
|
+
if not all(
|
1194
|
+
all(
|
1195
|
+
field in record["RECORD_DATA"]
|
1196
|
+
for field in primary_key_fields
|
1197
|
+
)
|
1198
|
+
for record in records
|
1199
|
+
):
|
1200
|
+
raise ValueError(
|
1201
|
+
f"Primary key fields '{primary_key_fields}' were not present in all records for stream {stream_name}"
|
1202
|
+
)
|
1203
|
+
# hash all of the primary key fields
|
1204
|
+
results_df["APP_IDENTIFIER"] = results_df["RECORD_DATA"].apply(lambda x: self.get_hash([str(x[field]) for field in primary_key_fields]))
|
1205
|
+
else:
|
1206
|
+
# the primary key field could contain a nested field, so we need to check for that
|
1207
|
+
# we need to check that each record in the results contains the primary key field
|
1208
|
+
if not all(
|
1209
|
+
primary_key_field in record["RECORD_DATA"]
|
1210
|
+
for record in records
|
1211
|
+
):
|
1212
|
+
if "." in primary_key_field:
|
1213
|
+
primary_key_field = primary_key_field.split(".")
|
1214
|
+
|
1215
|
+
if not all(
|
1216
|
+
get_nested_value(record["RECORD_DATA"], primary_key_field)
|
1217
|
+
for record in records
|
1218
|
+
):
|
1219
|
+
raise ValueError(
|
1220
|
+
f"Primary key field '{primary_key_field}' was not present in all records for stream {stream_name}"
|
1221
|
+
)
|
1222
|
+
else:
|
1197
1223
|
raise ValueError(
|
1198
1224
|
f"Primary key field '{primary_key_field}' was not present in all records for stream {stream_name}"
|
1199
1225
|
)
|
1200
|
-
|
1201
|
-
|
1202
|
-
|
1203
|
-
)
|
1204
|
-
# TODO: handle the scenario where the primary key field is a list, and concatenate the values to form the APP_IDENTIFIER
|
1205
|
-
# Currently this is only implemented in the java runtime, since it's typically databases that use composite keys
|
1206
|
-
results_df["APP_IDENTIFIER"] = results_df["RECORD_DATA"].apply(lambda x: get_nested_value(dict(x),primary_key_field))
|
1226
|
+
# TODO: handle the scenario where the primary key field is a list, and concatenate the values to form the APP_IDENTIFIER
|
1227
|
+
# Currently this is only implemented in the java runtime, since it's typically databases that use composite keys
|
1228
|
+
results_df["APP_IDENTIFIER"] = results_df["RECORD_DATA"].apply(lambda x: get_nested_value(dict(x),primary_key_field))
|
1207
1229
|
# ensure APP_IDENTIFIER is a string
|
1208
1230
|
results_df["APP_IDENTIFIER"] = results_df["APP_IDENTIFIER"].apply(str)
|
1209
1231
|
# the timestamps in Snowflake are TIMESTAMP_LTZ, so we upload in string format to ensure the
|
@@ -1238,6 +1260,16 @@ class InboundSyncRequest(SyncRequest):
|
|
1238
1260
|
["APP_IDENTIFIER", "STREAM_NAME", "RECORD_DATA", "RETRIEVE_DATE", "IS_DELETED"]
|
1239
1261
|
)
|
1240
1262
|
]
|
1263
|
+
|
1264
|
+
def get_hash(self, keys:List[str]) -> str:
|
1265
|
+
"""
|
1266
|
+
Creates a hash from a list of keys.
|
1267
|
+
The function will join the keys with an underscore and then create a
|
1268
|
+
SHA256 hash from the string. The function will return the hash as a string.
|
1269
|
+
"""
|
1270
|
+
key_string = "_".join(keys)
|
1271
|
+
hash_object = hashlib.sha256(key_string.encode())
|
1272
|
+
return hash_object.hexdigest()
|
1241
1273
|
|
1242
1274
|
def _apply_results_dataframe(self, stream_names: List[str], results_df: pandas.DataFrame):
|
1243
1275
|
"""
|
{omnata_plugin_runtime-0.3.21a64.dist-info → omnata_plugin_runtime-0.3.23a69.dist-info}/RECORD
RENAMED
@@ -3,10 +3,10 @@ omnata_plugin_runtime/api.py,sha256=_N5ok5LN7GDO4J9n3yduXp3tpjmhpySY__U2baiygrs,
|
|
3
3
|
omnata_plugin_runtime/configuration.py,sha256=7cMekoY8CeZAJHpASU6tCMidF55Hzfr7CD74jtebqIY,35742
|
4
4
|
omnata_plugin_runtime/forms.py,sha256=pw_aKVsXSz47EP8PFBI3VDwdSN5IjvZxp8JTjO1V130,18421
|
5
5
|
omnata_plugin_runtime/logging.py,sha256=bn7eKoNWvtuyTk7RTwBS9UARMtqkiICtgMtzq3KA2V0,3272
|
6
|
-
omnata_plugin_runtime/omnata_plugin.py,sha256=
|
6
|
+
omnata_plugin_runtime/omnata_plugin.py,sha256=EaGIQdq_gcmH2loTluTa0T3YxuUhDNZTQIItzYXtZxE,102783
|
7
7
|
omnata_plugin_runtime/plugin_entrypoints.py,sha256=s-SrUnXaS6FaBq1igiJhcCB3Md_a6op-dp_g1H_55QU,27736
|
8
8
|
omnata_plugin_runtime/rate_limiting.py,sha256=se6MftQI5NrVHaLb1hByPCgAESPQhkAgIG7KIU1clDU,16562
|
9
|
-
omnata_plugin_runtime-0.3.
|
10
|
-
omnata_plugin_runtime-0.3.
|
11
|
-
omnata_plugin_runtime-0.3.
|
12
|
-
omnata_plugin_runtime-0.3.
|
9
|
+
omnata_plugin_runtime-0.3.23a69.dist-info/LICENSE,sha256=IMF9i4xIpgCADf0U-V1cuf9HBmqWQd3qtI3FSuyW4zE,26526
|
10
|
+
omnata_plugin_runtime-0.3.23a69.dist-info/METADATA,sha256=u_HhdrNMZOCVn0A9Lv-u9q3KnOmxvRlJLDFAHrU8si0,1604
|
11
|
+
omnata_plugin_runtime-0.3.23a69.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
|
12
|
+
omnata_plugin_runtime-0.3.23a69.dist-info/RECORD,,
|
{omnata_plugin_runtime-0.3.21a64.dist-info → omnata_plugin_runtime-0.3.23a69.dist-info}/LICENSE
RENAMED
File without changes
|
{omnata_plugin_runtime-0.3.21a64.dist-info → omnata_plugin_runtime-0.3.23a69.dist-info}/WHEEL
RENAMED
File without changes
|