ingen-lib 3.0.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 (110) hide show
  1. {ingen_lib-3.0.0/ingen_lib.egg-info → ingen_lib-3.2.0}/PKG-INFO +7 -3
  2. {ingen_lib-3.0.0 → ingen_lib-3.2.0}/ingen/data_source/data_source_type.py +1 -0
  3. {ingen_lib-3.0.0 → ingen_lib-3.2.0}/ingen/data_source/json_source.py +1 -1
  4. ingen_lib-3.2.0/ingen/data_source/snowflake_source.py +130 -0
  5. {ingen_lib-3.0.0 → ingen_lib-3.2.0}/ingen/data_source/source_factory.py +3 -0
  6. {ingen_lib-3.0.0 → ingen_lib-3.2.0}/ingen/metadata/metadata.py +2 -1
  7. {ingen_lib-3.0.0 → ingen_lib-3.2.0}/ingen/pre_processor/outer_join.py +7 -2
  8. {ingen_lib-3.0.0 → ingen_lib-3.2.0}/ingen/reader/file_reader.py +2 -2
  9. ingen_lib-3.2.0/ingen/reader/snowflake_reader.py +32 -0
  10. {ingen_lib-3.0.0 → ingen_lib-3.2.0}/ingen/reader/xml_file_reader.py +6 -10
  11. {ingen_lib-3.0.0 → ingen_lib-3.2.0}/ingen/utils/path_parser.py +28 -2
  12. {ingen_lib-3.0.0 → ingen_lib-3.2.0}/ingen/utils/utils.py +3 -1
  13. ingen_lib-3.2.0/ingen/writer/json_writer/destinations/file_destination.py +11 -0
  14. {ingen_lib-3.0.0 → ingen_lib-3.2.0}/ingen/writer/util.py +4 -2
  15. {ingen_lib-3.0.0 → ingen_lib-3.2.0}/ingen/writer/writer.py +21 -15
  16. {ingen_lib-3.0.0 → ingen_lib-3.2.0/ingen_lib.egg-info}/PKG-INFO +7 -3
  17. {ingen_lib-3.0.0 → ingen_lib-3.2.0}/ingen_lib.egg-info/SOURCES.txt +2 -0
  18. {ingen_lib-3.0.0 → ingen_lib-3.2.0}/ingen_lib.egg-info/requires.txt +4 -2
  19. ingen_lib-3.2.0/requirements.txt +19 -0
  20. ingen_lib-3.2.0/setup.py +67 -0
  21. ingen_lib-3.0.0/ingen/writer/json_writer/destinations/file_destination.py +0 -8
  22. ingen_lib-3.0.0/requirements.txt +0 -10
  23. ingen_lib-3.0.0/setup.py +0 -33
  24. {ingen_lib-3.0.0 → ingen_lib-3.2.0}/LICENSE +0 -0
  25. {ingen_lib-3.0.0 → ingen_lib-3.2.0}/MANIFEST.in +0 -0
  26. {ingen_lib-3.0.0 → ingen_lib-3.2.0}/README.md +0 -0
  27. {ingen_lib-3.0.0 → ingen_lib-3.2.0}/ingen/__init__.py +0 -0
  28. {ingen_lib-3.0.0 → ingen_lib-3.2.0}/ingen/__main__.py +0 -0
  29. {ingen_lib-3.0.0 → ingen_lib-3.2.0}/ingen/data_source/__init__.py +0 -0
  30. {ingen_lib-3.0.0 → ingen_lib-3.2.0}/ingen/data_source/api_source.py +0 -0
  31. {ingen_lib-3.0.0 → ingen_lib-3.2.0}/ingen/data_source/dataframe_store.py +0 -0
  32. {ingen_lib-3.0.0 → ingen_lib-3.2.0}/ingen/data_source/file_source.py +0 -0
  33. {ingen_lib-3.0.0 → ingen_lib-3.2.0}/ingen/data_source/mysql_source.py +0 -0
  34. {ingen_lib-3.0.0 → ingen_lib-3.2.0}/ingen/data_source/rawdata_source.py +0 -0
  35. {ingen_lib-3.0.0 → ingen_lib-3.2.0}/ingen/data_source/source.py +0 -0
  36. {ingen_lib-3.0.0 → ingen_lib-3.2.0}/ingen/formatters/__init__.py +0 -0
  37. {ingen_lib-3.0.0 → ingen_lib-3.2.0}/ingen/formatters/common_formatters.py +0 -0
  38. {ingen_lib-3.0.0 → ingen_lib-3.2.0}/ingen/formatters/formatter.py +0 -0
  39. {ingen_lib-3.0.0 → ingen_lib-3.2.0}/ingen/formatters/utils.py +0 -0
  40. {ingen_lib-3.0.0 → ingen_lib-3.2.0}/ingen/generators/__init__.py +0 -0
  41. {ingen_lib-3.0.0 → ingen_lib-3.2.0}/ingen/generators/base_interface_generator.py +0 -0
  42. {ingen_lib-3.0.0 → ingen_lib-3.2.0}/ingen/generators/interface_generator.py +0 -0
  43. {ingen_lib-3.0.0 → ingen_lib-3.2.0}/ingen/lib/__init__.py +0 -0
  44. {ingen_lib-3.0.0 → ingen_lib-3.2.0}/ingen/lib/cryptor.py +0 -0
  45. {ingen_lib-3.0.0 → ingen_lib-3.2.0}/ingen/logger.py +0 -0
  46. {ingen_lib-3.0.0 → ingen_lib-3.2.0}/ingen/metadata/__init__.py +0 -0
  47. {ingen_lib-3.0.0 → ingen_lib-3.2.0}/ingen/metadata/metadata_parser.py +0 -0
  48. {ingen_lib-3.0.0 → ingen_lib-3.2.0}/ingen/post_processor/__init__.py +0 -0
  49. {ingen_lib-3.0.0 → ingen_lib-3.2.0}/ingen/post_processor/common_post_processor.py +0 -0
  50. {ingen_lib-3.0.0 → ingen_lib-3.2.0}/ingen/post_processor/post_processor.py +0 -0
  51. {ingen_lib-3.0.0 → ingen_lib-3.2.0}/ingen/pre_processor/__init__.py +0 -0
  52. {ingen_lib-3.0.0 → ingen_lib-3.2.0}/ingen/pre_processor/aggregator.py +0 -0
  53. {ingen_lib-3.0.0 → ingen_lib-3.2.0}/ingen/pre_processor/aggregators.py +0 -0
  54. {ingen_lib-3.0.0 → ingen_lib-3.2.0}/ingen/pre_processor/drop_duplicates.py +0 -0
  55. {ingen_lib-3.0.0 → ingen_lib-3.2.0}/ingen/pre_processor/filter.py +0 -0
  56. {ingen_lib-3.0.0 → ingen_lib-3.2.0}/ingen/pre_processor/json_array_expander.py +0 -0
  57. {ingen_lib-3.0.0 → ingen_lib-3.2.0}/ingen/pre_processor/mask.py +0 -0
  58. {ingen_lib-3.0.0 → ingen_lib-3.2.0}/ingen/pre_processor/melt.py +0 -0
  59. {ingen_lib-3.0.0 → ingen_lib-3.2.0}/ingen/pre_processor/merger.py +0 -0
  60. {ingen_lib-3.0.0 → ingen_lib-3.2.0}/ingen/pre_processor/not_equals_filter.py +0 -0
  61. {ingen_lib-3.0.0 → ingen_lib-3.2.0}/ingen/pre_processor/pre_processor.py +0 -0
  62. {ingen_lib-3.0.0 → ingen_lib-3.2.0}/ingen/pre_processor/process.py +0 -0
  63. {ingen_lib-3.0.0 → ingen_lib-3.2.0}/ingen/pre_processor/union.py +0 -0
  64. {ingen_lib-3.0.0 → ingen_lib-3.2.0}/ingen/reader/__init__.py +0 -0
  65. {ingen_lib-3.0.0 → ingen_lib-3.2.0}/ingen/reader/api_reader.py +0 -0
  66. {ingen_lib-3.0.0 → ingen_lib-3.2.0}/ingen/reader/data_source.py +0 -0
  67. {ingen_lib-3.0.0 → ingen_lib-3.2.0}/ingen/reader/json_reader.py +0 -0
  68. {ingen_lib-3.0.0 → ingen_lib-3.2.0}/ingen/reader/mysql_reader.py +0 -0
  69. {ingen_lib-3.0.0 → ingen_lib-3.2.0}/ingen/reader/rawdata_reader.py +0 -0
  70. {ingen_lib-3.0.0 → ingen_lib-3.2.0}/ingen/utils/__init__.py +0 -0
  71. {ingen_lib-3.0.0 → ingen_lib-3.2.0}/ingen/utils/app_http/__init__.py +0 -0
  72. {ingen_lib-3.0.0 → ingen_lib-3.2.0}/ingen/utils/app_http/aiohttp_retry.py +0 -0
  73. {ingen_lib-3.0.0 → ingen_lib-3.2.0}/ingen/utils/app_http/auth.py +0 -0
  74. {ingen_lib-3.0.0 → ingen_lib-3.2.0}/ingen/utils/app_http/http_request.py +0 -0
  75. {ingen_lib-3.0.0 → ingen_lib-3.2.0}/ingen/utils/app_http/http_util.py +0 -0
  76. {ingen_lib-3.0.0 → ingen_lib-3.2.0}/ingen/utils/app_http/success_criterias.py +0 -0
  77. {ingen_lib-3.0.0 → ingen_lib-3.2.0}/ingen/utils/app_secrets.py +0 -0
  78. {ingen_lib-3.0.0 → ingen_lib-3.2.0}/ingen/utils/interpolators/Interpolator.py +0 -0
  79. {ingen_lib-3.0.0 → ingen_lib-3.2.0}/ingen/utils/interpolators/__init__.py +0 -0
  80. {ingen_lib-3.0.0 → ingen_lib-3.2.0}/ingen/utils/interpolators/common_interpolators.py +0 -0
  81. {ingen_lib-3.0.0 → ingen_lib-3.2.0}/ingen/utils/json_df_convertors.py +0 -0
  82. {ingen_lib-3.0.0 → ingen_lib-3.2.0}/ingen/utils/properties.py +0 -0
  83. {ingen_lib-3.0.0 → ingen_lib-3.2.0}/ingen/utils/run_configuration.py +0 -0
  84. {ingen_lib-3.0.0 → ingen_lib-3.2.0}/ingen/utils/sql_query_parser.py +0 -0
  85. {ingen_lib-3.0.0 → ingen_lib-3.2.0}/ingen/utils/timer.py +0 -0
  86. {ingen_lib-3.0.0 → ingen_lib-3.2.0}/ingen/utils/url_constructor.py +0 -0
  87. {ingen_lib-3.0.0 → ingen_lib-3.2.0}/ingen/validation/__init__.py +0 -0
  88. {ingen_lib-3.0.0 → ingen_lib-3.2.0}/ingen/validation/common_validations.py +0 -0
  89. {ingen_lib-3.0.0 → ingen_lib-3.2.0}/ingen/validation/notification.py +0 -0
  90. {ingen_lib-3.0.0 → ingen_lib-3.2.0}/ingen/validation/send_email.py +0 -0
  91. {ingen_lib-3.0.0 → ingen_lib-3.2.0}/ingen/validation/validations.py +0 -0
  92. {ingen_lib-3.0.0 → ingen_lib-3.2.0}/ingen/writer/__init__.py +0 -0
  93. {ingen_lib-3.0.0 → ingen_lib-3.2.0}/ingen/writer/dataframe_writer.py +0 -0
  94. {ingen_lib-3.0.0 → ingen_lib-3.2.0}/ingen/writer/json_util.py +0 -0
  95. {ingen_lib-3.0.0 → ingen_lib-3.2.0}/ingen/writer/json_writer/__init__.py +0 -0
  96. {ingen_lib-3.0.0 → ingen_lib-3.2.0}/ingen/writer/json_writer/convertors/__init__.py +0 -0
  97. {ingen_lib-3.0.0 → ingen_lib-3.2.0}/ingen/writer/json_writer/convertors/convertor_factory.py +0 -0
  98. {ingen_lib-3.0.0 → ingen_lib-3.2.0}/ingen/writer/json_writer/convertors/df_to_multiple_json_convertor.py +0 -0
  99. {ingen_lib-3.0.0 → ingen_lib-3.2.0}/ingen/writer/json_writer/convertors/df_to_single_json_convertor.py +0 -0
  100. {ingen_lib-3.0.0 → ingen_lib-3.2.0}/ingen/writer/json_writer/destinations/__init__.py +0 -0
  101. {ingen_lib-3.0.0 → ingen_lib-3.2.0}/ingen/writer/json_writer/destinations/api_destination.py +0 -0
  102. {ingen_lib-3.0.0 → ingen_lib-3.2.0}/ingen/writer/json_writer/destinations/destination_factory.py +0 -0
  103. {ingen_lib-3.0.0 → ingen_lib-3.2.0}/ingen/writer/json_writer/json_writer.py +0 -0
  104. {ingen_lib-3.0.0 → ingen_lib-3.2.0}/ingen/writer/old_json_writer.py +0 -0
  105. {ingen_lib-3.0.0 → ingen_lib-3.2.0}/ingen/writer/split_file_writer.py +0 -0
  106. {ingen_lib-3.0.0 → ingen_lib-3.2.0}/ingen_lib.egg-info/dependency_links.txt +0 -0
  107. {ingen_lib-3.0.0 → ingen_lib-3.2.0}/ingen_lib.egg-info/top_level.txt +0 -0
  108. {ingen_lib-3.0.0 → ingen_lib-3.2.0}/pyproject.toml +0 -0
  109. {ingen_lib-3.0.0 → ingen_lib-3.2.0}/setup.cfg +0 -0
  110. {ingen_lib-3.0.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.0.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
@@ -9,16 +9,19 @@ License: License :: Apache License
9
9
  Classifier: License :: OSI Approved :: Apache Software License
10
10
  Classifier: Operating System :: OS Independent
11
11
  Classifier: Programming Language :: Python :: 3.12
12
+ Requires-Python: >=3.9,<3.13
12
13
  License-File: LICENSE
13
14
  Requires-Dist: aiohttp>=3.10.2
14
- Requires-Dist: great_expectations>=0.15.50
15
+ Requires-Dist: great_expectations<1.0,>=0.18.9
15
16
  Requires-Dist: holidays>=0.27.1
16
17
  Requires-Dist: hvac>=0.11.2
17
18
  Requires-Dist: numpy>=1.26.4
18
- Requires-Dist: pandas>=2.2.2
19
+ Requires-Dist: openpyxl>=3.1.0
20
+ Requires-Dist: pandas<3.0,>=2.2.2
19
21
  Requires-Dist: pycryptodome>=3.20.0
20
22
  Requires-Dist: PyMySQL>=1.1.1
21
23
  Requires-Dist: PyYAML>=6.0.2
24
+ Requires-Dist: snowflake-connector-python>=3.12.0
22
25
  Requires-Dist: xmltodict>=0.12.0
23
26
  Dynamic: classifier
24
27
  Dynamic: description
@@ -28,6 +31,7 @@ Dynamic: license-file
28
31
  Dynamic: maintainer
29
32
  Dynamic: maintainer-email
30
33
  Dynamic: requires-dist
34
+ Dynamic: requires-python
31
35
  Dynamic: summary
32
36
 
33
37
  InGen is a command line tool written on top of pandas and great_expectations to perform small scale data transformations and validations without writing code. It is designed for developers and analysts to quickly transform data by specifying their requirements in a simple YAML file.
@@ -16,3 +16,4 @@ class DataSourceType(Enum):
16
16
  MYSQL = "mysql"
17
17
  RawDataStore = "rawdatastore"
18
18
  JSON = "json"
19
+ Snowflake = "snowflake"
@@ -25,7 +25,7 @@ class JsonSource(DataSource):
25
25
  raise ValueError("JSON string is not provided")
26
26
 
27
27
  json_dict = json.loads(self._data)
28
- if not json_dict[self.id]:
28
+ if self.id not in json_dict or not json_dict[self.id]:
29
29
  raise ValueError("JSON source with ID {} does not exist".format(self.id))
30
30
  self._data = pd.json_normalize(json_dict[self.id])
31
31
  return self._data
@@ -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
 
@@ -24,10 +24,15 @@ class OuterJoin(Process):
24
24
  :return: A Pandas dataframe which is the result of the outer join process
25
25
  """
26
26
  left_dataframe = data
27
- right_dataframe = sources_data.get(config.get('source'))
27
+ source_key = config.get('source')
28
+ right_dataframe = sources_data.get(source_key)
28
29
  left_key = config.get('left_key')
29
30
  right_key = config.get('right_key')
30
-
31
+
32
+ if source_key is None:
33
+ raise KeyError("outer_join config is missing the 'source' to join against")
34
+ if right_dataframe is None:
35
+ raise KeyError(f"Source '{source_key}' not found in sources_data for outer_join")
31
36
  if left_key is not None and left_key not in left_dataframe.columns:
32
37
  raise KeyError(f"Column '{left_key}' not present in left dataframe")
33
38
  if right_key is not None and right_key not in right_dataframe.columns:
@@ -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()
@@ -4,7 +4,6 @@
4
4
  import collections
5
5
  import logging
6
6
  from pyexpat import ExpatError
7
- from xml.etree import ElementTree as et
8
7
 
9
8
  import pandas as pd
10
9
  import xmltodict
@@ -14,16 +13,13 @@ class XMLFileReader:
14
13
 
15
14
  def read(self, src):
16
15
  encoding = src.get('encoding', 'utf-8')
17
- xml_file = open(src['file_path'], 'r', encoding=encoding)
18
16
  try:
19
- data = xmltodict.parse(xml_file.read())
20
- tree = et.parse(src['file_path'])
21
- root = tree.getroot()
22
- root_with_xmlns = root.tag.split('}')
23
- if '}' in root.tag:
24
- parent_tag = root_with_xmlns[1]
25
- else:
26
- parent_tag = root.tag
17
+ with open(src['file_path'], 'r', encoding=encoding) as xml_file:
18
+ data = xmltodict.parse(xml_file.read())
19
+ # Valid XML has exactly one root element; its key in the parsed dict is the
20
+ # parent tag. Using it directly (instead of re-parsing with ElementTree) avoids
21
+ # a second file read and a namespace-prefix mismatch against xmltodict's keys.
22
+ parent_tag = next(iter(data))
27
23
  root_tag = src['root_tag']
28
24
  columns = src['columns']
29
25
  if root_tag in data[parent_tag]:
@@ -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:]
@@ -111,7 +111,9 @@ class KeyValue(argparse.Action):
111
111
  setattr(namespace, self.dest, dict())
112
112
 
113
113
  for value in values:
114
- key, value = value.split('=')
114
+ # Split on the FIRST '=' only, so values may themselves contain '=' (tokens, URLs with
115
+ # query strings, SQL fragments like "col=1"). Matches KeyValueOrString's behaviour.
116
+ key, value = value.split('=', 1)
115
117
  getattr(namespace, self.dest)[key] = value
116
118
 
117
119
 
@@ -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)
@@ -21,6 +21,8 @@ def get_custom_value(props, df, run_date):
21
21
  for prop in props:
22
22
  for key, value in prop.items():
23
23
  custom_function = get_type(key)
24
+ if custom_function is None:
25
+ raise ValueError(f"Unknown header/footer prop type: '{key}'")
24
26
  custom_string = custom_string + custom_function(value, df=df, run_date=run_date)
25
27
  return custom_string
26
28
 
@@ -103,8 +105,8 @@ def get_new_line(line, **kwargs):
103
105
  Takes a boolean input and adds a new line if bool value is true
104
106
  """
105
107
  if line:
106
- newline = '\n'
107
- return newline
108
+ return '\n'
109
+ return ''
108
110
 
109
111
 
110
112
  def sum_of_substr(props, **kwargs):
@@ -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.0.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
@@ -9,16 +9,19 @@ License: License :: Apache License
9
9
  Classifier: License :: OSI Approved :: Apache Software License
10
10
  Classifier: Operating System :: OS Independent
11
11
  Classifier: Programming Language :: Python :: 3.12
12
+ Requires-Python: >=3.9,<3.13
12
13
  License-File: LICENSE
13
14
  Requires-Dist: aiohttp>=3.10.2
14
- Requires-Dist: great_expectations>=0.15.50
15
+ Requires-Dist: great_expectations<1.0,>=0.18.9
15
16
  Requires-Dist: holidays>=0.27.1
16
17
  Requires-Dist: hvac>=0.11.2
17
18
  Requires-Dist: numpy>=1.26.4
18
- Requires-Dist: pandas>=2.2.2
19
+ Requires-Dist: openpyxl>=3.1.0
20
+ Requires-Dist: pandas<3.0,>=2.2.2
19
21
  Requires-Dist: pycryptodome>=3.20.0
20
22
  Requires-Dist: PyMySQL>=1.1.1
21
23
  Requires-Dist: PyYAML>=6.0.2
24
+ Requires-Dist: snowflake-connector-python>=3.12.0
22
25
  Requires-Dist: xmltodict>=0.12.0
23
26
  Dynamic: classifier
24
27
  Dynamic: description
@@ -28,6 +31,7 @@ Dynamic: license-file
28
31
  Dynamic: maintainer
29
32
  Dynamic: maintainer-email
30
33
  Dynamic: requires-dist
34
+ Dynamic: requires-python
31
35
  Dynamic: summary
32
36
 
33
37
  InGen is a command line tool written on top of pandas and great_expectations to perform small scale data transformations and validations without writing code. It is designed for developers and analysts to quickly transform data by specifying their requirements in a simple YAML file.
@@ -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
@@ -1,10 +1,12 @@
1
1
  aiohttp>=3.10.2
2
- great_expectations>=0.15.50
2
+ great_expectations<1.0,>=0.18.9
3
3
  holidays>=0.27.1
4
4
  hvac>=0.11.2
5
5
  numpy>=1.26.4
6
- pandas>=2.2.2
6
+ openpyxl>=3.1.0
7
+ pandas<3.0,>=2.2.2
7
8
  pycryptodome>=3.20.0
8
9
  PyMySQL>=1.1.1
9
10
  PyYAML>=6.0.2
11
+ snowflake-connector-python>=3.12.0
10
12
  xmltodict>=0.12.0
@@ -0,0 +1,19 @@
1
+ aiohttp>=3.10.2
2
+ # Cap below 1.0: InGen uses the legacy great_expectations Dataset API (ge.from_pandas + the
3
+ # expect_* methods on the returned object), which was removed in GE 1.0. The 0.18.x line is the
4
+ # last to retain that API and also ships Python 3.12 wheels.
5
+ great_expectations>=0.18.9,<1.0
6
+ holidays>=0.27.1
7
+ hvac>=0.11.2
8
+ numpy>=1.26.4
9
+ # pandas does not require openpyxl by default; ingen's own file_reader/writer call
10
+ # pd.read_excel/to_excel(engine='openpyxl') for .xlsx, so it must be a direct dependency.
11
+ openpyxl>=3.1.0
12
+ # Cap below 3.0: pandas 3.0 is a breaking major (Copy-on-Write becomes the default, deprecated
13
+ # APIs removed). InGen's formatters/readers are written against the pandas 2.x behaviour.
14
+ pandas>=2.2.2,<3.0
15
+ pycryptodome>=3.20.0
16
+ PyMySQL>=1.1.1
17
+ PyYAML>=6.0.2
18
+ snowflake-connector-python>=3.12.0
19
+ xmltodict>=0.12.0
@@ -0,0 +1,67 @@
1
+ # Copyright (c) 2023 BlackRock, Inc.
2
+ # All Rights Reserved.
3
+
4
+ import os
5
+
6
+ import setuptools
7
+ from setuptools import setup
8
+
9
+ PKG_NAME = 'ingen-lib'
10
+ MAIN_PKG = 'ingen'
11
+ VERSION_PY_FILE = os.path.join(MAIN_PKG, 'version.py')
12
+
13
+
14
+ def read_requirements():
15
+ """Parse requirements.txt for install_requires, ignoring blank lines and comments.
16
+
17
+ The previous ``open(...).read().splitlines()`` passed every line through verbatim, so any
18
+ comment or blank line became an invalid requirement. This makes the manifest safely
19
+ annotatable (e.g. documenting why a version is pinned).
20
+ """
21
+ with open('requirements.txt') as fh:
22
+ lines = [line.strip() for line in fh]
23
+ return [line for line in lines if line and not line.startswith('#')]
24
+
25
+
26
+ def resolve_version():
27
+ """Resolve the package version.
28
+
29
+ At release time the CI workflow (.github/workflows/python-publish.yml) replaces the
30
+ ``v3.2.0`` token below with the git tag via ``sed``. For local/editable
31
+ installs the token is left intact, which is NOT a valid PEP 440 version and breaks
32
+ ``pip install -e .``. So when the token has not been substituted, fall back to a valid
33
+ development version. The literal token is preserved verbatim so the existing CI ``sed`` keeps
34
+ working unchanged.
35
+ """
36
+ version = 'v3.2.0'
37
+ if version.startswith('{{'):
38
+ return '0.0.0.dev0'
39
+ return version
40
+
41
+
42
+ setup(name=PKG_NAME,
43
+ version=resolve_version(),
44
+ # Upper bound is real, not arbitrary: InGen uses the legacy great_expectations API, which
45
+ # requires numpy<2. numpy<2 only ships wheels through CPython 3.12, so on 3.13+ pip would try
46
+ # to build numpy from source (needs a C compiler). Capping here makes pip reject 3.13+ with a
47
+ # clear "Requires-Python" message instead of a confusing build failure.
48
+ python_requires='>=3.9,<3.13',
49
+ packages=setuptools.find_packages(include=['ingen', 'ingen.*']),
50
+ package_data={},
51
+ description='A Python script suite that generates interface files based on the given interface metadata/config '
52
+ 'file',
53
+ install_requires=read_requirements(),
54
+ long_description="InGen is a command line tool written on top of pandas and great_expectations to perform small "
55
+ "scale data transformations and validations without writing code. It is designed for "
56
+ "developers and analysts to quickly transform data by specifying their requirements in a "
57
+ "simple YAML file.",
58
+ classifiers=[
59
+ 'License :: OSI Approved :: Apache Software License',
60
+ 'Operating System :: OS Independent',
61
+ 'Programming Language :: Python :: 3.12'
62
+ ],
63
+ license='License :: Apache License',
64
+ maintainer='Swarna Dhakad, Piyush Ranjan, Jatin Varlyani, Pooja Katariya',
65
+ maintainer_email='swarna.dhakad@gmail.com, piyushranjan95@gmail.com, varlyanijatin88@gmail.com, '
66
+ 'poojakatariya1811@gmail.com',
67
+ url='https://github.com/blackrock/interface-generator')
@@ -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)
@@ -1,10 +0,0 @@
1
- aiohttp>=3.10.2
2
- great_expectations>=0.15.50
3
- holidays>=0.27.1
4
- hvac>=0.11.2
5
- numpy>=1.26.4
6
- pandas>=2.2.2
7
- pycryptodome>=3.20.0
8
- PyMySQL>=1.1.1
9
- PyYAML>=6.0.2
10
- xmltodict>=0.12.0
ingen_lib-3.0.0/setup.py DELETED
@@ -1,33 +0,0 @@
1
- # Copyright (c) 2023 BlackRock, Inc.
2
- # All Rights Reserved.
3
-
4
- import os
5
-
6
- import setuptools
7
- from setuptools import setup
8
-
9
- PKG_NAME = 'ingen-lib'
10
- MAIN_PKG = 'ingen'
11
- VERSION_PY_FILE = os.path.join(MAIN_PKG, 'version.py')
12
-
13
- setup(name=PKG_NAME,
14
- version='v3.0.0',
15
- packages=setuptools.find_packages(include=['ingen', 'ingen.*']),
16
- package_data={},
17
- description='A Python script suite that generates interface files based on the given interface metadata/config '
18
- 'file',
19
- install_requires=open('requirements.txt').read().splitlines(),
20
- long_description="InGen is a command line tool written on top of pandas and great_expectations to perform small "
21
- "scale data transformations and validations without writing code. It is designed for "
22
- "developers and analysts to quickly transform data by specifying their requirements in a "
23
- "simple YAML file.",
24
- classifiers=[
25
- 'License :: OSI Approved :: Apache Software License',
26
- 'Operating System :: OS Independent',
27
- 'Programming Language :: Python :: 3.12'
28
- ],
29
- license='License :: Apache License',
30
- maintainer='Swarna Dhakad, Piyush Ranjan, Jatin Varlyani, Pooja Katariya',
31
- maintainer_email='swarna.dhakad@gmail.com, piyushranjan95@gmail.com, varlyanijatin88@gmail.com, '
32
- 'poojakatariya1811@gmail.com',
33
- url='https://github.com/blackrock/interface-generator')
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes