dbt-db2 1.0.0.post1__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.
- dbt_db2-1.0.0.post1/LICENSE +201 -0
- dbt_db2-1.0.0.post1/PKG-INFO +123 -0
- dbt_db2-1.0.0.post1/README.md +98 -0
- dbt_db2-1.0.0.post1/dbt/adapters/ibmdb2/__init__.py +17 -0
- dbt_db2-1.0.0.post1/dbt/adapters/ibmdb2/__version__.py +1 -0
- dbt_db2-1.0.0.post1/dbt/adapters/ibmdb2/_env_bootstrap.py +55 -0
- dbt_db2-1.0.0.post1/dbt/adapters/ibmdb2/column.py +50 -0
- dbt_db2-1.0.0.post1/dbt/adapters/ibmdb2/connections.py +126 -0
- dbt_db2-1.0.0.post1/dbt/adapters/ibmdb2/impl.py +118 -0
- dbt_db2-1.0.0.post1/dbt/adapters/ibmdb2/relation.py +29 -0
- dbt_db2-1.0.0.post1/dbt/include/ibmdb2/__init__.py +2 -0
- dbt_db2-1.0.0.post1/dbt/include/ibmdb2/dbt_project.yml +10 -0
- dbt_db2-1.0.0.post1/dbt/include/ibmdb2/macros/adapters.sql +272 -0
- dbt_db2-1.0.0.post1/dbt/include/ibmdb2/macros/apply_grants.sql +22 -0
- dbt_db2-1.0.0.post1/dbt/include/ibmdb2/macros/catalog.sql +56 -0
- dbt_db2-1.0.0.post1/dbt/include/ibmdb2/macros/materializations/incremental/incremental.sql +94 -0
- dbt_db2-1.0.0.post1/dbt/include/ibmdb2/macros/materializations/seeds/helpers.sql +3 -0
- dbt_db2-1.0.0.post1/dbt/include/ibmdb2/macros/materializations/table/table.sql +66 -0
- dbt_db2-1.0.0.post1/dbt/include/ibmdb2/macros/materializations/view/view.sql +73 -0
- dbt_db2-1.0.0.post1/dbt/include/ibmdb2/macros/utils/datatypes.sql +3 -0
- dbt_db2-1.0.0.post1/dbt/include/ibmdb2/macros/utils/dateadd.sql +5 -0
- dbt_db2-1.0.0.post1/dbt/include/ibmdb2/macros/utils/datediff.sql +49 -0
- dbt_db2-1.0.0.post1/dbt/include/ibmdb2/macros/utils/hash.sql +3 -0
- dbt_db2-1.0.0.post1/dbt/include/ibmdb2/macros/utils/last_day.sql +13 -0
- dbt_db2-1.0.0.post1/dbt/include/ibmdb2/macros/utils/position.sql +7 -0
- dbt_db2-1.0.0.post1/dbt/include/ibmdb2/macros/utils/split_part.sql +14 -0
- dbt_db2-1.0.0.post1/dbt/include/ibmdb2/macros/utils/timestamps.sql +16 -0
- dbt_db2-1.0.0.post1/dbt/include/ibmdb2/sample_profiles.yml +23 -0
- dbt_db2-1.0.0.post1/dbt/include/ibmdb2/target/dbt-lsp.log +18 -0
- dbt_db2-1.0.0.post1/pyproject.toml +33 -0
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: dbt-db2
|
|
3
|
+
Version: 1.0.0.post1
|
|
4
|
+
Summary: The db2 adapter plugin for dbt (data build tool), 基于dbt-ibmdb2 1.8.0 修订
|
|
5
|
+
License: Apache Software License 2.0
|
|
6
|
+
License-File: LICENSE
|
|
7
|
+
Keywords: dbt,ibm,db2,data,engineering
|
|
8
|
+
Author: aurany
|
|
9
|
+
Author-email: rasmus.nyberg@gmail.com
|
|
10
|
+
Requires-Python: >=3.8
|
|
11
|
+
Classifier: License :: Other/Proprietary License
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
20
|
+
Requires-Dist: dbt-core (>=1.8.0)
|
|
21
|
+
Requires-Dist: ibm-db (>=3.1.0,<4.0.0)
|
|
22
|
+
Project-URL: Repository, https://github.com/459319819/dbt-db2
|
|
23
|
+
Description-Content-Type: text/markdown
|
|
24
|
+
|
|
25
|
+
[](https://pypi.org/project/dbt-ibmdb2/)
|
|
26
|
+
[](https://pypi.org/project/dbt-ibmdb2/)
|
|
27
|
+
|
|
28
|
+
# dbt-ibmdb2
|
|
29
|
+
|
|
30
|
+
This plugin ports [dbt](https://getdbt.com) functionality to IBM DB2.
|
|
31
|
+
|
|
32
|
+
This is an experimental plugin:
|
|
33
|
+
- We have not tested it extensively
|
|
34
|
+
- Only basic tests are implemented
|
|
35
|
+
- Compatibility with other [dbt packages](https://hub.getdbt.com/) (like [dbt_utils](https://hub.getdbt.com/fishtown-analytics/dbt_utils/latest/)) is only partially tested
|
|
36
|
+
|
|
37
|
+
Please read these docs carefully and use at your own risk. [Issues](https://github.com/aurany/dbt-ibmdb2/issues/new) welcome!
|
|
38
|
+
|
|
39
|
+
Table of Contents
|
|
40
|
+
=================
|
|
41
|
+
|
|
42
|
+
* [Installation](#installation)
|
|
43
|
+
* [Supported features](#supported-features)
|
|
44
|
+
* [Configuring your profile](#configuring-your-profile)
|
|
45
|
+
* [Running Tests](#setup-dev-environment-and-run-tests)
|
|
46
|
+
* [Reporting bugs](#reporting-bugs)
|
|
47
|
+
|
|
48
|
+
### Installation
|
|
49
|
+
This plugin can be installed via pip:
|
|
50
|
+
|
|
51
|
+
```bash
|
|
52
|
+
$ pip install dbt-ibmdb2
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
### Supported features
|
|
56
|
+
|
|
57
|
+
| DB2 LUW | DB2 z/OS | Feature |
|
|
58
|
+
|:---------:|:---:|---------------------|
|
|
59
|
+
| ✅ | 🤷 | Table materialization |
|
|
60
|
+
| ✅ | 🤷 | View materialization |
|
|
61
|
+
| ✅ | 🤷 | Incremental materialization |
|
|
62
|
+
| ✅ | 🤷 | Ephemeral materialization |
|
|
63
|
+
| ✅ | 🤷 | Seeds |
|
|
64
|
+
| ✅ | 🤷 | Sources |
|
|
65
|
+
| ✅ | 🤷 | Custom data tests |
|
|
66
|
+
| ✅ | 🤷 | Docs generate |
|
|
67
|
+
| ✅ | 🤷 | Snapshots |
|
|
68
|
+
|
|
69
|
+
*Notes:*
|
|
70
|
+
- dbt-ibmdb2 is built on the ibm_db python package and there are some known encoding issues related to z/OS.
|
|
71
|
+
|
|
72
|
+
### Configuring your profile
|
|
73
|
+
|
|
74
|
+
A dbt profile can be configured to run against DB2 using the following configuration example:
|
|
75
|
+
|
|
76
|
+
**Example entry for profiles.yml:**
|
|
77
|
+
|
|
78
|
+
```
|
|
79
|
+
your_profile_name:
|
|
80
|
+
target: dev
|
|
81
|
+
outputs:
|
|
82
|
+
dev:
|
|
83
|
+
type: ibmdb2
|
|
84
|
+
schema: analytics
|
|
85
|
+
database: test
|
|
86
|
+
host: localhost
|
|
87
|
+
port: 50000
|
|
88
|
+
protocol: TCPIP
|
|
89
|
+
user: my_username
|
|
90
|
+
password: my_password
|
|
91
|
+
extra_connect_opts: my_extra_config_options
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
| Option | Description | Required? | Example |
|
|
95
|
+
| --------------- | ----------------------------------------------------------------------------------- | ------------------------------------------------------------------ | ---------------------------------------------- |
|
|
96
|
+
| type | The specific adapter to use | Required | `ibmdb2` |
|
|
97
|
+
| schema | Specify the schema (database) to build models into | Required | `analytics` |
|
|
98
|
+
| database | Specify the database you want to connect to | Required | `testdb` |
|
|
99
|
+
| host | Hostname or IP-adress | Required | `localhost` |
|
|
100
|
+
| port | The port to use | Optional | `50000` |
|
|
101
|
+
| protocol | Protocol to use | Optional | `TCPIP` |
|
|
102
|
+
| user | The username to use to connect to the server | Required | `my-username` |
|
|
103
|
+
| password | The password to use for authenticating to the server | Required | `my-password` |
|
|
104
|
+
| extra_connect_opts | Extra connection options | Optional | `Security=SSL;SSLClientKeyStoreDB=<path-to-client-keystore>;SSLClientKeyStash=<path-to-client-keystash>` |
|
|
105
|
+
|
|
106
|
+
### Setup dev environment and run tests
|
|
107
|
+
|
|
108
|
+
Make sure you have docker and poetry installed globally.
|
|
109
|
+
|
|
110
|
+
```
|
|
111
|
+
make install
|
|
112
|
+
make test
|
|
113
|
+
make uninstall
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
### Reporting bugs
|
|
117
|
+
|
|
118
|
+
Want to report a bug or request a feature? Open [an issue](https://github.com/aurany/dbt-ibmdb2/issues/new).
|
|
119
|
+
|
|
120
|
+
### Credits
|
|
121
|
+
|
|
122
|
+
dbt-ibmdb2 is heavily inspired by and borrows from [dbt-mysql](https://github.com/dbeatty10/dbt-mysql) and [dbt-oracle](https://github.com/techindicium/dbt-oracle).
|
|
123
|
+
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
[](https://pypi.org/project/dbt-ibmdb2/)
|
|
2
|
+
[](https://pypi.org/project/dbt-ibmdb2/)
|
|
3
|
+
|
|
4
|
+
# dbt-ibmdb2
|
|
5
|
+
|
|
6
|
+
This plugin ports [dbt](https://getdbt.com) functionality to IBM DB2.
|
|
7
|
+
|
|
8
|
+
This is an experimental plugin:
|
|
9
|
+
- We have not tested it extensively
|
|
10
|
+
- Only basic tests are implemented
|
|
11
|
+
- Compatibility with other [dbt packages](https://hub.getdbt.com/) (like [dbt_utils](https://hub.getdbt.com/fishtown-analytics/dbt_utils/latest/)) is only partially tested
|
|
12
|
+
|
|
13
|
+
Please read these docs carefully and use at your own risk. [Issues](https://github.com/aurany/dbt-ibmdb2/issues/new) welcome!
|
|
14
|
+
|
|
15
|
+
Table of Contents
|
|
16
|
+
=================
|
|
17
|
+
|
|
18
|
+
* [Installation](#installation)
|
|
19
|
+
* [Supported features](#supported-features)
|
|
20
|
+
* [Configuring your profile](#configuring-your-profile)
|
|
21
|
+
* [Running Tests](#setup-dev-environment-and-run-tests)
|
|
22
|
+
* [Reporting bugs](#reporting-bugs)
|
|
23
|
+
|
|
24
|
+
### Installation
|
|
25
|
+
This plugin can be installed via pip:
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
$ pip install dbt-ibmdb2
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
### Supported features
|
|
32
|
+
|
|
33
|
+
| DB2 LUW | DB2 z/OS | Feature |
|
|
34
|
+
|:---------:|:---:|---------------------|
|
|
35
|
+
| ✅ | 🤷 | Table materialization |
|
|
36
|
+
| ✅ | 🤷 | View materialization |
|
|
37
|
+
| ✅ | 🤷 | Incremental materialization |
|
|
38
|
+
| ✅ | 🤷 | Ephemeral materialization |
|
|
39
|
+
| ✅ | 🤷 | Seeds |
|
|
40
|
+
| ✅ | 🤷 | Sources |
|
|
41
|
+
| ✅ | 🤷 | Custom data tests |
|
|
42
|
+
| ✅ | 🤷 | Docs generate |
|
|
43
|
+
| ✅ | 🤷 | Snapshots |
|
|
44
|
+
|
|
45
|
+
*Notes:*
|
|
46
|
+
- dbt-ibmdb2 is built on the ibm_db python package and there are some known encoding issues related to z/OS.
|
|
47
|
+
|
|
48
|
+
### Configuring your profile
|
|
49
|
+
|
|
50
|
+
A dbt profile can be configured to run against DB2 using the following configuration example:
|
|
51
|
+
|
|
52
|
+
**Example entry for profiles.yml:**
|
|
53
|
+
|
|
54
|
+
```
|
|
55
|
+
your_profile_name:
|
|
56
|
+
target: dev
|
|
57
|
+
outputs:
|
|
58
|
+
dev:
|
|
59
|
+
type: ibmdb2
|
|
60
|
+
schema: analytics
|
|
61
|
+
database: test
|
|
62
|
+
host: localhost
|
|
63
|
+
port: 50000
|
|
64
|
+
protocol: TCPIP
|
|
65
|
+
user: my_username
|
|
66
|
+
password: my_password
|
|
67
|
+
extra_connect_opts: my_extra_config_options
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
| Option | Description | Required? | Example |
|
|
71
|
+
| --------------- | ----------------------------------------------------------------------------------- | ------------------------------------------------------------------ | ---------------------------------------------- |
|
|
72
|
+
| type | The specific adapter to use | Required | `ibmdb2` |
|
|
73
|
+
| schema | Specify the schema (database) to build models into | Required | `analytics` |
|
|
74
|
+
| database | Specify the database you want to connect to | Required | `testdb` |
|
|
75
|
+
| host | Hostname or IP-adress | Required | `localhost` |
|
|
76
|
+
| port | The port to use | Optional | `50000` |
|
|
77
|
+
| protocol | Protocol to use | Optional | `TCPIP` |
|
|
78
|
+
| user | The username to use to connect to the server | Required | `my-username` |
|
|
79
|
+
| password | The password to use for authenticating to the server | Required | `my-password` |
|
|
80
|
+
| extra_connect_opts | Extra connection options | Optional | `Security=SSL;SSLClientKeyStoreDB=<path-to-client-keystore>;SSLClientKeyStash=<path-to-client-keystash>` |
|
|
81
|
+
|
|
82
|
+
### Setup dev environment and run tests
|
|
83
|
+
|
|
84
|
+
Make sure you have docker and poetry installed globally.
|
|
85
|
+
|
|
86
|
+
```
|
|
87
|
+
make install
|
|
88
|
+
make test
|
|
89
|
+
make uninstall
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
### Reporting bugs
|
|
93
|
+
|
|
94
|
+
Want to report a bug or request a feature? Open [an issue](https://github.com/aurany/dbt-ibmdb2/issues/new).
|
|
95
|
+
|
|
96
|
+
### Credits
|
|
97
|
+
|
|
98
|
+
dbt-ibmdb2 is heavily inspired by and borrows from [dbt-mysql](https://github.com/dbeatty10/dbt-mysql) and [dbt-oracle](https://github.com/techindicium/dbt-oracle).
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# 第一行:必须先执行环境补偿脚本!
|
|
2
|
+
# 这行代码会立即运行 _env_bootstrap.py 中的所有内容。
|
|
3
|
+
# 如果检测到 DLL 缺失,程序会在这里友好地退出,不会执行下面的代码。
|
|
4
|
+
from dbt.adapters.ibmdb2 import _env_bootstrap
|
|
5
|
+
|
|
6
|
+
from dbt.adapters.ibmdb2.connections import IBMDB2ConnectionManager
|
|
7
|
+
from dbt.adapters.ibmdb2.connections import IBMDB2Credentials
|
|
8
|
+
from dbt.adapters.ibmdb2.impl import IBMDB2Adapter
|
|
9
|
+
|
|
10
|
+
from dbt.adapters.base import AdapterPlugin
|
|
11
|
+
from dbt.include import ibmdb2
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
Plugin = AdapterPlugin(
|
|
15
|
+
adapter=IBMDB2Adapter,
|
|
16
|
+
credentials=IBMDB2Credentials,
|
|
17
|
+
include_path=ibmdb2.PACKAGE_PATH)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
version = "1.8.0"
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"""
|
|
2
|
+
IBM DB2 Windows 环境引导与 DLL 加载补偿模块。
|
|
3
|
+
此模块必须在任何其他 ibm_db 相关导入之前执行。
|
|
4
|
+
"""
|
|
5
|
+
import os
|
|
6
|
+
import sys
|
|
7
|
+
from pathlib import Path
|
|
8
|
+
|
|
9
|
+
def setup_windows_dll_path():
|
|
10
|
+
"""
|
|
11
|
+
在 Windows 环境下,自动查找并添加 clidriver/bin 到 DLL 搜索路径。
|
|
12
|
+
如果失败,提供友好的错误提示并退出。
|
|
13
|
+
"""
|
|
14
|
+
if os.name == "nt":
|
|
15
|
+
|
|
16
|
+
# 获取当前 Python 环境根目录 (虚拟环境或系统环境)
|
|
17
|
+
venv_root = Path(sys.prefix)
|
|
18
|
+
|
|
19
|
+
# 构建预期的 clidriver/bin 路径
|
|
20
|
+
# 注意:pip install ibm_db 通常会将 clidriver 安装在 site-packages 下
|
|
21
|
+
clidriver_bin = venv_root / "Lib" / "site-packages" / "clidriver" / "bin"
|
|
22
|
+
|
|
23
|
+
# 兼容某些特殊安装情况 (例如直接安装在根目录,虽然少见)
|
|
24
|
+
if not clidriver_bin.exists():
|
|
25
|
+
alt_path = venv_root / "clidriver" / "bin"
|
|
26
|
+
if alt_path.exists():
|
|
27
|
+
clidriver_bin = alt_path
|
|
28
|
+
|
|
29
|
+
if clidriver_bin.exists():
|
|
30
|
+
try:
|
|
31
|
+
# Python 3.8+ 推荐方式:显式添加 DLL 搜索目录
|
|
32
|
+
os.add_dll_directory(str(clidriver_bin))
|
|
33
|
+
print(f"[dbt-db2] 🎯 发现基于 dbt-ibmdb2 的定制化版本的 dbt 数据库适配器")
|
|
34
|
+
print(f"[dbt-db2] 🎯 当前修订版本是:1.0.0.post1")
|
|
35
|
+
print(f"[dbt-db2] ✅ 已自动添加 DLL 路径: {clidriver_bin}")
|
|
36
|
+
except Exception as e:
|
|
37
|
+
print(f"[dbt-db2] ⚠️ 添加 DLL 路径时发生警告: {e}")
|
|
38
|
+
else:
|
|
39
|
+
# 如果找不到,给出友好提示
|
|
40
|
+
print("❌ [dbt-db2] 启动失败:未找到 IBM DB2 驱动 (clidriver)")
|
|
41
|
+
print(f"检查路径: {clidriver_bin}")
|
|
42
|
+
print("❓可能的原因及解决方案:")
|
|
43
|
+
print("1. 未安装 ibm_db 包:")
|
|
44
|
+
print(" -> 运行: pip install ibm_db")
|
|
45
|
+
print("2. 安装了包但文件缺失 (网络问题导致下载不完整):")
|
|
46
|
+
print(" -> 运行: pip uninstall ibm_db -y && pip install ibm_db --no-cache-dir")
|
|
47
|
+
print("3. 使用了系统级 IBM Client 但未配置 PATH:")
|
|
48
|
+
print(" -> 请将 IBM CLI Driver 的 'bin' 目录添加到系统 PATH 环境变量中。")
|
|
49
|
+
|
|
50
|
+
# 关键:直接退出进程,阻止后续代码执行导致的 cryptic 报错
|
|
51
|
+
sys.exit(1)
|
|
52
|
+
# TODO: Unix / MacOS
|
|
53
|
+
|
|
54
|
+
# 立即执行
|
|
55
|
+
setup_windows_dll_path()
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
from dataclasses import dataclass
|
|
2
|
+
from typing import Dict, ClassVar
|
|
3
|
+
|
|
4
|
+
from dbt.adapters.base.column import Column
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
@dataclass
|
|
8
|
+
class IBMDB2Column(Column):
|
|
9
|
+
|
|
10
|
+
TYPE_LABELS: ClassVar[Dict[str, str]] = {
|
|
11
|
+
"STRING": "VARCHAR(4000)",
|
|
12
|
+
"TIMESTAMP": "TIMESTAMP",
|
|
13
|
+
"FLOAT": "DECFLOAT",
|
|
14
|
+
"INTEGER": "INTEGER",
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
STRING_DATATYPES = {'char', 'nchar', 'varchar', 'nvarchar'}
|
|
18
|
+
NUMBER_DATATYPES = {'decimal', 'decfloat'}
|
|
19
|
+
|
|
20
|
+
@property
|
|
21
|
+
def data_type(self) -> str:
|
|
22
|
+
if self.is_string():
|
|
23
|
+
return self.ibmdb2_string_type(self.dtype, self.string_size())
|
|
24
|
+
elif self.is_numeric():
|
|
25
|
+
return self.numeric_type(self.dtype, self.numeric_precision, self.numeric_scale)
|
|
26
|
+
else:
|
|
27
|
+
return self.dtype
|
|
28
|
+
|
|
29
|
+
@classmethod
|
|
30
|
+
def ibmdb2_string_type(cls, dtype: str, size: int = None):
|
|
31
|
+
"""
|
|
32
|
+
- CHAR(SIZE)
|
|
33
|
+
- VARCHAR(SIZE)
|
|
34
|
+
- NCHAR(SIZE) or NCHAR
|
|
35
|
+
- NVARCHAR(SIZE)
|
|
36
|
+
"""
|
|
37
|
+
if size is None:
|
|
38
|
+
return dtype
|
|
39
|
+
else:
|
|
40
|
+
return "{}({})".format(dtype, size)
|
|
41
|
+
|
|
42
|
+
def is_numeric(self) -> bool:
|
|
43
|
+
if self.dtype.lower() in self.NUMBER_DATATYPES:
|
|
44
|
+
return True
|
|
45
|
+
return super().is_numeric()
|
|
46
|
+
|
|
47
|
+
def is_string(self) -> bool:
|
|
48
|
+
if self.dtype.lower() in self.STRING_DATATYPES:
|
|
49
|
+
return True
|
|
50
|
+
return super().is_string()
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
from contextlib import contextmanager
|
|
2
|
+
|
|
3
|
+
from dataclasses import dataclass
|
|
4
|
+
|
|
5
|
+
import dbt_common.exceptions
|
|
6
|
+
from dbt.adapters.contracts.connection import Credentials
|
|
7
|
+
from dbt.adapters.contracts.connection import AdapterResponse
|
|
8
|
+
from dbt.adapters.contracts.connection import Connection
|
|
9
|
+
from dbt.adapters.sql import SQLConnectionManager
|
|
10
|
+
from dbt.adapters.events.logging import AdapterLogger
|
|
11
|
+
|
|
12
|
+
from typing import (
|
|
13
|
+
Type,
|
|
14
|
+
Iterable,
|
|
15
|
+
Optional
|
|
16
|
+
)
|
|
17
|
+
|
|
18
|
+
import ibm_db
|
|
19
|
+
import ibm_db_dbi
|
|
20
|
+
|
|
21
|
+
logger = AdapterLogger("IBM DB2")
|
|
22
|
+
|
|
23
|
+
@dataclass
|
|
24
|
+
class IBMDB2Credentials(Credentials):
|
|
25
|
+
host: str
|
|
26
|
+
database: str
|
|
27
|
+
schema: str
|
|
28
|
+
user: str
|
|
29
|
+
password: str
|
|
30
|
+
port: int = 50000
|
|
31
|
+
protocol: str = 'TCPIP'
|
|
32
|
+
extra_connect_opts: Optional[str] = None
|
|
33
|
+
|
|
34
|
+
@property
|
|
35
|
+
def type(self):
|
|
36
|
+
return 'ibmdb2'
|
|
37
|
+
|
|
38
|
+
def _connection_keys(self):
|
|
39
|
+
return ('host', 'database', 'schema', 'user', 'password', 'port', 'protocol', 'extra_connect_opts')
|
|
40
|
+
|
|
41
|
+
@property
|
|
42
|
+
def unique_field(self) -> str:
|
|
43
|
+
return self.host
|
|
44
|
+
|
|
45
|
+
class IBMDB2ConnectionManager(SQLConnectionManager):
|
|
46
|
+
TYPE = 'ibmdb2'
|
|
47
|
+
|
|
48
|
+
@contextmanager
|
|
49
|
+
def exception_handler(self, sql: str):
|
|
50
|
+
try:
|
|
51
|
+
yield
|
|
52
|
+
except ibm_db_dbi.DatabaseError as exc:
|
|
53
|
+
self.release()
|
|
54
|
+
logger.debug('ibm_db_dbi error: {}'.format(str(exc)))
|
|
55
|
+
logger.debug("Error running SQL: {}".format(sql))
|
|
56
|
+
raise dbt_common.exceptions.DbtDatabaseError(str(exc))
|
|
57
|
+
except Exception as exc:
|
|
58
|
+
self.release()
|
|
59
|
+
logger.debug("Error running SQL: {}".format(sql))
|
|
60
|
+
logger.debug("Rolling back transaction.")
|
|
61
|
+
raise dbt_common.exceptions.DbtRuntimeError(str(exc))
|
|
62
|
+
|
|
63
|
+
@classmethod
|
|
64
|
+
def open(cls, connection):
|
|
65
|
+
if connection.state == 'open':
|
|
66
|
+
logger.debug('Connection is already open, skipping open.')
|
|
67
|
+
return connection
|
|
68
|
+
|
|
69
|
+
credentials = connection.credentials
|
|
70
|
+
|
|
71
|
+
def connect():
|
|
72
|
+
con_str = f"DATABASE={credentials.database}"
|
|
73
|
+
con_str += f";HOSTNAME={credentials.host}"
|
|
74
|
+
con_str += f";PORT={credentials.port}"
|
|
75
|
+
con_str += f";PROTOCOL={credentials.protocol}"
|
|
76
|
+
con_str += f";UID={credentials.user}"
|
|
77
|
+
con_str += f";PWD={credentials.password}"
|
|
78
|
+
|
|
79
|
+
if credentials.extra_connect_opts is not None and credentials.extra_connect_opts != "":
|
|
80
|
+
con_str += f";{credentials.extra_connect_opts}"
|
|
81
|
+
|
|
82
|
+
handle = ibm_db_dbi.connect(con_str, '', '')
|
|
83
|
+
handle.set_autocommit(False)
|
|
84
|
+
|
|
85
|
+
return handle
|
|
86
|
+
|
|
87
|
+
retryable_exceptions = [ibm_db_dbi.OperationalError,]
|
|
88
|
+
|
|
89
|
+
return cls.retry_connection(
|
|
90
|
+
connection,
|
|
91
|
+
connect=connect,
|
|
92
|
+
logger=logger,
|
|
93
|
+
retry_limit=3,
|
|
94
|
+
retry_timeout=5,
|
|
95
|
+
retryable_exceptions=retryable_exceptions
|
|
96
|
+
)
|
|
97
|
+
|
|
98
|
+
@classmethod
|
|
99
|
+
def cancel(self, connection):
|
|
100
|
+
connection_name = connection.name
|
|
101
|
+
|
|
102
|
+
logger.info("Cancelling query '{}' ".format(connection_name))
|
|
103
|
+
|
|
104
|
+
try:
|
|
105
|
+
connection.handle.close()
|
|
106
|
+
except Exception as e:
|
|
107
|
+
logger.error('Error closing connection for cancel request')
|
|
108
|
+
raise Exception(str(e))
|
|
109
|
+
|
|
110
|
+
@classmethod
|
|
111
|
+
def get_credentials(cls, credentials):
|
|
112
|
+
return credentials
|
|
113
|
+
|
|
114
|
+
@classmethod
|
|
115
|
+
def get_response(cls, cursor) -> AdapterResponse:
|
|
116
|
+
|
|
117
|
+
message = 'OK'
|
|
118
|
+
rows = cursor.rowcount
|
|
119
|
+
|
|
120
|
+
return AdapterResponse(
|
|
121
|
+
_message=message,
|
|
122
|
+
rows_affected=rows
|
|
123
|
+
)
|
|
124
|
+
|
|
125
|
+
def add_begin_query(self):
|
|
126
|
+
pass
|