Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/betodealmeida/druid-dbapi
Python DB-API and SQLAlchemy dialect for Druid.
https://github.com/betodealmeida/druid-dbapi
dbapi druid druid-io python
Last synced: 2 months ago
JSON representation
Python DB-API and SQLAlchemy dialect for Druid.
- Host: GitHub
- URL: https://github.com/betodealmeida/druid-dbapi
- Owner: betodealmeida
- License: mit
- Created: 2017-12-13T18:38:31.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2021-03-29T17:22:27.000Z (over 3 years ago)
- Last Synced: 2024-10-13T14:27:25.612Z (2 months ago)
- Topics: dbapi, druid, druid-io, python
- Language: Python
- Homepage:
- Size: 33.2 KB
- Stars: 6
- Watchers: 2
- Forks: 4
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# A Python DB API 2.0 for Druid #
This module allows accessing Druid via its [experimental SQL API](http://druid.io/docs/latest/querying/sql.html).
## Usage ##
Using the DB API:
```python
from druiddb import connectconn = connect(host='localhost', port=8082, path='/druid/v2/sql/', scheme='http')
curs = conn.cursor()
curs.execute("""
SELECT place,
CAST(REGEXP_EXTRACT(place, '(.*),', 1) AS FLOAT) AS lat,
CAST(REGEXP_EXTRACT(place, ',(.*)', 1) AS FLOAT) AS lon
FROM places
LIMIT 10
""")
for row in curs:
print(row)
```
Using SQLAlchemy:```python
from sqlalchemy import *
from sqlalchemy.engine import create_engine
from sqlalchemy.schema import *engine = create_engine('druid://localhost:8082/druid/v2/sql/') # uses HTTP by default :(
# engine = create_engine('druid+http://localhost:8082/druid/v2/sql/')
# engine = create_engine('druid+https://localhost:8082/druid/v2/sql/')places = Table('places', MetaData(bind=engine), autoload=True)
print(select([func.count('*')], from_obj=places).scalar())
```Using the REPL:
```bash
$ druiddb http://localhost:8082/druid/v2/sql/
> SELECT COUNT(*) AS cnt FROM places
cnt
-----
12345
```