ingen-lib 3.1.0__tar.gz → 3.2.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.
- {ingen_lib-3.1.0/ingen_lib.egg-info → ingen_lib-3.2.0}/PKG-INFO +2 -1
- {ingen_lib-3.1.0 → ingen_lib-3.2.0}/ingen/data_source/data_source_type.py +1 -0
- ingen_lib-3.2.0/ingen/data_source/snowflake_source.py +130 -0
- {ingen_lib-3.1.0 → ingen_lib-3.2.0}/ingen/data_source/source_factory.py +3 -0
- {ingen_lib-3.1.0 → ingen_lib-3.2.0}/ingen/metadata/metadata.py +2 -1
- {ingen_lib-3.1.0 → ingen_lib-3.2.0}/ingen/reader/file_reader.py +2 -2
- ingen_lib-3.2.0/ingen/reader/snowflake_reader.py +32 -0
- {ingen_lib-3.1.0 → ingen_lib-3.2.0}/ingen/utils/path_parser.py +28 -2
- ingen_lib-3.2.0/ingen/writer/json_writer/destinations/file_destination.py +11 -0
- {ingen_lib-3.1.0 → ingen_lib-3.2.0}/ingen/writer/writer.py +21 -15
- {ingen_lib-3.1.0 → ingen_lib-3.2.0/ingen_lib.egg-info}/PKG-INFO +2 -1
- {ingen_lib-3.1.0 → ingen_lib-3.2.0}/ingen_lib.egg-info/SOURCES.txt +2 -0
- {ingen_lib-3.1.0 → ingen_lib-3.2.0}/ingen_lib.egg-info/requires.txt +1 -0
- {ingen_lib-3.1.0 → ingen_lib-3.2.0}/requirements.txt +1 -0
- {ingen_lib-3.1.0 → ingen_lib-3.2.0}/setup.py +2 -2
- ingen_lib-3.1.0/ingen/writer/json_writer/destinations/file_destination.py +0 -8
- {ingen_lib-3.1.0 → ingen_lib-3.2.0}/LICENSE +0 -0
- {ingen_lib-3.1.0 → ingen_lib-3.2.0}/MANIFEST.in +0 -0
- {ingen_lib-3.1.0 → ingen_lib-3.2.0}/README.md +0 -0
- {ingen_lib-3.1.0 → ingen_lib-3.2.0}/ingen/__init__.py +0 -0
- {ingen_lib-3.1.0 → ingen_lib-3.2.0}/ingen/__main__.py +0 -0
- {ingen_lib-3.1.0 → ingen_lib-3.2.0}/ingen/data_source/__init__.py +0 -0
- {ingen_lib-3.1.0 → ingen_lib-3.2.0}/ingen/data_source/api_source.py +0 -0
- {ingen_lib-3.1.0 → ingen_lib-3.2.0}/ingen/data_source/dataframe_store.py +0 -0
- {ingen_lib-3.1.0 → ingen_lib-3.2.0}/ingen/data_source/file_source.py +0 -0
- {ingen_lib-3.1.0 → ingen_lib-3.2.0}/ingen/data_source/json_source.py +0 -0
- {ingen_lib-3.1.0 → ingen_lib-3.2.0}/ingen/data_source/mysql_source.py +0 -0
- {ingen_lib-3.1.0 → ingen_lib-3.2.0}/ingen/data_source/rawdata_source.py +0 -0
- {ingen_lib-3.1.0 → ingen_lib-3.2.0}/ingen/data_source/source.py +0 -0
- {ingen_lib-3.1.0 → ingen_lib-3.2.0}/ingen/formatters/__init__.py +0 -0
- {ingen_lib-3.1.0 → ingen_lib-3.2.0}/ingen/formatters/common_formatters.py +0 -0
- {ingen_lib-3.1.0 → ingen_lib-3.2.0}/ingen/formatters/formatter.py +0 -0
- {ingen_lib-3.1.0 → ingen_lib-3.2.0}/ingen/formatters/utils.py +0 -0
- {ingen_lib-3.1.0 → ingen_lib-3.2.0}/ingen/generators/__init__.py +0 -0
- {ingen_lib-3.1.0 → ingen_lib-3.2.0}/ingen/generators/base_interface_generator.py +0 -0
- {ingen_lib-3.1.0 → ingen_lib-3.2.0}/ingen/generators/interface_generator.py +0 -0
- {ingen_lib-3.1.0 → ingen_lib-3.2.0}/ingen/lib/__init__.py +0 -0
- {ingen_lib-3.1.0 → ingen_lib-3.2.0}/ingen/lib/cryptor.py +0 -0
- {ingen_lib-3.1.0 → ingen_lib-3.2.0}/ingen/logger.py +0 -0
- {ingen_lib-3.1.0 → ingen_lib-3.2.0}/ingen/metadata/__init__.py +0 -0
- {ingen_lib-3.1.0 → ingen_lib-3.2.0}/ingen/metadata/metadata_parser.py +0 -0
- {ingen_lib-3.1.0 → ingen_lib-3.2.0}/ingen/post_processor/__init__.py +0 -0
- {ingen_lib-3.1.0 → ingen_lib-3.2.0}/ingen/post_processor/common_post_processor.py +0 -0
- {ingen_lib-3.1.0 → ingen_lib-3.2.0}/ingen/post_processor/post_processor.py +0 -0
- {ingen_lib-3.1.0 → ingen_lib-3.2.0}/ingen/pre_processor/__init__.py +0 -0
- {ingen_lib-3.1.0 → ingen_lib-3.2.0}/ingen/pre_processor/aggregator.py +0 -0
- {ingen_lib-3.1.0 → ingen_lib-3.2.0}/ingen/pre_processor/aggregators.py +0 -0
- {ingen_lib-3.1.0 → ingen_lib-3.2.0}/ingen/pre_processor/drop_duplicates.py +0 -0
- {ingen_lib-3.1.0 → ingen_lib-3.2.0}/ingen/pre_processor/filter.py +0 -0
- {ingen_lib-3.1.0 → ingen_lib-3.2.0}/ingen/pre_processor/json_array_expander.py +0 -0
- {ingen_lib-3.1.0 → ingen_lib-3.2.0}/ingen/pre_processor/mask.py +0 -0
- {ingen_lib-3.1.0 → ingen_lib-3.2.0}/ingen/pre_processor/melt.py +0 -0
- {ingen_lib-3.1.0 → ingen_lib-3.2.0}/ingen/pre_processor/merger.py +0 -0
- {ingen_lib-3.1.0 → ingen_lib-3.2.0}/ingen/pre_processor/not_equals_filter.py +0 -0
- {ingen_lib-3.1.0 → ingen_lib-3.2.0}/ingen/pre_processor/outer_join.py +0 -0
- {ingen_lib-3.1.0 → ingen_lib-3.2.0}/ingen/pre_processor/pre_processor.py +0 -0
- {ingen_lib-3.1.0 → ingen_lib-3.2.0}/ingen/pre_processor/process.py +0 -0
- {ingen_lib-3.1.0 → ingen_lib-3.2.0}/ingen/pre_processor/union.py +0 -0
- {ingen_lib-3.1.0 → ingen_lib-3.2.0}/ingen/reader/__init__.py +0 -0
- {ingen_lib-3.1.0 → ingen_lib-3.2.0}/ingen/reader/api_reader.py +0 -0
- {ingen_lib-3.1.0 → ingen_lib-3.2.0}/ingen/reader/data_source.py +0 -0
- {ingen_lib-3.1.0 → ingen_lib-3.2.0}/ingen/reader/json_reader.py +0 -0
- {ingen_lib-3.1.0 → ingen_lib-3.2.0}/ingen/reader/mysql_reader.py +0 -0
- {ingen_lib-3.1.0 → ingen_lib-3.2.0}/ingen/reader/rawdata_reader.py +0 -0
- {ingen_lib-3.1.0 → ingen_lib-3.2.0}/ingen/reader/xml_file_reader.py +0 -0
- {ingen_lib-3.1.0 → ingen_lib-3.2.0}/ingen/utils/__init__.py +0 -0
- {ingen_lib-3.1.0 → ingen_lib-3.2.0}/ingen/utils/app_http/__init__.py +0 -0
- {ingen_lib-3.1.0 → ingen_lib-3.2.0}/ingen/utils/app_http/aiohttp_retry.py +0 -0
- {ingen_lib-3.1.0 → ingen_lib-3.2.0}/ingen/utils/app_http/auth.py +0 -0
- {ingen_lib-3.1.0 → ingen_lib-3.2.0}/ingen/utils/app_http/http_request.py +0 -0
- {ingen_lib-3.1.0 → ingen_lib-3.2.0}/ingen/utils/app_http/http_util.py +0 -0
- {ingen_lib-3.1.0 → ingen_lib-3.2.0}/ingen/utils/app_http/success_criterias.py +0 -0
- {ingen_lib-3.1.0 → ingen_lib-3.2.0}/ingen/utils/app_secrets.py +0 -0
- {ingen_lib-3.1.0 → ingen_lib-3.2.0}/ingen/utils/interpolators/Interpolator.py +0 -0
- {ingen_lib-3.1.0 → ingen_lib-3.2.0}/ingen/utils/interpolators/__init__.py +0 -0
- {ingen_lib-3.1.0 → ingen_lib-3.2.0}/ingen/utils/interpolators/common_interpolators.py +0 -0
- {ingen_lib-3.1.0 → ingen_lib-3.2.0}/ingen/utils/json_df_convertors.py +0 -0
- {ingen_lib-3.1.0 → ingen_lib-3.2.0}/ingen/utils/properties.py +0 -0
- {ingen_lib-3.1.0 → ingen_lib-3.2.0}/ingen/utils/run_configuration.py +0 -0
- {ingen_lib-3.1.0 → ingen_lib-3.2.0}/ingen/utils/sql_query_parser.py +0 -0
- {ingen_lib-3.1.0 → ingen_lib-3.2.0}/ingen/utils/timer.py +0 -0
- {ingen_lib-3.1.0 → ingen_lib-3.2.0}/ingen/utils/url_constructor.py +0 -0
- {ingen_lib-3.1.0 → ingen_lib-3.2.0}/ingen/utils/utils.py +0 -0
- {ingen_lib-3.1.0 → ingen_lib-3.2.0}/ingen/validation/__init__.py +0 -0
- {ingen_lib-3.1.0 → ingen_lib-3.2.0}/ingen/validation/common_validations.py +0 -0
- {ingen_lib-3.1.0 → ingen_lib-3.2.0}/ingen/validation/notification.py +0 -0
- {ingen_lib-3.1.0 → ingen_lib-3.2.0}/ingen/validation/send_email.py +0 -0
- {ingen_lib-3.1.0 → ingen_lib-3.2.0}/ingen/validation/validations.py +0 -0
- {ingen_lib-3.1.0 → ingen_lib-3.2.0}/ingen/writer/__init__.py +0 -0
- {ingen_lib-3.1.0 → ingen_lib-3.2.0}/ingen/writer/dataframe_writer.py +0 -0
- {ingen_lib-3.1.0 → ingen_lib-3.2.0}/ingen/writer/json_util.py +0 -0
- {ingen_lib-3.1.0 → ingen_lib-3.2.0}/ingen/writer/json_writer/__init__.py +0 -0
- {ingen_lib-3.1.0 → ingen_lib-3.2.0}/ingen/writer/json_writer/convertors/__init__.py +0 -0
- {ingen_lib-3.1.0 → ingen_lib-3.2.0}/ingen/writer/json_writer/convertors/convertor_factory.py +0 -0
- {ingen_lib-3.1.0 → ingen_lib-3.2.0}/ingen/writer/json_writer/convertors/df_to_multiple_json_convertor.py +0 -0
- {ingen_lib-3.1.0 → ingen_lib-3.2.0}/ingen/writer/json_writer/convertors/df_to_single_json_convertor.py +0 -0
- {ingen_lib-3.1.0 → ingen_lib-3.2.0}/ingen/writer/json_writer/destinations/__init__.py +0 -0
- {ingen_lib-3.1.0 → ingen_lib-3.2.0}/ingen/writer/json_writer/destinations/api_destination.py +0 -0
- {ingen_lib-3.1.0 → ingen_lib-3.2.0}/ingen/writer/json_writer/destinations/destination_factory.py +0 -0
- {ingen_lib-3.1.0 → ingen_lib-3.2.0}/ingen/writer/json_writer/json_writer.py +0 -0
- {ingen_lib-3.1.0 → ingen_lib-3.2.0}/ingen/writer/old_json_writer.py +0 -0
- {ingen_lib-3.1.0 → ingen_lib-3.2.0}/ingen/writer/split_file_writer.py +0 -0
- {ingen_lib-3.1.0 → ingen_lib-3.2.0}/ingen/writer/util.py +0 -0
- {ingen_lib-3.1.0 → ingen_lib-3.2.0}/ingen_lib.egg-info/dependency_links.txt +0 -0
- {ingen_lib-3.1.0 → ingen_lib-3.2.0}/ingen_lib.egg-info/top_level.txt +0 -0
- {ingen_lib-3.1.0 → ingen_lib-3.2.0}/pyproject.toml +0 -0
- {ingen_lib-3.1.0 → ingen_lib-3.2.0}/setup.cfg +0 -0
- {ingen_lib-3.1.0 → ingen_lib-3.2.0}/test/test_interface_generator.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: ingen-lib
|
|
3
|
-
Version: 3.
|
|
3
|
+
Version: 3.2.0
|
|
4
4
|
Summary: A Python script suite that generates interface files based on the given interface metadata/config file
|
|
5
5
|
Home-page: https://github.com/blackrock/interface-generator
|
|
6
6
|
Maintainer: Swarna Dhakad, Piyush Ranjan, Jatin Varlyani, Pooja Katariya
|
|
@@ -21,6 +21,7 @@ Requires-Dist: pandas<3.0,>=2.2.2
|
|
|
21
21
|
Requires-Dist: pycryptodome>=3.20.0
|
|
22
22
|
Requires-Dist: PyMySQL>=1.1.1
|
|
23
23
|
Requires-Dist: PyYAML>=6.0.2
|
|
24
|
+
Requires-Dist: snowflake-connector-python>=3.12.0
|
|
24
25
|
Requires-Dist: xmltodict>=0.12.0
|
|
25
26
|
Dynamic: classifier
|
|
26
27
|
Dynamic: description
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
# Copyright (c) 2023 BlackRock, Inc.
|
|
2
|
+
# All Rights Reserved.
|
|
3
|
+
|
|
4
|
+
import logging
|
|
5
|
+
|
|
6
|
+
from ingen.data_source.source import DataSource
|
|
7
|
+
from ingen.reader.snowflake_reader import DEFAULT_BATCH_SIZE, SnowflakeReader
|
|
8
|
+
from ingen.utils.properties import properties
|
|
9
|
+
from ingen.utils.sql_query_parser import SqlQueryParser
|
|
10
|
+
from ingen.utils.timer import log_time
|
|
11
|
+
|
|
12
|
+
log = logging.getLogger()
|
|
13
|
+
|
|
14
|
+
PROPERTY_PREFIX = 'datasource.snowflake.'
|
|
15
|
+
|
|
16
|
+
PASSWORD = 'snowflake'
|
|
17
|
+
KEY_PAIR = 'snowflake_jwt'
|
|
18
|
+
OAUTH = 'oauth'
|
|
19
|
+
EXTERNAL_BROWSER = 'externalbrowser'
|
|
20
|
+
|
|
21
|
+
# Credentials required by each authenticator, read from config.properties.
|
|
22
|
+
REQUIRED_CREDENTIALS = {
|
|
23
|
+
PASSWORD: ['user', 'password'],
|
|
24
|
+
KEY_PAIR: ['user', 'private_key_path'],
|
|
25
|
+
OAUTH: ['token'],
|
|
26
|
+
EXTERNAL_BROWSER: ['user'],
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
CREDENTIAL_KEYS = ['account', 'user', 'password', 'private_key_path', 'private_key_passphrase', 'token']
|
|
30
|
+
SESSION_KEYS = ['warehouse', 'database', 'schema', 'role']
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
class SnowflakeSource(DataSource):
|
|
34
|
+
"""
|
|
35
|
+
This class represents snowflake database source.
|
|
36
|
+
Connection details and credentials are read from config.properties (datasource.snowflake.*);
|
|
37
|
+
session context (warehouse, database, schema, role) and the query are read from the source config.
|
|
38
|
+
"""
|
|
39
|
+
|
|
40
|
+
def __init__(self, source, params_map=None):
|
|
41
|
+
"""
|
|
42
|
+
Loads a SnowflakeSource
|
|
43
|
+
:param source: Map which contains source data such as id, query, warehouse, database, etc.
|
|
44
|
+
:param params_map: Map which contains runtime parameters such as query_params, run_date
|
|
45
|
+
"""
|
|
46
|
+
super().__init__(source['id'])
|
|
47
|
+
if source.get('temp_table_params'):
|
|
48
|
+
# SqlQueryParser builds Sybase-style temp tables (#name, multiple statements), which Snowflake rejects.
|
|
49
|
+
raise ValueError("temp_table_params is not supported for snowflake sources")
|
|
50
|
+
self._batch_size = source.get('batch_size', DEFAULT_BATCH_SIZE)
|
|
51
|
+
if isinstance(self._batch_size, bool) or not isinstance(self._batch_size, int) or self._batch_size <= 0:
|
|
52
|
+
raise ValueError(f"batch_size must be a positive integer, got '{self._batch_size}'")
|
|
53
|
+
self._src_data_checks = source.get('src_data_checks', [])
|
|
54
|
+
self._query = SqlQueryParser().parse_query(source['query'], params_map)
|
|
55
|
+
self._connection_params = self._build_connection_params(source)
|
|
56
|
+
|
|
57
|
+
@staticmethod
|
|
58
|
+
def _build_connection_params(source):
|
|
59
|
+
credentials = {key: properties.get_property(PROPERTY_PREFIX + key) for key in CREDENTIAL_KEYS}
|
|
60
|
+
if not credentials['account']:
|
|
61
|
+
raise ValueError(f"Missing Snowflake property '{PROPERTY_PREFIX}account'")
|
|
62
|
+
|
|
63
|
+
authenticator = SnowflakeSource._resolve_authenticator(source, credentials)
|
|
64
|
+
missing = [PROPERTY_PREFIX + key for key in REQUIRED_CREDENTIALS[authenticator] if not credentials[key]]
|
|
65
|
+
if missing:
|
|
66
|
+
raise ValueError(f"Missing Snowflake properties for authenticator '{authenticator}': {', '.join(missing)}")
|
|
67
|
+
|
|
68
|
+
params = {'account': credentials['account'], 'authenticator': authenticator}
|
|
69
|
+
params.update({key: source[key] for key in SESSION_KEYS if source.get(key)})
|
|
70
|
+
if credentials['user']:
|
|
71
|
+
params['user'] = credentials['user']
|
|
72
|
+
if authenticator == PASSWORD:
|
|
73
|
+
params['password'] = credentials['password']
|
|
74
|
+
elif authenticator == KEY_PAIR:
|
|
75
|
+
params['private_key_file'] = credentials['private_key_path']
|
|
76
|
+
if credentials['private_key_passphrase']:
|
|
77
|
+
params['private_key_file_pwd'] = credentials['private_key_passphrase']
|
|
78
|
+
elif authenticator == OAUTH:
|
|
79
|
+
params['token'] = credentials['token']
|
|
80
|
+
else:
|
|
81
|
+
log.warning("Snowflake externalbrowser (SSO) authentication opens a browser window and is intended "
|
|
82
|
+
"for local use only. Use key pair, OAuth or password authentication for automated runs.")
|
|
83
|
+
return params
|
|
84
|
+
|
|
85
|
+
@staticmethod
|
|
86
|
+
def _resolve_authenticator(source, credentials):
|
|
87
|
+
"""
|
|
88
|
+
Uses the authenticator set in the source config, if any. Otherwise it is inferred from the configured
|
|
89
|
+
credentials: private key > OAuth token > password. externalbrowser is never inferred, it must be explicit.
|
|
90
|
+
"""
|
|
91
|
+
authenticator = source.get('authenticator')
|
|
92
|
+
if authenticator:
|
|
93
|
+
authenticator = str(authenticator).lower()
|
|
94
|
+
if authenticator not in REQUIRED_CREDENTIALS:
|
|
95
|
+
raise ValueError(f"Unsupported Snowflake authenticator '{authenticator}'. "
|
|
96
|
+
f"Supported: {', '.join(REQUIRED_CREDENTIALS)}")
|
|
97
|
+
return authenticator
|
|
98
|
+
if credentials['private_key_path']:
|
|
99
|
+
return KEY_PAIR
|
|
100
|
+
if credentials['token']:
|
|
101
|
+
return OAUTH
|
|
102
|
+
if credentials['password']:
|
|
103
|
+
return PASSWORD
|
|
104
|
+
raise ValueError(f"No Snowflake credentials found. Set one of {PROPERTY_PREFIX}private_key_path, "
|
|
105
|
+
f"{PROPERTY_PREFIX}token or {PROPERTY_PREFIX}password in config.properties, "
|
|
106
|
+
f"or set 'authenticator: {EXTERNAL_BROWSER}' in the source for local SSO.")
|
|
107
|
+
|
|
108
|
+
def fetch(self):
|
|
109
|
+
"""
|
|
110
|
+
Executes the SQL query
|
|
111
|
+
:return: A DataFrame created using the result of the query
|
|
112
|
+
"""
|
|
113
|
+
# Imported lazily: the connector is slow to import and only needed when a snowflake source is used.
|
|
114
|
+
import snowflake.connector
|
|
115
|
+
reader = SnowflakeReader(snowflake.connector.connect(**self._connection_params), self._batch_size)
|
|
116
|
+
return self.fetch_data(reader)
|
|
117
|
+
|
|
118
|
+
@log_time
|
|
119
|
+
def fetch_data(self, reader):
|
|
120
|
+
"""
|
|
121
|
+
returns a DataFrame of data fetched from SnowflakeSource.
|
|
122
|
+
"""
|
|
123
|
+
return reader.execute(self._query)
|
|
124
|
+
|
|
125
|
+
def fetch_validations(self):
|
|
126
|
+
"""
|
|
127
|
+
Method to fetch validations from the source
|
|
128
|
+
:return: list of dictionaries containing mentioned validations on all columns
|
|
129
|
+
"""
|
|
130
|
+
return self._src_data_checks
|
|
@@ -6,6 +6,7 @@ from ingen.data_source.file_source import FileSource
|
|
|
6
6
|
from ingen.data_source.json_source import JsonSource
|
|
7
7
|
from ingen.data_source.mysql_source import MYSQLSource
|
|
8
8
|
from ingen.data_source.rawdata_source import RawDataSource
|
|
9
|
+
from ingen.data_source.snowflake_source import SnowflakeSource
|
|
9
10
|
|
|
10
11
|
|
|
11
12
|
class SourceFactory:
|
|
@@ -23,5 +24,7 @@ class SourceFactory:
|
|
|
23
24
|
return RawDataSource(source)
|
|
24
25
|
elif source['type'] == DataSourceType.JSON.value:
|
|
25
26
|
return JsonSource(source, dynamic_data)
|
|
27
|
+
elif source['type'] == DataSourceType.Snowflake.value:
|
|
28
|
+
return SnowflakeSource(source, params_map)
|
|
26
29
|
else:
|
|
27
30
|
raise ValueError(f"Unknown source type {source.get('type')}.")
|
|
@@ -89,7 +89,8 @@ class MetaData:
|
|
|
89
89
|
path = [path]
|
|
90
90
|
|
|
91
91
|
run_date = self._params_map.get("run_date", date.today())
|
|
92
|
-
path_parser = PathParser(run_date)
|
|
92
|
+
path_parser = PathParser(run_date, override_params=self._params_map.get("override_params"),
|
|
93
|
+
strict_overrides=True)
|
|
93
94
|
parsed_paths = [path_parser.parse(p) for p in path]
|
|
94
95
|
props["path"] = parsed_paths
|
|
95
96
|
|
|
@@ -33,8 +33,8 @@ class CSVFileReader(Reader):
|
|
|
33
33
|
names=config['all_cols'],
|
|
34
34
|
dtype=dtype,
|
|
35
35
|
encoding=encoding)
|
|
36
|
-
|
|
37
|
-
|
|
36
|
+
if src.get('convert_dtypes', False):
|
|
37
|
+
result = result.convert_dtypes()
|
|
38
38
|
except TypeError:
|
|
39
39
|
logging.error(self.DTYPE_LOG_MSG)
|
|
40
40
|
raise
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# Copyright (c) 2023 BlackRock, Inc.
|
|
2
|
+
# All Rights Reserved.
|
|
3
|
+
|
|
4
|
+
import logging
|
|
5
|
+
|
|
6
|
+
import pandas as pd
|
|
7
|
+
|
|
8
|
+
log = logging.getLogger()
|
|
9
|
+
|
|
10
|
+
DEFAULT_BATCH_SIZE = 100000
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class SnowflakeReader:
|
|
14
|
+
def __init__(self, connection, batch_size=DEFAULT_BATCH_SIZE):
|
|
15
|
+
self._connection = connection
|
|
16
|
+
self._batch_size = batch_size
|
|
17
|
+
|
|
18
|
+
def execute(self, sql):
|
|
19
|
+
log.debug(f"Running query: {sql}")
|
|
20
|
+
try:
|
|
21
|
+
with self._connection.cursor() as cursor:
|
|
22
|
+
cursor.execute(sql)
|
|
23
|
+
columns = [col[0] for col in cursor.description]
|
|
24
|
+
# Rows are fetched and converted to DataFrames batch by batch, so the full result set is never held
|
|
25
|
+
# in memory as Python row tuples (several times larger than the equivalent DataFrame).
|
|
26
|
+
batches = [pd.DataFrame.from_records(rows, columns=columns)
|
|
27
|
+
for rows in iter(lambda: cursor.fetchmany(self._batch_size), [])]
|
|
28
|
+
dataframe = pd.concat(batches, ignore_index=True) if batches else pd.DataFrame(columns=columns)
|
|
29
|
+
log.info(f"TOTAL RECORDS IN DATAFRAME FROM SNOWFLAKE: {len(dataframe)}")
|
|
30
|
+
return dataframe
|
|
31
|
+
finally:
|
|
32
|
+
self._connection.close()
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
import logging
|
|
5
5
|
import os
|
|
6
|
+
import re
|
|
6
7
|
from datetime import date
|
|
7
8
|
|
|
8
9
|
from ingen.utils.interpolators.Interpolator import Interpolator
|
|
@@ -15,11 +16,19 @@ class PathParser:
|
|
|
15
16
|
PathParser is a utility class that provides methods to parse file paths and replace
|
|
16
17
|
the dynamic fields in it with appropriate values. A replaceable item can be one of the following:
|
|
17
18
|
1. date - $date(<FORMAT>) - it will be replaced by the date provided in the constructor in the given format
|
|
19
|
+
2. override - $override(<KEY>) - replaced by the value of KEY from --override_params
|
|
18
20
|
"""
|
|
19
21
|
|
|
20
|
-
def __init__(self, run_date=date.today(), interpolator=
|
|
22
|
+
def __init__(self, run_date=date.today(), interpolator=None, override_params=None,
|
|
23
|
+
strict_overrides=False):
|
|
21
24
|
self.run_date = run_date
|
|
22
|
-
self.
|
|
25
|
+
self.override_params = override_params
|
|
26
|
+
self.strict_overrides = strict_overrides
|
|
27
|
+
if interpolator is not None:
|
|
28
|
+
self.interpolator = interpolator
|
|
29
|
+
else:
|
|
30
|
+
params = {'override_params': override_params} if override_params is not None else None
|
|
31
|
+
self.interpolator = Interpolator(params=params)
|
|
23
32
|
self.item_name_method_map = {
|
|
24
33
|
'date': self.get_formatted_run_date
|
|
25
34
|
}
|
|
@@ -31,8 +40,25 @@ class PathParser:
|
|
|
31
40
|
:return: path with tokens and date values. e.g, "u1/ftp/some/path/file_name_12092020.csv"
|
|
32
41
|
"""
|
|
33
42
|
path = self.parse_env_variable(path)
|
|
43
|
+
if self.strict_overrides:
|
|
44
|
+
self._validate_override_keys(path)
|
|
34
45
|
return self.interpolator.interpolate(path, self.item_name_method_map)
|
|
35
46
|
|
|
47
|
+
def _validate_override_keys(self, path):
|
|
48
|
+
keys = list(dict.fromkeys(re.findall(r"\$override\((.*?)\)", path)))
|
|
49
|
+
supplied = self.override_params or {}
|
|
50
|
+
missing = [key for key in keys
|
|
51
|
+
if key not in supplied or str(supplied[key]).strip() == '']
|
|
52
|
+
if missing:
|
|
53
|
+
raise ValueError(f"Path '{path}' uses $override({', '.join(missing)}) but no value was supplied. "
|
|
54
|
+
f"Pass --override_params {missing[0]}=<value>.")
|
|
55
|
+
for key in keys:
|
|
56
|
+
value = str(supplied[key])
|
|
57
|
+
if '..' in value:
|
|
58
|
+
raise ValueError(f"Path '{path}' uses $override({key}) with value '{value}', "
|
|
59
|
+
f"which contains '..'. "
|
|
60
|
+
f"Parent-directory references are not allowed in override values.")
|
|
61
|
+
|
|
36
62
|
def parse_env_variable(self, path):
|
|
37
63
|
if path.startswith(ENVIRONMENT_VAR_PATTERN):
|
|
38
64
|
environment_var = path[2:]
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# Copyright (c) 2023 BlackRock, Inc.
|
|
2
|
+
# All Rights Reserved.
|
|
3
|
+
|
|
4
|
+
class FileDestination:
|
|
5
|
+
def handle(self, json_strings, destination_props):
|
|
6
|
+
paths = destination_props.get('path')
|
|
7
|
+
if not isinstance(paths, list):
|
|
8
|
+
paths = [paths]
|
|
9
|
+
for file_path in paths:
|
|
10
|
+
with open(file_path, 'w') as file:
|
|
11
|
+
file.writelines(json_strings)
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
# Copyright (c) 2023 BlackRock, Inc.
|
|
2
2
|
# All Rights Reserved.
|
|
3
3
|
|
|
4
|
+
import csv
|
|
4
5
|
import logging
|
|
5
6
|
|
|
6
7
|
from ingen.writer.dataframe_writer import DataFrameWriter
|
|
@@ -51,10 +52,13 @@ class InterfaceWriter:
|
|
|
51
52
|
logger.info(f"writing file to {path}")
|
|
52
53
|
sep = self._props['delimiter'] if 'delimiter' in self._props else ','
|
|
53
54
|
encoding = self._props.get('encoding', 'utf-8')
|
|
55
|
+
csv_options = {'index': InterfaceWriter.SHOW_DATAFRAME_INDEX, 'encoding': encoding}
|
|
56
|
+
if str(self._props.get('quote_all', False)).strip().lower() == 'true':
|
|
57
|
+
csv_options['quoting'] = csv.QUOTE_ALL
|
|
54
58
|
if self.header and self.header.get('type') == 'delimited_result_header':
|
|
55
|
-
self._df.to_csv(path, sep,
|
|
59
|
+
self._df.to_csv(path, sep, **csv_options)
|
|
56
60
|
else:
|
|
57
|
-
self._df.to_csv(path, sep, header=False,
|
|
61
|
+
self._df.to_csv(path, sep, header=False, **csv_options)
|
|
58
62
|
|
|
59
63
|
def file_writer(self):
|
|
60
64
|
paths = self._props.get('path')
|
|
@@ -63,7 +67,7 @@ class InterfaceWriter:
|
|
|
63
67
|
|
|
64
68
|
for path in paths:
|
|
65
69
|
if self._type == 'json':
|
|
66
|
-
json_writer = OldJSONWriter(self._df, self._type, self._props)
|
|
70
|
+
json_writer = OldJSONWriter(self._df, self._type, {**self._props, 'path': path})
|
|
67
71
|
json_writer.write()
|
|
68
72
|
elif self._type == 'json_writer':
|
|
69
73
|
writer = JSONWriter(self._df, self._props, self._params)
|
|
@@ -92,19 +96,21 @@ class InterfaceWriter:
|
|
|
92
96
|
return footer_string
|
|
93
97
|
|
|
94
98
|
def add_header_footer(self, header, footer):
|
|
95
|
-
|
|
99
|
+
paths = self._props['path']
|
|
100
|
+
if not isinstance(paths, list):
|
|
101
|
+
paths = [paths]
|
|
96
102
|
encoding = self._props.get('encoding', 'utf-8')
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
103
|
+
for path in paths:
|
|
104
|
+
with open(path, 'r+', encoding=encoding) as file:
|
|
105
|
+
if header != '':
|
|
106
|
+
lines = file.readlines()
|
|
107
|
+
file.seek(0)
|
|
108
|
+
file.writelines(header + '\n')
|
|
109
|
+
for line in lines:
|
|
110
|
+
file.write(line)
|
|
111
|
+
if footer != '':
|
|
112
|
+
file.read()
|
|
113
|
+
file.write(footer)
|
|
108
114
|
|
|
109
115
|
def custom_function(self, value):
|
|
110
116
|
run_date = self._params['run_date']
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: ingen-lib
|
|
3
|
-
Version: 3.
|
|
3
|
+
Version: 3.2.0
|
|
4
4
|
Summary: A Python script suite that generates interface files based on the given interface metadata/config file
|
|
5
5
|
Home-page: https://github.com/blackrock/interface-generator
|
|
6
6
|
Maintainer: Swarna Dhakad, Piyush Ranjan, Jatin Varlyani, Pooja Katariya
|
|
@@ -21,6 +21,7 @@ Requires-Dist: pandas<3.0,>=2.2.2
|
|
|
21
21
|
Requires-Dist: pycryptodome>=3.20.0
|
|
22
22
|
Requires-Dist: PyMySQL>=1.1.1
|
|
23
23
|
Requires-Dist: PyYAML>=6.0.2
|
|
24
|
+
Requires-Dist: snowflake-connector-python>=3.12.0
|
|
24
25
|
Requires-Dist: xmltodict>=0.12.0
|
|
25
26
|
Dynamic: classifier
|
|
26
27
|
Dynamic: description
|
|
@@ -15,6 +15,7 @@ ingen/data_source/file_source.py
|
|
|
15
15
|
ingen/data_source/json_source.py
|
|
16
16
|
ingen/data_source/mysql_source.py
|
|
17
17
|
ingen/data_source/rawdata_source.py
|
|
18
|
+
ingen/data_source/snowflake_source.py
|
|
18
19
|
ingen/data_source/source.py
|
|
19
20
|
ingen/data_source/source_factory.py
|
|
20
21
|
ingen/formatters/__init__.py
|
|
@@ -53,6 +54,7 @@ ingen/reader/file_reader.py
|
|
|
53
54
|
ingen/reader/json_reader.py
|
|
54
55
|
ingen/reader/mysql_reader.py
|
|
55
56
|
ingen/reader/rawdata_reader.py
|
|
57
|
+
ingen/reader/snowflake_reader.py
|
|
56
58
|
ingen/reader/xml_file_reader.py
|
|
57
59
|
ingen/utils/__init__.py
|
|
58
60
|
ingen/utils/app_secrets.py
|
|
@@ -27,13 +27,13 @@ def resolve_version():
|
|
|
27
27
|
"""Resolve the package version.
|
|
28
28
|
|
|
29
29
|
At release time the CI workflow (.github/workflows/python-publish.yml) replaces the
|
|
30
|
-
``v3.
|
|
30
|
+
``v3.2.0`` token below with the git tag via ``sed``. For local/editable
|
|
31
31
|
installs the token is left intact, which is NOT a valid PEP 440 version and breaks
|
|
32
32
|
``pip install -e .``. So when the token has not been substituted, fall back to a valid
|
|
33
33
|
development version. The literal token is preserved verbatim so the existing CI ``sed`` keeps
|
|
34
34
|
working unchanged.
|
|
35
35
|
"""
|
|
36
|
-
version = 'v3.
|
|
36
|
+
version = 'v3.2.0'
|
|
37
37
|
if version.startswith('{{'):
|
|
38
38
|
return '0.0.0.dev0'
|
|
39
39
|
return version
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{ingen_lib-3.1.0 → ingen_lib-3.2.0}/ingen/writer/json_writer/convertors/convertor_factory.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{ingen_lib-3.1.0 → ingen_lib-3.2.0}/ingen/writer/json_writer/destinations/api_destination.py
RENAMED
|
File without changes
|
{ingen_lib-3.1.0 → ingen_lib-3.2.0}/ingen/writer/json_writer/destinations/destination_factory.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|