Skip to content

Commit 9221f93

Browse files
authored
Undo reverts (dremio-hub#52)
* Refactor python example (dremio-hub#41) * bootstrap refactored example * refactor original code * performance optimizations * add logging * remove user/pwd defaults and add exceptions * fix tests * remove pycache files * fix exceptions and tests * fix imports * add copyright headers * fix readme and remove requirements.txt * run formatters, bandit and restructure * update readme * make changes to git ignore * address doc review comments * doc updates * quickstart changes * add endpoint class to mask other two * add functional programming * add title to readme * rename modules * Fix arg requirements and client middleware auth header (dremio-hub#42) * bootstrap refactored example * refactor original code * performance optimizations * add logging * remove user/pwd defaults and add exceptions * fix tests * remove pycache files * fix exceptions and tests * fix imports * add copyright headers * fix readme and remove requirements.txt * run formatters, bandit and restructure * update readme * make changes to git ignore * address doc review comments * doc updates * quickstart changes * add endpoint class to mask other two * add functional programming * add title to readme * rename modules * fix argument requirements and client middleware * change wording * fix typo * fix typo * fix spacing * encode bearer token * Change package version (dremio-hub#43) * bootstrap refactored example * refactor original code * performance optimizations * add logging * remove user/pwd defaults and add exceptions * fix tests * remove pycache files * fix exceptions and tests * fix imports * add copyright headers * fix readme and remove requirements.txt * run formatters, bandit and restructure * update readme * make changes to git ignore * address doc review comments * doc updates * quickstart changes * add endpoint class to mask other two * add functional programming * add title to readme * rename modules * fix argument requirements and client middleware * change wording * fix typo * fix typo * fix spacing * encode bearer token * change version to 1.0.0 * Fix typos in readme (dremio-hub#44) * bootstrap refactored example * refactor original code * performance optimizations * add logging * remove user/pwd defaults and add exceptions * fix tests * remove pycache files * fix exceptions and tests * fix imports * add copyright headers * fix readme and remove requirements.txt * run formatters, bandit and restructure * update readme * make changes to git ignore * address doc review comments * doc updates * quickstart changes * add endpoint class to mask other two * add functional programming * add title to readme * rename modules * fix argument requirements and client middleware * change wording * fix typo * fix typo * fix spacing * encode bearer token * change version to 1.0.0 * doc typos * Refactor python example (dremio-hub#41) * bootstrap refactored example * refactor original code * performance optimizations * add logging * remove user/pwd defaults and add exceptions * fix tests * remove pycache files * fix exceptions and tests * fix imports * add copyright headers * fix readme and remove requirements.txt * run formatters, bandit and restructure * update readme * make changes to git ignore * address doc review comments * doc updates * quickstart changes * add endpoint class to mask other two * add functional programming * add title to readme * rename modules "merge conflicts" * Fix arg requirements and client middleware auth header (dremio-hub#42) * bootstrap refactored example * refactor original code * performance optimizations * add logging * remove user/pwd defaults and add exceptions * fix tests * remove pycache files * fix exceptions and tests * fix imports * add copyright headers * fix readme and remove requirements.txt * run formatters, bandit and restructure * update readme * make changes to git ignore * address doc review comments * doc updates * quickstart changes * add endpoint class to mask other two * add functional programming * add title to readme * rename modules * fix argument requirements and client middleware * change wording * fix typo * fix typo * fix spacing * encode bearer token "allow empty" * include all modules that start with dremio * change folder structure * add documentation for using pat against software
1 parent 34c4a56 commit 9221f93

18 files changed

Lines changed: 753 additions & 445 deletions

File tree

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,10 @@ java/.idea
22
java/target
33
java/*.iml
44
.idea
5+
*.env
6+
**/__pycache__
7+
**/*.egg-info
8+
**/build
9+
**/dist
10+
**/*.pytest_cache
11+
**/*.log

QUICKSTART.md

Lines changed: 8 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -12,41 +12,18 @@
1212
## 1 Query data using Flight clients
1313
This process is the same if you launched the Dremio locally or via docker.
1414

15-
### 1.1 Query your datasets with arrow flight client in python
16-
17-
This lightweight Python client application connects to the Dremio Arrow Flight server endpoint. It requires the username and password for authentication. Developers can use admin or regular user credentials for authentication. Any datasets in Dremio that are accessible by the provided Dremio user can be queried. By default, the hostname is `localhost` and the port is `32010`. Developers can change these default settings by providing the hostname and port as arguments when running the client. Moreover, the tls option can be provided to establish an encrypted connection.
18-
19-
> Note: Trusted certificates must be provided when the tls option is enabled.
15+
### 1.1 Query your datasets with Python
2016
>
21-
#### 1.1.1 Prerequisites
22-
23-
- Python 3
24-
25-
#### 1.1.2 Instructions on using this Python sample application
17+
#### 1.1.1 Getting Started
2618

27-
- This application also requires `pyarrow` and `pandas`. Consider one of the dependency installation methods below. We recommend using `conda` for its ease of use.
28-
- Install dependencies using `conda`
29-
- `conda install -c conda-forge --file requirements.txt`
30-
- Alternatively, install dependencies using `pip`
31-
- `pip3 install -r requirements.txt`
32-
- Run the Python sample application:
33-
- `python3 example.py -host '<DREMIO_HOST>' -user '<DREMIO_USERNAME>' -pass '<DREMIO_PASSWORD>'`
19+
1. Install [Python 3](https://www.python.org/downloads/)
20+
2. Download and install the [dremio-flight-endpoint whl file](https://github.com/dremio-hub/arrow-flight-client-examples/releases)
21+
- `python -m pip install <PATH TO WHEEL>`
22+
3. Copy the contents of arrow-flight-client-examples/python/example.py into your own python file.
23+
4. Run your python file with a local instance of Dremio:
24+
- `python3 example.py --username <USER> --password <password> -query 'SELECT 1'`
3425

35-
#### 1.1.3 Usage
36-
```
37-
example.py [-h] [-host HOSTNAME] [-port FLIGHTPORT] -user USERNAME -pass PASSWORD [-query SQLQUERY] [-tls] [-certs TRUSTEDCERTIFICATES]
3826

39-
optional arguments:
40-
-h, --help show this help message and exit
41-
-host HOSTNAME, --hostname HOSTNAME Dremio co-ordinator hostname
42-
-port FLIGHTPORT, --flightPort FLIGHTPORT Dremio flight server port
43-
-user USERNAME, --username USERNAME Dremio username
44-
-pass PASSWORD, --password PASSWORD Dremio password
45-
-query SQLQUERY, --sqlquery SQLQUERY SQL query to test
46-
-tls, --tls Enable encrypted connection
47-
-certs TRUSTEDCERTIFICATES, --trustedCertificates TRUSTEDCERTIFICATES Path to trusted certificates for encrypted connection
48-
```
49-
---
5027

5128
### 1.2 Query your dataset with arrow flight client in java
5229
This lightweight Java client application connects to the Dremio Arrow Flight server endpoint. It requires the username and password for authentication. Developers can use admin or regular user credentials for authentication. Any datasets in Dremio that are accessible by the provided Dremio user can be queried. By default, the hostname is `localhost` and the port is `32010`. Developers can change these default settings by providing the hostname and port as arguments when running the client. Moreover, the tls option can be provided to establish an encrypted connection.

python/README.md

Lines changed: 54 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,82 +1,73 @@
11
# Python Arrow Flight Client Application Example
2-
![Build Status](https://github.com/dremio-hub/arrow-flight-client-examples/workflows/python-build/badge.svg)
32

4-
This lightweight Python client application connects to the Dremio Arrow Flight server endpoint. Developers can use token based or regular user credentials (username/password) for authentication. Please note username/password is not supported for Dremio Cloud. Any datasets in Dremio that are accessible by the provided Dremio user can be queried. By default, the hostname is `localhost` and the port is `32010`. Developers can change these default settings by providing the hostname and port as arguments when running the client.
5-
Moreover, the tls option can be provided to establish an encrypted connection.
3+
## Getting Started
4+
1. Install [Python 3](https://www.python.org/downloads/)
5+
2. Download and install the [dremio-flight-endpoint whl file](https://github.com/dremio-hub/arrow-flight-client-examples/releases)
6+
- `python -m pip install <PATH TO WHEEL>`
7+
3. Copy the contents of arrow-flight-client-examples/python/example.py into your own python file.
8+
4. Run your python file with a local instance of Dremio:
9+
- `python3 example.py --username <USER> --password <password> -query 'SELECT 1'`
10+
11+
12+
## How to connect to Dremio Cloud
13+
14+
Get started with your first query to Dremio Cloud.
15+
16+
* The following example requires you to create a [Personal Access Token](https://docs.dremio.com/cloud/security/authentication/personal-access-token/) in Dremio. Replace ```<INSERT PAT HERE>``` in the example below with your actual PAT token.
17+
* You may need to wait for a Dremio engine to start up or start it manually if no Dremio engine for your Organization is running.
18+
19+
This example queries the Dremio Sample dataset ```NYC-taxi-trips``` and returns the first 10 values.
20+
21+
```python3 example.py -host data.dremio.cloud -port 443 -pat '<INSERT PAT HERE>' -tls -query 'SELECT * FROM Samples."samples.dremio.com"."NYC-taxi-trips" limit 10'```
22+
23+
You have now run your first Flight query on Dremio Cloud!
624

7-
### Instructions on using this Python sample application
8-
- Install and setup Python3 as `pyarrow` requires Python3
9-
- This application also requires `pyarrow` and `pandas`. Consider one of the dependency installation methods below. We recommend using `conda` for its ease of use.
10-
- Install dependencies using `conda`
11-
- `conda install -c conda-forge --file requirements.txt`
12-
- Alternatively, install dependencies using `pip`
13-
- `pip3 install -r requirements.txt`
14-
- Run the Python sample application with a local instance of Dremio (with default parameters):
15-
- `python3 example.py -query 'SELECT 1'`
25+
## Configuration Options
1626

1727
```
18-
usage: example.py [-h] [-host HOSTNAME] [-port PORT] [-user USERNAME] [-pass PASSWORD]
19-
[-pat, -authToken PAT_OR_AUTH_TOKEN] [-query QUERY] [-tls] [-dsv DISABLE_SERVER_VERIFICATION]
20-
[-certs TRUSTED_CERTIFICATES] [-sessionProperties [SESSION_PROPERTIES ...]] [-engine ENGINE]
28+
usage: example.py [-h] [-host HOSTNAME] [-port PORT] -user USERNAME -pass PASSWORD
29+
-pat TOKEN -query QUERY [-tls]
30+
[-dcv DISABLE_CERTIFICATE_VERIFICATION]
31+
[-path_to_certs PATH_TO_CERTS] [-sp [SESSION_PROPERTIES ...]]
32+
[-engine ENGINE]
2133
22-
optional arguments:
34+
options:
2335
-h, --help show this help message and exit
2436
-host HOSTNAME, --hostname HOSTNAME
2537
Dremio co-ordinator hostname. Defaults to "localhost".
2638
-port PORT, --flightport PORT
2739
Dremio flight server port. Defaults to 32010.
2840
-user USERNAME, --username USERNAME
29-
Dremio username. Defaults to "dremio".
41+
Dremio username. Not applicable when connecting to Dremio
42+
Cloud
3043
-pass PASSWORD, --password PASSWORD
31-
Dremio password. Defaults to "dremio123".
32-
-pat PAT_OR_AUTH_TOKEN, --personalAccessToken PAT_OR_AUTH_TOKEN, -authToken PAT_OR_AUTH_TOKEN, --authToken PAT_OR_AUTH_TOKEN
33-
Either a Personal Access Token or an OAuth2 Token.
44+
Dremio password. Not applicable when connecting to Dremio
45+
Cloud
46+
-pat TOKEN, --token TOKEN
47+
Either a Personal Access Token or an OAuth2 Token. Only
48+
applicable to Dremio Cloud. Use --password if connecting to
49+
Dremio Software using PAT
3450
-query QUERY, --sqlQuery QUERY
35-
SQL query to test.
51+
SQL query to test. Must be enclosed in single quotes. If
52+
single quotes are already present within the query, change
53+
those to double quotes and enclose entire query in single
54+
quotes.
3655
-tls, --tls Enable encrypted connection. Defaults to False.
37-
-dsv DISABLE_SERVER_VERIFICATION, --disableServerVerification DISABLE_SERVER_VERIFICATION
38-
Disable TLS server verification. Defaults to False.
39-
-certs TRUSTED_CERTIFICATES, --trustedCertificates TRUSTED_CERTIFICATES
40-
Path to trusted certificates for encrypted connection. Defaults to system certificates.
41-
-sessionProperties [SESSION_PROPERTIES ...], --sessionProperties [SESSION_PROPERTIES ...]
42-
Key value pairs of SessionProperty, example: -sessionProperties schema='Samples."samples.dremio.com"'
56+
-dcv DISABLE_CERTIFICATE_VERIFICATION, --disableCertificateVerification DISABLE_CERTIFICATE_VERIFICATION
57+
Disables TLS server verification. Defaults to False.
58+
-path_to_certs PATH_TO_CERTS, --trustedCertificates PATH_TO_CERTS
59+
Path to trusted certificates for encrypted connection.
60+
Defaults to system certificates.
61+
-sp [SESSION_PROPERTIES ...], --sessionProperty [SESSION_PROPERTIES ...]
62+
Key value pairs of SessionProperty, example: -sp
63+
schema='Samples."samples.dremio.com"' -sp key=value
4364
-engine ENGINE, --engine ENGINE
44-
The specific engine to run against.
45-
```
46-
47-
### Getting Started
48-
49-
Get started with your first query to Dremio Cloud.
50-
51-
* The following example requires you to create a [Personal Access Token](https://docs.dremio.com/software/security/personal-access-tokens/) in Dremio. Replace ```<INSERT PAT HERE>``` in the example below with your actual PAT token.
52-
* You may need to wait for a Dremio engine to start up if no Dremio engine for your Organization is running.
53-
54-
This example queries the Dremio Sample dataset ```NYC-taxi-trips``` and returns the first 10 values.
65+
The specific engine to run against. Only applicable to Dremio
66+
Cloud.
5567
56-
```python3 example.py -host data.dremio.cloud -port 443 -pat '<INSERT PAT HERE>' -tls -query 'SELECT * FROM Samples."samples.dremio.com"."NYC-taxi-trips" limit 10'```
57-
58-
Running the command will return the following.
59-
60-
``` [INFO] Enabling TLS connection
61-
[INFO] Trusted certificates provided
62-
[INFO] Authentication skipped until first request
63-
[INFO] Query: SELECT * FROM Samples."samples.dremio.com"."NYC-taxi-trips" limit 10
64-
[INFO] GetSchema was successful
65-
[INFO] Schema: <pyarrow._flight.SchemaResult object at 0x7febe2944610>
66-
[INFO] GetFlightInfo was successful
67-
[INFO] Ticket: <Ticket b'\nDSELECT * FROM Samples."samples.dremio.com"."NYC-taxi-trips" limit 10\x12^\n\\\nDSELECT * FROM Samples."samples.dremio.com"."NYC-taxi-trips" limit 10\x10(\x1a\x12\t\x8a\x883#\x12\xd1\xd9\x1d\x11\x00\xb3\xbbC\xdb\xd9J\t'>
68-
[INFO] Reading query results from Dremio
69-
pickup_datetime passenger_count trip_distance_mi fare_amount tip_amount total_amount
70-
0 2013-05-27 19:15:00 1 1.26 7.5 0.00 8.00
71-
1 2013-05-31 16:40:00 1 0.73 5.0 1.20 7.70
72-
2 2013-05-27 19:03:00 2 9.23 27.5 5.00 38.33
73-
3 2013-05-31 16:24:00 1 2.27 12.0 0.00 13.50
74-
4 2013-05-27 19:17:00 1 0.71 5.0 0.00 5.50
75-
5 2013-05-27 19:11:00 1 2.52 10.5 3.15 14.15
76-
6 2013-05-31 16:41:00 5 1.01 6.0 1.10 8.60
77-
7 2013-05-31 16:37:00 1 1.25 8.5 0.00 10.00
78-
8 2013-05-31 16:39:00 1 2.04 10.0 1.50 13.00
79-
9 2013-05-27 19:02:00 1 11.73 32.5 8.12 41.12
8068
```
8169

82-
You have now run your first Flight query on Dremio Cloud!
70+
## Description
71+
![Build Status](https://github.com/dremio-hub/arrow-flight-client-examples/workflows/python-build/badge.svg)
72+
This lightweight Python client application connects to the Dremio Arrow Flight server endpoint. Developers can use token based or regular user credentials (username/password) for authentication. Please note username/password is not supported for Dremio Cloud. Any datasets in Dremio that are accessible by the provided Dremio user can be queried. By default, the hostname is `localhost` and the port is `32010`. Developers can change these default settings by providing the hostname and port as arguments when running the client.
73+
Moreover, the tls option can be provided to establish an encrypted connection.

python/dremio-flight/dremio/__init__.py

Whitespace-only changes.

python/dremio-flight/dremio/arguments/__init__.py

Whitespace-only changes.
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
"""
2+
Copyright (C) 2017-2021 Dremio Corporation
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
"""
16+
17+
import argparse
18+
import sys
19+
import certifi
20+
21+
22+
class KVParser(argparse.Action):
23+
def __call__(self, parser, namespace, values, option_string=None):
24+
setattr(namespace, self.dest, [])
25+
26+
dest = list(
27+
map(
28+
lambda value: list(
29+
map(lambda split_val: split_val.encode("utf-8"), value.split("="))
30+
),
31+
values,
32+
)
33+
)
34+
setattr(namespace, self.dest, dest)
35+
36+
37+
def parse_arguments():
38+
"""
39+
Parses the command-line arguments supplied to the script.
40+
"""
41+
42+
parser = argparse.ArgumentParser()
43+
parser.add_argument(
44+
"-host",
45+
"--hostname",
46+
type=str,
47+
help='Dremio co-ordinator hostname. Defaults to "localhost".',
48+
default="localhost",
49+
)
50+
parser.add_argument(
51+
"-port",
52+
"--flightport",
53+
dest="port",
54+
type=int,
55+
help="Dremio flight server port. Defaults to 32010.",
56+
default=32010,
57+
)
58+
parser.add_argument(
59+
"-user",
60+
"--username",
61+
type=str,
62+
help="Dremio username. Not applicable when connecting to Dremio Cloud",
63+
required="-pat" not in sys.argv and "--token" not in sys.argv,
64+
)
65+
parser.add_argument(
66+
"-pass",
67+
"--password",
68+
type=str,
69+
help="Dremio password. Not applicable when connecting to Dremio Cloud",
70+
required="-pat" not in sys.argv and "--token" not in sys.argv,
71+
)
72+
parser.add_argument(
73+
"-pat",
74+
"--token",
75+
dest="token",
76+
type=str,
77+
help="Either a Personal Access Token or an OAuth2 Token. Only applicable to Dremio Cloud. Use --password if connecting to Dremio Software using PAT",
78+
required="-user" not in sys.argv and "--username" not in sys.argv,
79+
)
80+
parser.add_argument(
81+
"-query",
82+
"--sqlQuery",
83+
dest="query",
84+
type=str,
85+
help="SQL query to test. Must be enclosed in single quotes. If single quotes are already present within the query, change those to double quotes and enclose entire query in single quotes.",
86+
required=True,
87+
)
88+
parser.add_argument(
89+
"-tls",
90+
"--tls",
91+
dest="tls",
92+
help="Enable encrypted connection. Defaults to False.",
93+
default=False,
94+
action="store_true",
95+
)
96+
parser.add_argument(
97+
"-dcv",
98+
"--disableCertificateVerification",
99+
dest="disable_certificate_verification",
100+
type=bool,
101+
help="Disables TLS server verification. Defaults to False.",
102+
default=False,
103+
)
104+
parser.add_argument(
105+
"-path_to_certs",
106+
"--trustedCertificates",
107+
dest="path_to_certs",
108+
type=str,
109+
help="Path to trusted certificates for encrypted connection. Defaults to system certificates.",
110+
default=certifi.where(),
111+
)
112+
parser.add_argument(
113+
"-sp",
114+
"--sessionProperty",
115+
dest="session_properties",
116+
help="Key value pairs of SessionProperty, example: -sp schema='Samples.\"samples.dremio.com\"' -sp key=value",
117+
required=False,
118+
nargs="*",
119+
action=KVParser,
120+
)
121+
parser.add_argument(
122+
"-engine",
123+
"--engine",
124+
type=str,
125+
help="The specific engine to run against. Only applicable to Dremio Cloud.",
126+
required=False,
127+
)
128+
return parser.parse_args()

python/dremio-flight/dremio/flight/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)