Databricks SQL framework, easy to learn, fast to code, ready for production.
Project description
Databricks SQL
Databricks SQL framework, easy to learn, fast to code, ready for production.
Installation
$ pip install databricks-sql
Configuration
from databricks_sql.client import Configuration
CONFIGURATION = Configuration.instance(
access_token="",
command_directory="",
http_path="",
server_hostname="",
)
Usage
Databricks SQL usage description:
Execute
from databricks_sql.client import Database
with Database() as connection:
(
connection
.execute(
"""
CREATE TABLE IF NOT EXISTS catalog.schema.table (
id STRING NOT NULL,
name STRING NOT NULL,
description STRING,
CONSTRAINT table_primary_key PRIMARY KEY(id)
) USING DELTA
""",
parameters=None,
skip_load=True,
)
)
Insert
from databricks_sql.client import Database
with Database() as connection:
(
connection
.insert("catalog.schema.table")
.set("id", "994238a4-8c18-436a-8c06-29ec89c4c056")
.set("name", "Name")
.set("description", "Description")
.execute()
)
Paging
Paging with where condition
from databricks_sql.client import Database
with Database() as connection:
(
connection
.select("catalog.schema.table")
.fields("id", "name", "description")
.where("name", "%Databricks%", operator="LIKE")
.order_by("id")
.paging(0, 10)
)
Paging without where condition
from databricks_sql.client import Database
with Database() as connection:
(
connection
.select("catalog.schema.table")
.paging(0, 10)
)
Select
Fetch all
from databricks_sql.client import Database
with Database() as connection:
(
connection
.select("test")
.execute()
.fetch_all()
)
Fetch many
from databricks_sql.client import Database
with Database() as connection:
(
connection
.select("test")
.execute()
.fetch_many(1)
)
Fetch one
from databricks_sql.client import Database
with Database() as connection:
(
connection
.select("test")
.execute()
.fetch_one()
)
Select by file
from databricks_sql.client import Database
with Database() as connection:
(
connection
.execute("read_by_id", {"id": "994238a4-8c18-436a-8c06-29ec89c4c056"})
.fetch_one()
)
Select by command
from databricks_sql.client import Database
with Database() as connection:
(
connection
.execute("SELECT id, name, description FROM catalog.schema.table WHERE id = %(id)s", {"id": "994238a4-8c18-436a-8c06-29ec89c4c056"})
.fetch_one()
)
License
This project is licensed under the terms of the Apache License 2.0.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
databricks_sql-0.0.3.tar.gz
(8.1 kB
view hashes)
Built Distribution
Close
Hashes for databricks_sql-0.0.3-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 32bebb9b60f1dabca49c7e61d37724140520e0602f254c2beedb44a3ac0a1911 |
|
MD5 | 9e9f2cc543a2ae18da3b6ae3c84e7929 |
|
BLAKE2b-256 | 00055edbea65d3c270d2fb462ecb0bf4a2d692c451388ec7d12fece18e482524 |