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.
Files changed (108) hide show
  1. {ingen_lib-3.1.0/ingen_lib.egg-info → ingen_lib-3.2.0}/PKG-INFO +2 -1
  2. {ingen_lib-3.1.0 → ingen_lib-3.2.0}/ingen/data_source/data_source_type.py +1 -0
  3. ingen_lib-3.2.0/ingen/data_source/snowflake_source.py +130 -0
  4. {ingen_lib-3.1.0 → ingen_lib-3.2.0}/ingen/data_source/source_factory.py +3 -0
  5. {ingen_lib-3.1.0 → ingen_lib-3.2.0}/ingen/metadata/metadata.py +2 -1
  6. {ingen_lib-3.1.0 → ingen_lib-3.2.0}/ingen/reader/file_reader.py +2 -2
  7. ingen_lib-3.2.0/ingen/reader/snowflake_reader.py +32 -0
  8. {ingen_lib-3.1.0 → ingen_lib-3.2.0}/ingen/utils/path_parser.py +28 -2
  9. ingen_lib-3.2.0/ingen/writer/json_writer/destinations/file_destination.py +11 -0
  10. {ingen_lib-3.1.0 → ingen_lib-3.2.0}/ingen/writer/writer.py +21 -15
  11. {ingen_lib-3.1.0 → ingen_lib-3.2.0/ingen_lib.egg-info}/PKG-INFO +2 -1
  12. {ingen_lib-3.1.0 → ingen_lib-3.2.0}/ingen_lib.egg-info/SOURCES.txt +2 -0
  13. {ingen_lib-3.1.0 → ingen_lib-3.2.0}/ingen_lib.egg-info/requires.txt +1 -0
  14. {ingen_lib-3.1.0 → ingen_lib-3.2.0}/requirements.txt +1 -0
  15. {ingen_lib-3.1.0 → ingen_lib-3.2.0}/setup.py +2 -2
  16. ingen_lib-3.1.0/ingen/writer/json_writer/destinations/file_destination.py +0 -8
  17. {ingen_lib-3.1.0 → ingen_lib-3.2.0}/LICENSE +0 -0
  18. {ingen_lib-3.1.0 → ingen_lib-3.2.0}/MANIFEST.in +0 -0
  19. {ingen_lib-3.1.0 → ingen_lib-3.2.0}/README.md +0 -0
  20. {ingen_lib-3.1.0 → ingen_lib-3.2.0}/ingen/__init__.py +0 -0
  21. {ingen_lib-3.1.0 → ingen_lib-3.2.0}/ingen/__main__.py +0 -0
  22. {ingen_lib-3.1.0 → ingen_lib-3.2.0}/ingen/data_source/__init__.py +0 -0
  23. {ingen_lib-3.1.0 → ingen_lib-3.2.0}/ingen/data_source/api_source.py +0 -0
  24. {ingen_lib-3.1.0 → ingen_lib-3.2.0}/ingen/data_source/dataframe_store.py +0 -0
  25. {ingen_lib-3.1.0 → ingen_lib-3.2.0}/ingen/data_source/file_source.py +0 -0
  26. {ingen_lib-3.1.0 → ingen_lib-3.2.0}/ingen/data_source/json_source.py +0 -0
  27. {ingen_lib-3.1.0 → ingen_lib-3.2.0}/ingen/data_source/mysql_source.py +0 -0
  28. {ingen_lib-3.1.0 → ingen_lib-3.2.0}/ingen/data_source/rawdata_source.py +0 -0
  29. {ingen_lib-3.1.0 → ingen_lib-3.2.0}/ingen/data_source/source.py +0 -0
  30. {ingen_lib-3.1.0 → ingen_lib-3.2.0}/ingen/formatters/__init__.py +0 -0
  31. {ingen_lib-3.1.0 → ingen_lib-3.2.0}/ingen/formatters/common_formatters.py +0 -0
  32. {ingen_lib-3.1.0 → ingen_lib-3.2.0}/ingen/formatters/formatter.py +0 -0
  33. {ingen_lib-3.1.0 → ingen_lib-3.2.0}/ingen/formatters/utils.py +0 -0
  34. {ingen_lib-3.1.0 → ingen_lib-3.2.0}/ingen/generators/__init__.py +0 -0
  35. {ingen_lib-3.1.0 → ingen_lib-3.2.0}/ingen/generators/base_interface_generator.py +0 -0
  36. {ingen_lib-3.1.0 → ingen_lib-3.2.0}/ingen/generators/interface_generator.py +0 -0
  37. {ingen_lib-3.1.0 → ingen_lib-3.2.0}/ingen/lib/__init__.py +0 -0
  38. {ingen_lib-3.1.0 → ingen_lib-3.2.0}/ingen/lib/cryptor.py +0 -0
  39. {ingen_lib-3.1.0 → ingen_lib-3.2.0}/ingen/logger.py +0 -0
  40. {ingen_lib-3.1.0 → ingen_lib-3.2.0}/ingen/metadata/__init__.py +0 -0
  41. {ingen_lib-3.1.0 → ingen_lib-3.2.0}/ingen/metadata/metadata_parser.py +0 -0
  42. {ingen_lib-3.1.0 → ingen_lib-3.2.0}/ingen/post_processor/__init__.py +0 -0
  43. {ingen_lib-3.1.0 → ingen_lib-3.2.0}/ingen/post_processor/common_post_processor.py +0 -0
  44. {ingen_lib-3.1.0 → ingen_lib-3.2.0}/ingen/post_processor/post_processor.py +0 -0
  45. {ingen_lib-3.1.0 → ingen_lib-3.2.0}/ingen/pre_processor/__init__.py +0 -0
  46. {ingen_lib-3.1.0 → ingen_lib-3.2.0}/ingen/pre_processor/aggregator.py +0 -0
  47. {ingen_lib-3.1.0 → ingen_lib-3.2.0}/ingen/pre_processor/aggregators.py +0 -0
  48. {ingen_lib-3.1.0 → ingen_lib-3.2.0}/ingen/pre_processor/drop_duplicates.py +0 -0
  49. {ingen_lib-3.1.0 → ingen_lib-3.2.0}/ingen/pre_processor/filter.py +0 -0
  50. {ingen_lib-3.1.0 → ingen_lib-3.2.0}/ingen/pre_processor/json_array_expander.py +0 -0
  51. {ingen_lib-3.1.0 → ingen_lib-3.2.0}/ingen/pre_processor/mask.py +0 -0
  52. {ingen_lib-3.1.0 → ingen_lib-3.2.0}/ingen/pre_processor/melt.py +0 -0
  53. {ingen_lib-3.1.0 → ingen_lib-3.2.0}/ingen/pre_processor/merger.py +0 -0
  54. {ingen_lib-3.1.0 → ingen_lib-3.2.0}/ingen/pre_processor/not_equals_filter.py +0 -0
  55. {ingen_lib-3.1.0 → ingen_lib-3.2.0}/ingen/pre_processor/outer_join.py +0 -0
  56. {ingen_lib-3.1.0 → ingen_lib-3.2.0}/ingen/pre_processor/pre_processor.py +0 -0
  57. {ingen_lib-3.1.0 → ingen_lib-3.2.0}/ingen/pre_processor/process.py +0 -0
  58. {ingen_lib-3.1.0 → ingen_lib-3.2.0}/ingen/pre_processor/union.py +0 -0
  59. {ingen_lib-3.1.0 → ingen_lib-3.2.0}/ingen/reader/__init__.py +0 -0
  60. {ingen_lib-3.1.0 → ingen_lib-3.2.0}/ingen/reader/api_reader.py +0 -0
  61. {ingen_lib-3.1.0 → ingen_lib-3.2.0}/ingen/reader/data_source.py +0 -0
  62. {ingen_lib-3.1.0 → ingen_lib-3.2.0}/ingen/reader/json_reader.py +0 -0
  63. {ingen_lib-3.1.0 → ingen_lib-3.2.0}/ingen/reader/mysql_reader.py +0 -0
  64. {ingen_lib-3.1.0 → ingen_lib-3.2.0}/ingen/reader/rawdata_reader.py +0 -0
  65. {ingen_lib-3.1.0 → ingen_lib-3.2.0}/ingen/reader/xml_file_reader.py +0 -0
  66. {ingen_lib-3.1.0 → ingen_lib-3.2.0}/ingen/utils/__init__.py +0 -0
  67. {ingen_lib-3.1.0 → ingen_lib-3.2.0}/ingen/utils/app_http/__init__.py +0 -0
  68. {ingen_lib-3.1.0 → ingen_lib-3.2.0}/ingen/utils/app_http/aiohttp_retry.py +0 -0
  69. {ingen_lib-3.1.0 → ingen_lib-3.2.0}/ingen/utils/app_http/auth.py +0 -0
  70. {ingen_lib-3.1.0 → ingen_lib-3.2.0}/ingen/utils/app_http/http_request.py +0 -0
  71. {ingen_lib-3.1.0 → ingen_lib-3.2.0}/ingen/utils/app_http/http_util.py +0 -0
  72. {ingen_lib-3.1.0 → ingen_lib-3.2.0}/ingen/utils/app_http/success_criterias.py +0 -0
  73. {ingen_lib-3.1.0 → ingen_lib-3.2.0}/ingen/utils/app_secrets.py +0 -0
  74. {ingen_lib-3.1.0 → ingen_lib-3.2.0}/ingen/utils/interpolators/Interpolator.py +0 -0
  75. {ingen_lib-3.1.0 → ingen_lib-3.2.0}/ingen/utils/interpolators/__init__.py +0 -0
  76. {ingen_lib-3.1.0 → ingen_lib-3.2.0}/ingen/utils/interpolators/common_interpolators.py +0 -0
  77. {ingen_lib-3.1.0 → ingen_lib-3.2.0}/ingen/utils/json_df_convertors.py +0 -0
  78. {ingen_lib-3.1.0 → ingen_lib-3.2.0}/ingen/utils/properties.py +0 -0
  79. {ingen_lib-3.1.0 → ingen_lib-3.2.0}/ingen/utils/run_configuration.py +0 -0
  80. {ingen_lib-3.1.0 → ingen_lib-3.2.0}/ingen/utils/sql_query_parser.py +0 -0
  81. {ingen_lib-3.1.0 → ingen_lib-3.2.0}/ingen/utils/timer.py +0 -0
  82. {ingen_lib-3.1.0 → ingen_lib-3.2.0}/ingen/utils/url_constructor.py +0 -0
  83. {ingen_lib-3.1.0 → ingen_lib-3.2.0}/ingen/utils/utils.py +0 -0
  84. {ingen_lib-3.1.0 → ingen_lib-3.2.0}/ingen/validation/__init__.py +0 -0
  85. {ingen_lib-3.1.0 → ingen_lib-3.2.0}/ingen/validation/common_validations.py +0 -0
  86. {ingen_lib-3.1.0 → ingen_lib-3.2.0}/ingen/validation/notification.py +0 -0
  87. {ingen_lib-3.1.0 → ingen_lib-3.2.0}/ingen/validation/send_email.py +0 -0
  88. {ingen_lib-3.1.0 → ingen_lib-3.2.0}/ingen/validation/validations.py +0 -0
  89. {ingen_lib-3.1.0 → ingen_lib-3.2.0}/ingen/writer/__init__.py +0 -0
  90. {ingen_lib-3.1.0 → ingen_lib-3.2.0}/ingen/writer/dataframe_writer.py +0 -0
  91. {ingen_lib-3.1.0 → ingen_lib-3.2.0}/ingen/writer/json_util.py +0 -0
  92. {ingen_lib-3.1.0 → ingen_lib-3.2.0}/ingen/writer/json_writer/__init__.py +0 -0
  93. {ingen_lib-3.1.0 → ingen_lib-3.2.0}/ingen/writer/json_writer/convertors/__init__.py +0 -0
  94. {ingen_lib-3.1.0 → ingen_lib-3.2.0}/ingen/writer/json_writer/convertors/convertor_factory.py +0 -0
  95. {ingen_lib-3.1.0 → ingen_lib-3.2.0}/ingen/writer/json_writer/convertors/df_to_multiple_json_convertor.py +0 -0
  96. {ingen_lib-3.1.0 → ingen_lib-3.2.0}/ingen/writer/json_writer/convertors/df_to_single_json_convertor.py +0 -0
  97. {ingen_lib-3.1.0 → ingen_lib-3.2.0}/ingen/writer/json_writer/destinations/__init__.py +0 -0
  98. {ingen_lib-3.1.0 → ingen_lib-3.2.0}/ingen/writer/json_writer/destinations/api_destination.py +0 -0
  99. {ingen_lib-3.1.0 → ingen_lib-3.2.0}/ingen/writer/json_writer/destinations/destination_factory.py +0 -0
  100. {ingen_lib-3.1.0 → ingen_lib-3.2.0}/ingen/writer/json_writer/json_writer.py +0 -0
  101. {ingen_lib-3.1.0 → ingen_lib-3.2.0}/ingen/writer/old_json_writer.py +0 -0
  102. {ingen_lib-3.1.0 → ingen_lib-3.2.0}/ingen/writer/split_file_writer.py +0 -0
  103. {ingen_lib-3.1.0 → ingen_lib-3.2.0}/ingen/writer/util.py +0 -0
  104. {ingen_lib-3.1.0 → ingen_lib-3.2.0}/ingen_lib.egg-info/dependency_links.txt +0 -0
  105. {ingen_lib-3.1.0 → ingen_lib-3.2.0}/ingen_lib.egg-info/top_level.txt +0 -0
  106. {ingen_lib-3.1.0 → ingen_lib-3.2.0}/pyproject.toml +0 -0
  107. {ingen_lib-3.1.0 → ingen_lib-3.2.0}/setup.cfg +0 -0
  108. {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.1.0
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
@@ -16,3 +16,4 @@ class DataSourceType(Enum):
16
16
  MYSQL = "mysql"
17
17
  RawDataStore = "rawdatastore"
18
18
  JSON = "json"
19
+ Snowflake = "snowflake"
@@ -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
- result=result.convert_dtypes()
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=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.interpolator = interpolator
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, index=InterfaceWriter.SHOW_DATAFRAME_INDEX, encoding=encoding)
59
+ self._df.to_csv(path, sep, **csv_options)
56
60
  else:
57
- self._df.to_csv(path, sep, header=False, index=InterfaceWriter.SHOW_DATAFRAME_INDEX, encoding=encoding)
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
- path = self._props['path']
99
+ paths = self._props['path']
100
+ if not isinstance(paths, list):
101
+ paths = [paths]
96
102
  encoding = self._props.get('encoding', 'utf-8')
97
- file = open(path, 'r+', encoding=encoding)
98
- if header != '':
99
- lines = file.readlines()
100
- file.seek(0)
101
- file.writelines(header + '\n')
102
- for line in lines:
103
- file.write(line)
104
- if footer != '':
105
- file.read()
106
- file.write(footer)
107
- file.close()
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.1.0
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
@@ -8,4 +8,5 @@ pandas<3.0,>=2.2.2
8
8
  pycryptodome>=3.20.0
9
9
  PyMySQL>=1.1.1
10
10
  PyYAML>=6.0.2
11
+ snowflake-connector-python>=3.12.0
11
12
  xmltodict>=0.12.0
@@ -15,4 +15,5 @@ pandas>=2.2.2,<3.0
15
15
  pycryptodome>=3.20.0
16
16
  PyMySQL>=1.1.1
17
17
  PyYAML>=6.0.2
18
+ snowflake-connector-python>=3.12.0
18
19
  xmltodict>=0.12.0
@@ -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.1.0`` token below with the git tag via ``sed``. For local/editable
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.1.0'
36
+ version = 'v3.2.0'
37
37
  if version.startswith('{{'):
38
38
  return '0.0.0.dev0'
39
39
  return version
@@ -1,8 +0,0 @@
1
- # Copyright (c) 2023 BlackRock, Inc.
2
- # All Rights Reserved.
3
-
4
- class FileDestination:
5
- def handle(self, json_strings, destination_props):
6
- file_path = destination_props.get('path')
7
- with open(file_path, 'w') as file:
8
- file.writelines(json_strings)
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes