mageml-singer-python 5.13.0.post3__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- mageml_singer_python-5.13.0.post3.dist-info/METADATA +14 -0
- mageml_singer_python-5.13.0.post3.dist-info/RECORD +19 -0
- mageml_singer_python-5.13.0.post3.dist-info/WHEEL +5 -0
- mageml_singer_python-5.13.0.post3.dist-info/licenses/LICENSE +177 -0
- mageml_singer_python-5.13.0.post3.dist-info/top_level.txt +1 -0
- singer/__init__.py +86 -0
- singer/bookmarks.py +46 -0
- singer/catalog.py +156 -0
- singer/exceptions.py +30 -0
- singer/logger.py +54 -0
- singer/logging.conf +24 -0
- singer/messages.py +287 -0
- singer/metadata.py +46 -0
- singer/metrics.py +248 -0
- singer/requests.py +6 -0
- singer/schema.py +111 -0
- singer/statediff.py +70 -0
- singer/transform.py +422 -0
- singer/utils.py +311 -0
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: mageml-singer-python
|
|
3
|
+
Version: 5.13.0.post3
|
|
4
|
+
Summary: Singer protocol utilities used by Mage connectors.
|
|
5
|
+
License-Expression: Apache-2.0
|
|
6
|
+
Requires-Python: <3.15,>=3.12
|
|
7
|
+
License-File: LICENSE
|
|
8
|
+
Requires-Dist: pytz>=2018.4
|
|
9
|
+
Requires-Dist: jsonschema<5,>=4.25
|
|
10
|
+
Requires-Dist: simplejson<5,>=3.19
|
|
11
|
+
Requires-Dist: python-dateutil<3,>=2.8
|
|
12
|
+
Requires-Dist: backoff<3,>=2.2
|
|
13
|
+
Requires-Dist: ciso8601<3,>=2.3
|
|
14
|
+
Dynamic: license-file
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
mageml_singer_python-5.13.0.post3.dist-info/licenses/LICENSE,sha256=DVQuDIgE45qn836wDaWnYhSdxoLXgpRRKH4RuTjpRZQ,10174
|
|
2
|
+
singer/__init__.py,sha256=eAaQgIfu_oH7DzxSLUrQTzEaSSFjbyQlz-DtLTBNpaM,1519
|
|
3
|
+
singer/bookmarks.py,sha256=nRmDdOwHPUNTU-0S-ZIo6UprOQU8n7eZNPAjr-xWHes,1713
|
|
4
|
+
singer/catalog.py,sha256=EDxDt4A5Ow-HR4vXL65sMjqCpsws2dGQQSc9fL_Xtuk,5495
|
|
5
|
+
singer/exceptions.py,sha256=li5cu5XJv8rjI9s8MEln4pT8z4EUkOErkeQNz5rDUis,1011
|
|
6
|
+
singer/logger.py,sha256=pEAXrEWCBikdisQo70pMd1bJ4NP89rcQ0uDR9Oa9obY,1545
|
|
7
|
+
singer/logging.conf,sha256=erahU2eOyFu9aZMWaSjQb-oUfqucntt4RJ7uunrN-as,297
|
|
8
|
+
singer/messages.py,sha256=wqku7_8jkIio9XAjB84aKipcjT-dcXEEtfZWo91iCWw,8819
|
|
9
|
+
singer/metadata.py,sha256=pRT2B_N9n3Q7dHB9uTyL1mN2t72NG25TfcynR9xAHgc,1746
|
|
10
|
+
singer/metrics.py,sha256=LLj7--VbCeDTl0jARIP4jYY5py_Wfeu3ISKzKWenN-k,7434
|
|
11
|
+
singer/requests.py,sha256=3VgtbgfL9YSrR0eYSSRrBZ95XV5EaAhI3CkJBK2mPgM,210
|
|
12
|
+
singer/schema.py,sha256=Zo1sPlQt_WxXfWQxXxCJ9XWBbFk1AQmunetvRLLUzK0,3461
|
|
13
|
+
singer/statediff.py,sha256=n9c138rtQN93eRbyX8-cVH0K8NKnNA4pCgEwlwtmlnU,2331
|
|
14
|
+
singer/transform.py,sha256=cyIJ9nX-JMpOGvr-38mlAoE4-x1c_rOypHiBVNa7CbI,15447
|
|
15
|
+
singer/utils.py,sha256=8UVIFUAFun4L91cp1rGcaCir83Q9JrBAShQM2Jf1Ud8,8677
|
|
16
|
+
mageml_singer_python-5.13.0.post3.dist-info/METADATA,sha256=xdPd-PCaF5i6qNtrAfhuPzBUm0ZEJCCVEJ54djloEEg,436
|
|
17
|
+
mageml_singer_python-5.13.0.post3.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
|
|
18
|
+
mageml_singer_python-5.13.0.post3.dist-info/top_level.txt,sha256=IGORWoMUQyjv9mq8dYxOGmiC3puxuBE1itWgNtVeJ9g,7
|
|
19
|
+
mageml_singer_python-5.13.0.post3.dist-info/RECORD,,
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
singer
|
singer/__init__.py
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
from singer import utils
|
|
2
|
+
from singer.utils import (
|
|
3
|
+
chunk,
|
|
4
|
+
load_json,
|
|
5
|
+
parse_args,
|
|
6
|
+
ratelimit,
|
|
7
|
+
strftime,
|
|
8
|
+
strptime,
|
|
9
|
+
update_state,
|
|
10
|
+
should_sync_field,
|
|
11
|
+
)
|
|
12
|
+
|
|
13
|
+
from singer.logger import (
|
|
14
|
+
get_logger,
|
|
15
|
+
log_debug,
|
|
16
|
+
log_info,
|
|
17
|
+
log_warning,
|
|
18
|
+
log_error,
|
|
19
|
+
log_critical,
|
|
20
|
+
log_fatal,
|
|
21
|
+
log_exception,
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
from singer.metrics import (
|
|
25
|
+
Counter,
|
|
26
|
+
Timer,
|
|
27
|
+
http_request_timer,
|
|
28
|
+
job_timer,
|
|
29
|
+
record_counter,
|
|
30
|
+
)
|
|
31
|
+
|
|
32
|
+
from singer.messages import (
|
|
33
|
+
ActivateVersionMessage,
|
|
34
|
+
Message,
|
|
35
|
+
RecordMessage,
|
|
36
|
+
SchemaMessage,
|
|
37
|
+
StateMessage,
|
|
38
|
+
format_message,
|
|
39
|
+
parse_message,
|
|
40
|
+
write_message,
|
|
41
|
+
write_record,
|
|
42
|
+
write_records,
|
|
43
|
+
write_schema,
|
|
44
|
+
write_state,
|
|
45
|
+
write_version,
|
|
46
|
+
)
|
|
47
|
+
|
|
48
|
+
from singer.transform import (
|
|
49
|
+
NO_INTEGER_DATETIME_PARSING,
|
|
50
|
+
UNIX_SECONDS_INTEGER_DATETIME_PARSING,
|
|
51
|
+
UNIX_MILLISECONDS_INTEGER_DATETIME_PARSING,
|
|
52
|
+
Transformer,
|
|
53
|
+
transform,
|
|
54
|
+
_transform_datetime,
|
|
55
|
+
resolve_schema_references
|
|
56
|
+
)
|
|
57
|
+
|
|
58
|
+
from singer.catalog import (
|
|
59
|
+
Catalog,
|
|
60
|
+
CatalogEntry
|
|
61
|
+
)
|
|
62
|
+
from singer.schema import Schema
|
|
63
|
+
|
|
64
|
+
from singer.bookmarks import (
|
|
65
|
+
write_bookmark,
|
|
66
|
+
get_bookmark,
|
|
67
|
+
clear_bookmark,
|
|
68
|
+
reset_stream,
|
|
69
|
+
set_offset,
|
|
70
|
+
clear_offset,
|
|
71
|
+
get_offset,
|
|
72
|
+
set_currently_syncing,
|
|
73
|
+
get_currently_syncing,
|
|
74
|
+
)
|
|
75
|
+
|
|
76
|
+
from singer.exceptions import (
|
|
77
|
+
SingerConfigurationError,
|
|
78
|
+
SingerDiscoveryError,
|
|
79
|
+
SingerError,
|
|
80
|
+
SingerRetryableRequestError,
|
|
81
|
+
SingerSyncError,
|
|
82
|
+
)
|
|
83
|
+
|
|
84
|
+
if __name__ == "__main__":
|
|
85
|
+
import doctest
|
|
86
|
+
doctest.testmod()
|
singer/bookmarks.py
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
def ensure_bookmark_path(state, path):
|
|
2
|
+
submap = state
|
|
3
|
+
for path_component in path:
|
|
4
|
+
if submap.get(path_component) is None:
|
|
5
|
+
submap[path_component] = {}
|
|
6
|
+
|
|
7
|
+
submap = submap[path_component]
|
|
8
|
+
return state
|
|
9
|
+
|
|
10
|
+
def write_bookmark(state, tap_stream_id, key, val):
|
|
11
|
+
state = ensure_bookmark_path(state, ['bookmarks', tap_stream_id])
|
|
12
|
+
state['bookmarks'][tap_stream_id][key] = val
|
|
13
|
+
return state
|
|
14
|
+
|
|
15
|
+
def clear_bookmark(state, tap_stream_id, key):
|
|
16
|
+
state = ensure_bookmark_path(state, ['bookmarks', tap_stream_id])
|
|
17
|
+
state['bookmarks'][tap_stream_id].pop(key, None)
|
|
18
|
+
return state
|
|
19
|
+
|
|
20
|
+
def reset_stream(state, tap_stream_id):
|
|
21
|
+
state = ensure_bookmark_path(state, ['bookmarks', tap_stream_id])
|
|
22
|
+
state['bookmarks'][tap_stream_id] = {}
|
|
23
|
+
return state
|
|
24
|
+
|
|
25
|
+
def get_bookmark(state, tap_stream_id, key, default=None):
|
|
26
|
+
return state.get('bookmarks', {}).get(tap_stream_id, {}).get(key, default)
|
|
27
|
+
|
|
28
|
+
def set_offset(state, tap_stream_id, offset_key, offset_value):
|
|
29
|
+
state = ensure_bookmark_path(state, ['bookmarks', tap_stream_id, "offset", offset_key])
|
|
30
|
+
state['bookmarks'][tap_stream_id]["offset"][offset_key] = offset_value
|
|
31
|
+
return state
|
|
32
|
+
|
|
33
|
+
def clear_offset(state, tap_stream_id):
|
|
34
|
+
state = ensure_bookmark_path(state, ['bookmarks', tap_stream_id, "offset"])
|
|
35
|
+
state['bookmarks'][tap_stream_id]["offset"] = {}
|
|
36
|
+
return state
|
|
37
|
+
|
|
38
|
+
def get_offset(state, tap_stream_id, default=None):
|
|
39
|
+
return state.get('bookmarks', {}).get(tap_stream_id, {}).get("offset", default)
|
|
40
|
+
|
|
41
|
+
def set_currently_syncing(state, tap_stream_id):
|
|
42
|
+
state['currently_syncing'] = tap_stream_id
|
|
43
|
+
return state
|
|
44
|
+
|
|
45
|
+
def get_currently_syncing(state, default=None):
|
|
46
|
+
return state.get('currently_syncing', default)
|
singer/catalog.py
ADDED
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
'''Provides an object model for a Singer Catalog.'''
|
|
2
|
+
import json
|
|
3
|
+
import sys
|
|
4
|
+
|
|
5
|
+
from . import metadata as metadata_module
|
|
6
|
+
from .bookmarks import get_currently_syncing
|
|
7
|
+
from .logger import get_logger
|
|
8
|
+
from .schema import Schema
|
|
9
|
+
|
|
10
|
+
LOGGER = get_logger()
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def write_catalog(catalog):
|
|
14
|
+
# If the catalog has no streams, log a warning
|
|
15
|
+
if not catalog.streams:
|
|
16
|
+
LOGGER.warning("Catalog being written with no streams.")
|
|
17
|
+
|
|
18
|
+
json.dump(catalog.to_dict(), sys.stdout, indent=2)
|
|
19
|
+
|
|
20
|
+
# pylint: disable=too-many-instance-attributes
|
|
21
|
+
class CatalogEntry():
|
|
22
|
+
|
|
23
|
+
def __init__(self, tap_stream_id=None, stream=None,
|
|
24
|
+
key_properties=None, schema=None, replication_key=None,
|
|
25
|
+
is_view=None, database=None, table=None, row_count=None,
|
|
26
|
+
stream_alias=None, metadata=None, replication_method=None):
|
|
27
|
+
|
|
28
|
+
self.tap_stream_id = tap_stream_id
|
|
29
|
+
self.stream = stream
|
|
30
|
+
self.key_properties = key_properties
|
|
31
|
+
self.schema = schema
|
|
32
|
+
self.replication_key = replication_key
|
|
33
|
+
self.replication_method = replication_method
|
|
34
|
+
self.is_view = is_view
|
|
35
|
+
self.database = database
|
|
36
|
+
self.table = table
|
|
37
|
+
self.row_count = row_count
|
|
38
|
+
self.stream_alias = stream_alias
|
|
39
|
+
self.metadata = metadata
|
|
40
|
+
|
|
41
|
+
def __str__(self):
|
|
42
|
+
return str(self.__dict__)
|
|
43
|
+
|
|
44
|
+
def __eq__(self, other):
|
|
45
|
+
return self.__dict__ == other.__dict__
|
|
46
|
+
|
|
47
|
+
def is_selected(self):
|
|
48
|
+
mdata = metadata_module.to_map(self.metadata)
|
|
49
|
+
# pylint: disable=no-member
|
|
50
|
+
return self.schema.selected or metadata_module.get(mdata, (), 'selected')
|
|
51
|
+
|
|
52
|
+
def to_dict(self):
|
|
53
|
+
result = {}
|
|
54
|
+
if self.tap_stream_id:
|
|
55
|
+
result['tap_stream_id'] = self.tap_stream_id
|
|
56
|
+
if self.database:
|
|
57
|
+
result['database_name'] = self.database
|
|
58
|
+
if self.table:
|
|
59
|
+
result['table_name'] = self.table
|
|
60
|
+
if self.replication_key is not None:
|
|
61
|
+
result['replication_key'] = self.replication_key
|
|
62
|
+
if self.replication_method is not None:
|
|
63
|
+
result['replication_method'] = self.replication_method
|
|
64
|
+
if self.key_properties is not None:
|
|
65
|
+
result['key_properties'] = self.key_properties
|
|
66
|
+
if self.schema is not None:
|
|
67
|
+
schema = self.schema.to_dict() # pylint: disable=no-member
|
|
68
|
+
result['schema'] = schema
|
|
69
|
+
if self.is_view is not None:
|
|
70
|
+
result['is_view'] = self.is_view
|
|
71
|
+
if self.stream is not None:
|
|
72
|
+
result['stream'] = self.stream
|
|
73
|
+
if self.row_count is not None:
|
|
74
|
+
result['row_count'] = self.row_count
|
|
75
|
+
if self.stream_alias is not None:
|
|
76
|
+
result['stream_alias'] = self.stream_alias
|
|
77
|
+
if self.metadata is not None:
|
|
78
|
+
result['metadata'] = self.metadata
|
|
79
|
+
return result
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
class Catalog():
|
|
83
|
+
|
|
84
|
+
def __init__(self, streams):
|
|
85
|
+
self.streams = streams
|
|
86
|
+
|
|
87
|
+
def __str__(self):
|
|
88
|
+
return str(self.__dict__)
|
|
89
|
+
|
|
90
|
+
def __eq__(self, other):
|
|
91
|
+
return self.__dict__ == other.__dict__
|
|
92
|
+
|
|
93
|
+
@classmethod
|
|
94
|
+
def load(cls, filename):
|
|
95
|
+
with open(filename) as fp: # pylint: disable=invalid-name
|
|
96
|
+
return Catalog.from_dict(json.load(fp))
|
|
97
|
+
|
|
98
|
+
@classmethod
|
|
99
|
+
def from_dict(cls, data):
|
|
100
|
+
# TODO: We may want to store streams as a dict where the key is a
|
|
101
|
+
# tap_stream_id and the value is a CatalogEntry. This will allow
|
|
102
|
+
# faster lookup based on tap_stream_id. This would be a breaking
|
|
103
|
+
# change, since callers typically access the streams property
|
|
104
|
+
# directly.
|
|
105
|
+
streams = []
|
|
106
|
+
for stream in data['streams']:
|
|
107
|
+
entry = CatalogEntry()
|
|
108
|
+
entry.tap_stream_id = stream.get('tap_stream_id')
|
|
109
|
+
entry.stream = stream.get('stream')
|
|
110
|
+
entry.replication_key = stream.get('replication_key')
|
|
111
|
+
entry.key_properties = stream.get('key_properties')
|
|
112
|
+
entry.database = stream.get('database_name')
|
|
113
|
+
entry.table = stream.get('table_name')
|
|
114
|
+
entry.schema = Schema.from_dict(stream.get('schema'))
|
|
115
|
+
entry.is_view = stream.get('is_view')
|
|
116
|
+
entry.stream_alias = stream.get('stream_alias')
|
|
117
|
+
entry.metadata = stream.get('metadata')
|
|
118
|
+
entry.replication_method = stream.get('replication_method')
|
|
119
|
+
streams.append(entry)
|
|
120
|
+
return Catalog(streams)
|
|
121
|
+
|
|
122
|
+
def to_dict(self):
|
|
123
|
+
return {'streams': [stream.to_dict() for stream in self.streams]}
|
|
124
|
+
|
|
125
|
+
def dump(self):
|
|
126
|
+
json.dump(self.to_dict(), sys.stdout, indent=2)
|
|
127
|
+
|
|
128
|
+
def get_stream(self, tap_stream_id):
|
|
129
|
+
for stream in self.streams:
|
|
130
|
+
if stream.tap_stream_id == tap_stream_id:
|
|
131
|
+
return stream
|
|
132
|
+
return None
|
|
133
|
+
|
|
134
|
+
def _shuffle_streams(self, state):
|
|
135
|
+
currently_syncing = get_currently_syncing(state)
|
|
136
|
+
|
|
137
|
+
if currently_syncing is None:
|
|
138
|
+
return self.streams
|
|
139
|
+
|
|
140
|
+
matching_index = 0
|
|
141
|
+
for i, catalog_entry in enumerate(self.streams):
|
|
142
|
+
if catalog_entry.tap_stream_id == currently_syncing:
|
|
143
|
+
matching_index = i
|
|
144
|
+
break
|
|
145
|
+
top_half = self.streams[matching_index:]
|
|
146
|
+
bottom_half = self.streams[:matching_index]
|
|
147
|
+
return top_half + bottom_half
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
def get_selected_streams(self, state):
|
|
151
|
+
for stream in self._shuffle_streams(state):
|
|
152
|
+
if not stream.is_selected():
|
|
153
|
+
LOGGER.info('Skipping stream: %s', stream.tap_stream_id)
|
|
154
|
+
continue
|
|
155
|
+
|
|
156
|
+
yield stream
|
singer/exceptions.py
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"""
|
|
2
|
+
The exceptions module contains Exception subclasses whose instances might be
|
|
3
|
+
raised by the singer library or taps that use the singer library.
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
class SingerError(Exception):
|
|
7
|
+
"""The base Exeception class for singer"""
|
|
8
|
+
def __init__(self, message):
|
|
9
|
+
"""Create an exeception with a multiline error message
|
|
10
|
+
|
|
11
|
+
The first line is the error's class name. The subsequent lines are
|
|
12
|
+
the message that class was created with.
|
|
13
|
+
"""
|
|
14
|
+
super().__init__('{}\n{}'.format(self.__class__.__name__, message))
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class SingerConfigurationError(SingerError):
|
|
18
|
+
"""The base class of errors encountered before discovery and before sync mode"""
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class SingerDiscoveryError(SingerError):
|
|
22
|
+
"""The base class of errors encountered in discovery mode"""
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
class SingerSyncError(SingerError):
|
|
26
|
+
"""The base class of errors encountered in sync mode"""
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
class SingerRetryableRequestError(SingerError):
|
|
30
|
+
"""This error is meant to be thrown when a tap encounters a retryable request"""
|
singer/logger.py
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import logging
|
|
2
|
+
import logging.config
|
|
3
|
+
import os
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def get_logger():
|
|
7
|
+
"""Return a Logger instance appropriate for using in a Tap or a Target."""
|
|
8
|
+
# this_dir, _ = os.path.split(__file__)
|
|
9
|
+
# path = os.path.join(this_dir, 'logging.conf')
|
|
10
|
+
# See
|
|
11
|
+
# https://docs.python.org/3.5/library/logging.config.html#logging.config.fileConfig
|
|
12
|
+
# for a discussion of why or why not to set disable_existing_loggers
|
|
13
|
+
# to False. The long and short of it is that if you don't set it to
|
|
14
|
+
# False it ruins external module's abilities to use the logging
|
|
15
|
+
# facility.
|
|
16
|
+
# logging.config.fileConfig(path, disable_existing_loggers=False)
|
|
17
|
+
logger = logging.getLogger('singer')
|
|
18
|
+
|
|
19
|
+
logger.setLevel(logging.INFO)
|
|
20
|
+
handler = logging.StreamHandler()
|
|
21
|
+
handler.setFormatter(logging.Formatter('%(levelname)s %(message)s'))
|
|
22
|
+
for h in logger.handlers[:]:
|
|
23
|
+
logger.removeHandler(h)
|
|
24
|
+
logger.addHandler(handler)
|
|
25
|
+
|
|
26
|
+
return logger
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def log_debug(msg, *args, **kwargs):
|
|
30
|
+
get_logger().debug(msg, *args, **kwargs)
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def log_info(msg, *args, **kwargs):
|
|
34
|
+
get_logger().info(msg, *args, **kwargs)
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def log_warning(msg, *args, **kwargs):
|
|
38
|
+
get_logger().warning(msg, *args, **kwargs)
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def log_error(msg, *args, **kwargs):
|
|
42
|
+
get_logger().error(msg, *args, **kwargs)
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def log_critical(msg, *args, **kwargs):
|
|
46
|
+
get_logger().critical(msg, *args, **kwargs)
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def log_fatal(msg, *args, **kwargs):
|
|
50
|
+
get_logger().fatal(msg, *args, **kwargs)
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def log_exception(msg, *args, **kwargs):
|
|
54
|
+
get_logger().exception(msg, *args, **kwargs)
|
singer/logging.conf
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
[loggers]
|
|
2
|
+
keys=root
|
|
3
|
+
|
|
4
|
+
[handlers]
|
|
5
|
+
keys=stderr
|
|
6
|
+
|
|
7
|
+
[formatters]
|
|
8
|
+
keys=child
|
|
9
|
+
|
|
10
|
+
[logger_root]
|
|
11
|
+
level=INFO
|
|
12
|
+
handlers=stderr
|
|
13
|
+
formatter=child
|
|
14
|
+
propagate=0
|
|
15
|
+
|
|
16
|
+
[handler_stderr]
|
|
17
|
+
class=StreamHandler
|
|
18
|
+
formatter=child
|
|
19
|
+
args=(sys.stderr,)
|
|
20
|
+
|
|
21
|
+
[formatter_child]
|
|
22
|
+
class=logging.Formatter
|
|
23
|
+
format=%(levelname)s %(message)s
|
|
24
|
+
datefmt=
|