1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
|
%global _empty_manifest_terminate_build 0
Name: python-sqlalchemy-drill
Version: 1.1.2
Release: 1
Summary: Apache Drill for SQLAlchemy
License: MIT
URL: https://github.com/JohnOmernik/sqlalchemy-drill
Source0: https://mirrors.nju.edu.cn/pypi/web/packages/93/0c/8236efc6db99bd8ef238cac53be8f99bf5f93442668fdd349fc43c68a8dd/sqlalchemy_drill-1.1.2.tar.gz
BuildArch: noarch
%description
The primary purpose of this is to have a working dialect for Apache Drill that can be used with Apache Superset.
https://superset.incubator.apache.org
Obviously, a working, robust dialect for Drill serves other purposes as well, but most of the iterative planning for this REPO will be based on working with Superset. Other changes will gladly be incorporated, as long as it doesn't hurt Superset integration.
## Installation
Installing the dialect is straightforward. Simply:
```
pip install sqlalchemy-drill
```
Alternatively, you can download the latest release from github and install from here:
```python
python3 -m pip install git+https://github.com/JohnOmernik/sqlalchemy-drill.git
```
## Usage with REST
Drill's REST API can execute queries with results streamed to JSON returned over chunked HTTP for Drill >= 1.19, otherwise with results buffered and then returned in a conventional HTTP response. A SQLAlchemy URL to connect to Drill over REST looks like the following.
```
drill+sadrill://<username>:<password>@<host>:<port>/<storage_plugin>?use_ssl=True
```
To connect to Drill running on a local machine running in embedded mode you can use the following connection string.
```
drill+sadrill://localhost:8047/dfs?use_ssl=False
```
### Supported URL query parameters
| Parameter | Type | Description |
| ------------------------- | ------- | -------------------------------------------------------------- |
| use_ssl | boolean | Whether to connect to Drill using HTTPS |
| verify_ssl | boolean | Whether to verify the server's TLS certificate |
| impersonation_target\[1\] | string | Username of a Drill user to be impersonated by this connection |
[1] Requires a build of Drill that incorporates the fix for DRILL-8168.
### Trailing metadata
Query result metadata returned by the Drill REST API is stored in the `result_md` field of the DB-API Cursor object. Note that any trailing metadata, i.e. metadata which comes after result row data, will only be populated after you have iterated through all of the returned rows. If you need this trailing metadata you can make the cursor object reachable after it has been completely iterated by obtaining a reference to it beforehand, as follows.
```python
r = engine.execute('select current_timestamp')
r.cursor.result_md # access metadata, but only leading metadata
cur = r.cursor # obtain a reference for use later
r.fetchall() # iterate through all result data
cur.result_md # access metadata, including trailing metadata
del cur # optionally delete the reference when done
```
### Drill < 1.19
In versions of Drill earlier than 1.19, all data values are serialised to JSON strings and column type metadata comes after the data itself. As a result, for these versions of Drill, the drill+sadrill dialect returns every data value as a string. To convert non-string data to its native type you need to typecast it yourself.
### Drill >= 1.19
In Drill 1.19 the REST API began making use of numeric types in JSON for numbers and times, the latter via a UNIX time representation while column type metadata was moved ahead of the result data. Because of this, the drill+sadrill dialect is able to return appropriate types for numbers and times when used with Drill >= 1.19.
## Usage with JDBC
Connecting to Drill via JDBC is a little more complicated than a local installation and complete instructions can be found on the Drill documentation here: https://drill.apache.org/docs/using-the-jdbc-driver/.
In order to configure SQLAlchemy to work with Drill via JDBC you must:
- Download the latest JDBC Driver available here: http://apache.osuosl.org/drill/
- Copy this driver to your classpath or other known path
- Set an environment variable called `DRILL_JDBC_DRIVER_PATH` to the full path of your driver location
- Set an environment variable called `DRILL_JDBC_JAR_NAME` to the name of the `.jar` file for the Drill driver.
Additionally, you will need to install `JayDeBeApi` as well as jPype version 0.6.3.
These modules are listed as optional dependencies and will not be installed by the default installer.
If the JDBC driver is not available, the dialect will throw errors when trying
to connect. In addition, sqlalchemy-drill will not launch a JVM for you so you
need to do this yourself with a call to JPype like the following. See the file
test-jdbc.py in this repo for a working example.
```python
jpype.startJVM("-ea", classpath="lib/*")
```
```
drill+jdbc://<username>:<passsword>@<host>:<port>
```
For a simple installation, this might look like:
```
drill+jdbc://admin:password@localhost:31010
```
## Usage with ODBC
In order to configure SQLAlchemy to work with Drill via ODBC you must:
- Install latest Drill ODBC Driver: https://drill.apache.org/docs/installing-the-driver-on-linux/
- Ensure that you have ODBC support in your system (`unixODBC` package for RedHat-based systems).
- Install `pyodbc` Python package.
This module is listed as an optional dependency and will not be installed by the default installer.
To connect to Drill with SQLAlchemy use the following connection string:
```
drill+odbc:///?<ODBC connection parameters>
```
Connection properties are available in the official documentation: https://drill.apache.org/docs/odbc-configuration-reference/
For a simple installation, this might look like:
```
drill+odbc:///?Driver=/opt/mapr/drill/lib/64/libdrillodbc_sb64.so&ConnectionType=Direct&HOST=localhost&PORT=31010&AuthenticationType=Plain&UID=admin&PWD=password
```
or for the case when you have DSN configured in `odbc.ini`:
```
drill+odbc:///?DSN=drill_dsn_name
```
**Note:** it's better to avoid using connection string with `hostname:port` or `username`/`password`, like 'drill+odbc://admin:password@localhost:31010/' but use only ODBC properties instead to avoid any misinterpretation between these parameters.
## Usage with Superset
For a complete tutorial on how to use Superset with Drill, read the tutorial on @cgivre's blog available here: http://thedataist.com/visualize-anything-with-superset-and-drill/.
## Current Status/Development Approach
Currently we can connect to drill, and issue queries for most visualizations and get results. We also enumerate table columns for some times of tables. Here are things that are working as some larger issues to work out. (Individual issues are tracked under issues)
- Connection to Drill via the databases tab in Superset succeeds
- You can do basic queries for most types of viz/tables
- There may be issues with advanced queries/joins. As you learn about new ones, please track in issues
### Many thanks
to drillpy and pydrill for code used in creating the original `drilldbapi.py` code for connecting!
### Docker
It is recommended to extend [the official Docker image](https://hub.docker.com/r/apache/superset) to include this Apache Drill driver:
```dockerfile
FROM apache/superset
# Switching to root to install the required packages
USER root
RUN pip install git+https://github.com/JohnOmernik/sqlalchemy-drill.git
# Switching back to using the `superset` user
USER superset
```
%package -n python3-sqlalchemy-drill
Summary: Apache Drill for SQLAlchemy
Provides: python-sqlalchemy-drill
BuildRequires: python3-devel
BuildRequires: python3-setuptools
BuildRequires: python3-pip
%description -n python3-sqlalchemy-drill
The primary purpose of this is to have a working dialect for Apache Drill that can be used with Apache Superset.
https://superset.incubator.apache.org
Obviously, a working, robust dialect for Drill serves other purposes as well, but most of the iterative planning for this REPO will be based on working with Superset. Other changes will gladly be incorporated, as long as it doesn't hurt Superset integration.
## Installation
Installing the dialect is straightforward. Simply:
```
pip install sqlalchemy-drill
```
Alternatively, you can download the latest release from github and install from here:
```python
python3 -m pip install git+https://github.com/JohnOmernik/sqlalchemy-drill.git
```
## Usage with REST
Drill's REST API can execute queries with results streamed to JSON returned over chunked HTTP for Drill >= 1.19, otherwise with results buffered and then returned in a conventional HTTP response. A SQLAlchemy URL to connect to Drill over REST looks like the following.
```
drill+sadrill://<username>:<password>@<host>:<port>/<storage_plugin>?use_ssl=True
```
To connect to Drill running on a local machine running in embedded mode you can use the following connection string.
```
drill+sadrill://localhost:8047/dfs?use_ssl=False
```
### Supported URL query parameters
| Parameter | Type | Description |
| ------------------------- | ------- | -------------------------------------------------------------- |
| use_ssl | boolean | Whether to connect to Drill using HTTPS |
| verify_ssl | boolean | Whether to verify the server's TLS certificate |
| impersonation_target\[1\] | string | Username of a Drill user to be impersonated by this connection |
[1] Requires a build of Drill that incorporates the fix for DRILL-8168.
### Trailing metadata
Query result metadata returned by the Drill REST API is stored in the `result_md` field of the DB-API Cursor object. Note that any trailing metadata, i.e. metadata which comes after result row data, will only be populated after you have iterated through all of the returned rows. If you need this trailing metadata you can make the cursor object reachable after it has been completely iterated by obtaining a reference to it beforehand, as follows.
```python
r = engine.execute('select current_timestamp')
r.cursor.result_md # access metadata, but only leading metadata
cur = r.cursor # obtain a reference for use later
r.fetchall() # iterate through all result data
cur.result_md # access metadata, including trailing metadata
del cur # optionally delete the reference when done
```
### Drill < 1.19
In versions of Drill earlier than 1.19, all data values are serialised to JSON strings and column type metadata comes after the data itself. As a result, for these versions of Drill, the drill+sadrill dialect returns every data value as a string. To convert non-string data to its native type you need to typecast it yourself.
### Drill >= 1.19
In Drill 1.19 the REST API began making use of numeric types in JSON for numbers and times, the latter via a UNIX time representation while column type metadata was moved ahead of the result data. Because of this, the drill+sadrill dialect is able to return appropriate types for numbers and times when used with Drill >= 1.19.
## Usage with JDBC
Connecting to Drill via JDBC is a little more complicated than a local installation and complete instructions can be found on the Drill documentation here: https://drill.apache.org/docs/using-the-jdbc-driver/.
In order to configure SQLAlchemy to work with Drill via JDBC you must:
- Download the latest JDBC Driver available here: http://apache.osuosl.org/drill/
- Copy this driver to your classpath or other known path
- Set an environment variable called `DRILL_JDBC_DRIVER_PATH` to the full path of your driver location
- Set an environment variable called `DRILL_JDBC_JAR_NAME` to the name of the `.jar` file for the Drill driver.
Additionally, you will need to install `JayDeBeApi` as well as jPype version 0.6.3.
These modules are listed as optional dependencies and will not be installed by the default installer.
If the JDBC driver is not available, the dialect will throw errors when trying
to connect. In addition, sqlalchemy-drill will not launch a JVM for you so you
need to do this yourself with a call to JPype like the following. See the file
test-jdbc.py in this repo for a working example.
```python
jpype.startJVM("-ea", classpath="lib/*")
```
```
drill+jdbc://<username>:<passsword>@<host>:<port>
```
For a simple installation, this might look like:
```
drill+jdbc://admin:password@localhost:31010
```
## Usage with ODBC
In order to configure SQLAlchemy to work with Drill via ODBC you must:
- Install latest Drill ODBC Driver: https://drill.apache.org/docs/installing-the-driver-on-linux/
- Ensure that you have ODBC support in your system (`unixODBC` package for RedHat-based systems).
- Install `pyodbc` Python package.
This module is listed as an optional dependency and will not be installed by the default installer.
To connect to Drill with SQLAlchemy use the following connection string:
```
drill+odbc:///?<ODBC connection parameters>
```
Connection properties are available in the official documentation: https://drill.apache.org/docs/odbc-configuration-reference/
For a simple installation, this might look like:
```
drill+odbc:///?Driver=/opt/mapr/drill/lib/64/libdrillodbc_sb64.so&ConnectionType=Direct&HOST=localhost&PORT=31010&AuthenticationType=Plain&UID=admin&PWD=password
```
or for the case when you have DSN configured in `odbc.ini`:
```
drill+odbc:///?DSN=drill_dsn_name
```
**Note:** it's better to avoid using connection string with `hostname:port` or `username`/`password`, like 'drill+odbc://admin:password@localhost:31010/' but use only ODBC properties instead to avoid any misinterpretation between these parameters.
## Usage with Superset
For a complete tutorial on how to use Superset with Drill, read the tutorial on @cgivre's blog available here: http://thedataist.com/visualize-anything-with-superset-and-drill/.
## Current Status/Development Approach
Currently we can connect to drill, and issue queries for most visualizations and get results. We also enumerate table columns for some times of tables. Here are things that are working as some larger issues to work out. (Individual issues are tracked under issues)
- Connection to Drill via the databases tab in Superset succeeds
- You can do basic queries for most types of viz/tables
- There may be issues with advanced queries/joins. As you learn about new ones, please track in issues
### Many thanks
to drillpy and pydrill for code used in creating the original `drilldbapi.py` code for connecting!
### Docker
It is recommended to extend [the official Docker image](https://hub.docker.com/r/apache/superset) to include this Apache Drill driver:
```dockerfile
FROM apache/superset
# Switching to root to install the required packages
USER root
RUN pip install git+https://github.com/JohnOmernik/sqlalchemy-drill.git
# Switching back to using the `superset` user
USER superset
```
%package help
Summary: Development documents and examples for sqlalchemy-drill
Provides: python3-sqlalchemy-drill-doc
%description help
The primary purpose of this is to have a working dialect for Apache Drill that can be used with Apache Superset.
https://superset.incubator.apache.org
Obviously, a working, robust dialect for Drill serves other purposes as well, but most of the iterative planning for this REPO will be based on working with Superset. Other changes will gladly be incorporated, as long as it doesn't hurt Superset integration.
## Installation
Installing the dialect is straightforward. Simply:
```
pip install sqlalchemy-drill
```
Alternatively, you can download the latest release from github and install from here:
```python
python3 -m pip install git+https://github.com/JohnOmernik/sqlalchemy-drill.git
```
## Usage with REST
Drill's REST API can execute queries with results streamed to JSON returned over chunked HTTP for Drill >= 1.19, otherwise with results buffered and then returned in a conventional HTTP response. A SQLAlchemy URL to connect to Drill over REST looks like the following.
```
drill+sadrill://<username>:<password>@<host>:<port>/<storage_plugin>?use_ssl=True
```
To connect to Drill running on a local machine running in embedded mode you can use the following connection string.
```
drill+sadrill://localhost:8047/dfs?use_ssl=False
```
### Supported URL query parameters
| Parameter | Type | Description |
| ------------------------- | ------- | -------------------------------------------------------------- |
| use_ssl | boolean | Whether to connect to Drill using HTTPS |
| verify_ssl | boolean | Whether to verify the server's TLS certificate |
| impersonation_target\[1\] | string | Username of a Drill user to be impersonated by this connection |
[1] Requires a build of Drill that incorporates the fix for DRILL-8168.
### Trailing metadata
Query result metadata returned by the Drill REST API is stored in the `result_md` field of the DB-API Cursor object. Note that any trailing metadata, i.e. metadata which comes after result row data, will only be populated after you have iterated through all of the returned rows. If you need this trailing metadata you can make the cursor object reachable after it has been completely iterated by obtaining a reference to it beforehand, as follows.
```python
r = engine.execute('select current_timestamp')
r.cursor.result_md # access metadata, but only leading metadata
cur = r.cursor # obtain a reference for use later
r.fetchall() # iterate through all result data
cur.result_md # access metadata, including trailing metadata
del cur # optionally delete the reference when done
```
### Drill < 1.19
In versions of Drill earlier than 1.19, all data values are serialised to JSON strings and column type metadata comes after the data itself. As a result, for these versions of Drill, the drill+sadrill dialect returns every data value as a string. To convert non-string data to its native type you need to typecast it yourself.
### Drill >= 1.19
In Drill 1.19 the REST API began making use of numeric types in JSON for numbers and times, the latter via a UNIX time representation while column type metadata was moved ahead of the result data. Because of this, the drill+sadrill dialect is able to return appropriate types for numbers and times when used with Drill >= 1.19.
## Usage with JDBC
Connecting to Drill via JDBC is a little more complicated than a local installation and complete instructions can be found on the Drill documentation here: https://drill.apache.org/docs/using-the-jdbc-driver/.
In order to configure SQLAlchemy to work with Drill via JDBC you must:
- Download the latest JDBC Driver available here: http://apache.osuosl.org/drill/
- Copy this driver to your classpath or other known path
- Set an environment variable called `DRILL_JDBC_DRIVER_PATH` to the full path of your driver location
- Set an environment variable called `DRILL_JDBC_JAR_NAME` to the name of the `.jar` file for the Drill driver.
Additionally, you will need to install `JayDeBeApi` as well as jPype version 0.6.3.
These modules are listed as optional dependencies and will not be installed by the default installer.
If the JDBC driver is not available, the dialect will throw errors when trying
to connect. In addition, sqlalchemy-drill will not launch a JVM for you so you
need to do this yourself with a call to JPype like the following. See the file
test-jdbc.py in this repo for a working example.
```python
jpype.startJVM("-ea", classpath="lib/*")
```
```
drill+jdbc://<username>:<passsword>@<host>:<port>
```
For a simple installation, this might look like:
```
drill+jdbc://admin:password@localhost:31010
```
## Usage with ODBC
In order to configure SQLAlchemy to work with Drill via ODBC you must:
- Install latest Drill ODBC Driver: https://drill.apache.org/docs/installing-the-driver-on-linux/
- Ensure that you have ODBC support in your system (`unixODBC` package for RedHat-based systems).
- Install `pyodbc` Python package.
This module is listed as an optional dependency and will not be installed by the default installer.
To connect to Drill with SQLAlchemy use the following connection string:
```
drill+odbc:///?<ODBC connection parameters>
```
Connection properties are available in the official documentation: https://drill.apache.org/docs/odbc-configuration-reference/
For a simple installation, this might look like:
```
drill+odbc:///?Driver=/opt/mapr/drill/lib/64/libdrillodbc_sb64.so&ConnectionType=Direct&HOST=localhost&PORT=31010&AuthenticationType=Plain&UID=admin&PWD=password
```
or for the case when you have DSN configured in `odbc.ini`:
```
drill+odbc:///?DSN=drill_dsn_name
```
**Note:** it's better to avoid using connection string with `hostname:port` or `username`/`password`, like 'drill+odbc://admin:password@localhost:31010/' but use only ODBC properties instead to avoid any misinterpretation between these parameters.
## Usage with Superset
For a complete tutorial on how to use Superset with Drill, read the tutorial on @cgivre's blog available here: http://thedataist.com/visualize-anything-with-superset-and-drill/.
## Current Status/Development Approach
Currently we can connect to drill, and issue queries for most visualizations and get results. We also enumerate table columns for some times of tables. Here are things that are working as some larger issues to work out. (Individual issues are tracked under issues)
- Connection to Drill via the databases tab in Superset succeeds
- You can do basic queries for most types of viz/tables
- There may be issues with advanced queries/joins. As you learn about new ones, please track in issues
### Many thanks
to drillpy and pydrill for code used in creating the original `drilldbapi.py` code for connecting!
### Docker
It is recommended to extend [the official Docker image](https://hub.docker.com/r/apache/superset) to include this Apache Drill driver:
```dockerfile
FROM apache/superset
# Switching to root to install the required packages
USER root
RUN pip install git+https://github.com/JohnOmernik/sqlalchemy-drill.git
# Switching back to using the `superset` user
USER superset
```
%prep
%autosetup -n sqlalchemy-drill-1.1.2
%build
%py3_build
%install
%py3_install
install -d -m755 %{buildroot}/%{_pkgdocdir}
if [ -d doc ]; then cp -arf doc %{buildroot}/%{_pkgdocdir}; fi
if [ -d docs ]; then cp -arf docs %{buildroot}/%{_pkgdocdir}; fi
if [ -d example ]; then cp -arf example %{buildroot}/%{_pkgdocdir}; fi
if [ -d examples ]; then cp -arf examples %{buildroot}/%{_pkgdocdir}; fi
pushd %{buildroot}
if [ -d usr/lib ]; then
find usr/lib -type f -printf "/%h/%f\n" >> filelist.lst
fi
if [ -d usr/lib64 ]; then
find usr/lib64 -type f -printf "/%h/%f\n" >> filelist.lst
fi
if [ -d usr/bin ]; then
find usr/bin -type f -printf "/%h/%f\n" >> filelist.lst
fi
if [ -d usr/sbin ]; then
find usr/sbin -type f -printf "/%h/%f\n" >> filelist.lst
fi
touch doclist.lst
if [ -d usr/share/man ]; then
find usr/share/man -type f -printf "/%h/%f.gz\n" >> doclist.lst
fi
popd
mv %{buildroot}/filelist.lst .
mv %{buildroot}/doclist.lst .
%files -n python3-sqlalchemy-drill -f filelist.lst
%dir %{python3_sitelib}/*
%files help -f doclist.lst
%{_docdir}/*
%changelog
* Wed Apr 12 2023 Python_Bot <Python_Bot@openeuler.org> - 1.1.2-1
- Package Spec generated
|