Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/pinot_dbapi_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.9", "3.10", "3.11", "3.12"]
python-version: ["3.10", "3.11", "3.12"]
name: Pinot DB API Integration Test Set
steps:
- uses: actions/checkout@v2
Expand Down Expand Up @@ -75,7 +75,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.9", "3.10", "3.11", "3.12"]
python-version: ["3.10", "3.11", "3.12"]
name: Pinot DB API Unit Test Set
steps:
- uses: actions/checkout@v2
Expand Down
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ pinot+https://<my-user>:<my-password>@<pinot-broker-host>:<pinot-broker-port><pi
E.g.
`pinot+https://my-user:my-password@my-secure-pinot-broker:443/query/sql?controller=https://my-secure-pinot-controller/&&verify_ssl=true`.

Below are some sample scripts to query pinot using sqlalchemy:
Below are some sample scripts to query pinot using SQLAlchemy 2.x:

```python
from sqlalchemy import *
Expand All @@ -135,8 +135,11 @@ engine = create_engine('pinot://localhost:8099/query/sql?controller=http://local
# connect_args={"use_multistage_engine": "true"}
# )

places = Table('places', MetaData(bind=engine), autoload=True)
print(select([func.count('*')], from_obj=places).scalar())
metadata = MetaData()
places = Table('places', metadata, autoload_with=engine)
query = select(func.count()).select_from(places)
with engine.connect() as connection:
print(connection.execute(query).scalar())
```

To configure query parameters (such as `timeoutMs=10000`) at the engine level
Expand Down
35 changes: 23 additions & 12 deletions examples/pinot_live.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,25 +23,36 @@ def run_pinot_live_example() -> None:
connect_args={"query_options": "timeoutMs=10000"}
) # uses HTTP by default :(

airlineStats = Table("airlineStats", MetaData(bind=engine), autoload=True, schema="default")
metadata = MetaData()
airlineStats = Table(
"airlineStats",
metadata,
autoload_with=engine,
schema="default",
)
print(f"\nSending Count(*) SQL to Pinot")
query=select([func.count("*")], from_obj=airlineStats)
print(engine.execute(query).scalar())
query = select(func.count()).select_from(airlineStats)
with engine.connect() as connection:
print(connection.execute(query).scalar())

Session = sessionmaker(bind=engine)
session = Session()
query = select(
[column("AirlineID"), func.max(column("AirTime")).label("max_airtime")],
from_obj=airlineStats,
group_by=[column("AirlineID")],
order_by=text("max_airtime DESC"),
limit="10",
query = (
select(
column("AirlineID"),
func.max(column("AirTime")).label("max_airtime"),
)
.select_from(airlineStats)
.group_by(column("AirlineID"))
.order_by(text("max_airtime DESC"))
.limit(10)
)
print(
f'\nSending SQL: "SELECT playerName, sum(runs) AS sum_runs FROM "baseballStats"'
f' WHERE yearID>=2000 GROUP BY playerName ORDER BY sum_runs DESC LIMIT 5" to Pinot'
'\nSending SQL: "SELECT AirlineID, max(AirTime) AS max_airtime FROM airlineStats '
'GROUP BY AirlineID ORDER BY max_airtime DESC LIMIT 10" to Pinot'
)
print(engine.execute(query).fetchall())
with engine.connect() as connection:
print(connection.execute(query).fetchall())


def run_main():
Expand Down
33 changes: 22 additions & 11 deletions examples/pinot_quickstart_auth_zk.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,26 +66,37 @@ def run_pinot_quickstart_batch_sqlalchemy_example() -> None:
# engine = create_engine('pinot+http://localhost:8000/query/sql?controller=http://localhost:9000/')
# engine = create_engine('pinot+https://localhost:8000/query/sql?controller=http://localhost:9000/')

baseballStats = Table("baseballStats", MetaData(bind=engine), autoload=True, schema="default")
metadata = MetaData()
baseballStats = Table(
"baseballStats",
metadata,
autoload_with=engine,
schema="default",
)
print(f"\nSending Count(*) SQL to Pinot")
query = select([func.count("*")], from_obj=baseballStats)
print(engine.execute(query).scalar())
query = select(func.count()).select_from(baseballStats)
with engine.connect() as connection:
print(connection.execute(query).scalar())

Session = sessionmaker(bind=engine)
session = Session()
query = select(
[column("playerName"), func.sum(column("runs")).label("sum_runs")],
from_obj=baseballStats,
whereclause=text("yearID>=2000"),
group_by=[column("playerName")],
order_by=text("sum_runs DESC"),
limit="5",
query = (
select(
column("playerName"),
func.sum(column("runs")).label("sum_runs"),
)
.select_from(baseballStats)
.where(text("yearID>=2000"))
.group_by(column("playerName"))
.order_by(text("sum_runs DESC"))
.limit(5)
)
print(
f'\nSending SQL: "SELECT playerName, sum(runs) AS sum_runs FROM "baseballStats"'
f' WHERE yearID>=2000 GROUP BY playerName ORDER BY sum_runs DESC LIMIT 5" to Pinot'
)
print(engine.execute(query).fetchall())
with engine.connect() as connection:
print(connection.execute(query).fetchall())


def run_main():
Expand Down
33 changes: 22 additions & 11 deletions examples/pinot_quickstart_batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,25 +53,36 @@ def run_pinot_quickstart_batch_sqlalchemy_example() -> None:
# engine = create_engine('pinot+http://localhost:8000/query/sql?controller=http://localhost:9000/')
# engine = create_engine('pinot+https://localhost:8000/query/sql?controller=http://localhost:9000/')

baseballStats = Table("baseballStats", MetaData(bind=engine), autoload=True, schema="default")
metadata = MetaData()
baseballStats = Table(
"baseballStats",
metadata,
autoload_with=engine,
schema="default",
)
print(f"\nSending Count(*) SQL to Pinot")
query = select([func.count("*")], from_obj=baseballStats)
print(engine.execute(query).scalar())
query = select(func.count()).select_from(baseballStats)
with engine.connect() as connection:
print(connection.execute(query).scalar())

Session = sessionmaker(bind=engine)
session = Session()
query = select(
[column("playerName"), func.sum(column("runs")).label("sum_runs")],
from_obj=baseballStats,
whereclause=text("yearID>=2000"),
group_by=[column("playerName")],
order_by=text("sum_runs DESC"),
limit="5",
query = (
select(
column("playerName"),
func.sum(column("runs")).label("sum_runs"),
)
.select_from(baseballStats)
.where(text("yearID>=2000"))
.group_by(column("playerName"))
.order_by(text("sum_runs DESC"))
.limit(5)
)
print(
f'\nSending SQL: "SELECT playerName, sum(runs) AS sum_runs FROM "baseballStats" WHERE yearID>=2000 GROUP BY playerName ORDER BY sum_runs DESC LIMIT 5" to Pinot'
)
print(engine.execute(query).fetchall())
with engine.connect() as connection:
print(connection.execute(query).fetchall())


def run_main():
Expand Down
33 changes: 22 additions & 11 deletions examples/pinot_quickstart_hybrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,28 +55,39 @@ def run_pinot_quickstart_hybrid_sqlalchemy_example() -> None:
# engine = create_engine('pinot+http://localhost:8000/query/sql?controller=http://localhost:9000/')
# engine = create_engine('pinot+https://localhost:8000/query/sql?controller=http://localhost:9000/')

airlineStats = Table("airlineStats", MetaData(bind=engine), autoload=True, schema="default")
metadata = MetaData()
airlineStats = Table(
"airlineStats",
metadata,
autoload_with=engine,
schema="default",
)
print(f"\nSending Count(*) SQL to Pinot")
query=select([func.count("*")], from_obj=airlineStats)
print(engine.execute(query).scalar())
query = select(func.count()).select_from(airlineStats)
with engine.connect() as connection:
print(connection.execute(query).scalar())


from sqlalchemy.orm import sessionmaker

Session = sessionmaker(bind=engine)
session = Session()
query = select(
[column("OriginCityName"), func.sum(column("Cancelled")).label("sum_cancelled")],
from_obj=airlineStats,
whereclause=text("Year>2010"),
group_by=[column("OriginCityName")],
order_by=text("sum_cancelled DESC"),
limit="5",
query = (
select(
column("OriginCityName"),
func.sum(column("Cancelled")).label("sum_cancelled"),
)
.select_from(airlineStats)
.where(text("Year>2010"))
.group_by(column("OriginCityName"))
.order_by(text("sum_cancelled DESC"))
.limit(5)
)
print(
f'\nSending SQL: "SELECT OriginCityName, sum(Cancelled) AS sum_cancelled FROM "airlineStats" WHERE Year>2010 GROUP BY OriginCityName ORDER BY sum_cancelled DESC LIMIT 5" to Pinot'
)
print(engine.execute(query).fetchall())
with engine.connect() as connection:
print(connection.execute(query).fetchall())


def run_main():
Expand Down
54 changes: 34 additions & 20 deletions examples/pinot_quickstart_json_batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,51 +44,65 @@ def run_quickstart_json_batch_sqlalchemy_example() -> None:
# engine = create_engine('pinot+http://localhost:8000/query/sql?controller=http://localhost:9000/')
# engine = create_engine('pinot+https://localhost:8000/query/sql?controller=http://localhost:9000/')

githubEvents = Table("githubEvents", MetaData(bind=engine), autoload=True, schema="default")
metadata = MetaData()
githubEvents = Table(
"githubEvents",
metadata,
autoload_with=engine,
schema="default",
)
print(f"\nSending Count(*) SQL to Pinot\nResults:")
query=select([func.count("*")], from_obj=githubEvents)
print(engine.execute(query).scalar())
query = select(func.count()).select_from(githubEvents)
with engine.connect() as connection:
print(connection.execute(query).scalar())

Session = sessionmaker(bind=engine)
session = Session()
query = select(
[text("json_extract_scalar(repo, \'$.name\', \'STRING\')"), func.count("*")],
from_obj=githubEvents,
whereclause=text("json_match(actor, '\"$.login\"=''LombiqBot''')"),
group_by=text("1"),
order_by=text("2 DESC"),
limit="10",
query = (
select(
text("json_extract_scalar(repo, \'$.name\', \'STRING\')"),
func.count(),
)
.select_from(githubEvents)
.where(text("json_match(actor, '\"$.login\"=''LombiqBot''')"))
.group_by(text("1"))
.order_by(text("2 DESC"))
.limit(10)
)
print(
f'\nSending SQL: "SELECT json_extract_scalar(repo, \'$.name\', \'STRING\'), count(*) FROM githubEvents'
f' WHERE json_match(actor, \'\"$.login\"=''LombiqBot''\') GROUP BY 1 ORDER BY 2 DESC LIMIT 10" to Pinot'
'\nResults:'
)
print(engine.execute(query).fetchall())
with engine.connect() as connection:
print(connection.execute(query).fetchall())

Session = sessionmaker(bind=engine)
session = Session()
query = select(["*"],
from_obj=githubEvents,
limit="10",
)
# Pinot doesn't accept fully qualified reflected column references like
# `default.githubEvents.id` (emitted by SQLAlchemy when selecting the whole
# reflected table). Use a raw SELECT * instead.
query = text("SELECT * FROM githubEvents LIMIT 10")
print(
f'\nSending SQL: "SELECT * FROM githubEvents LIMIT 10" to Pinot'
f'\nResults:'
)
print(engine.execute(query).fetchall())
with engine.connect() as connection:
print(connection.execute(query).fetchall())

Session = sessionmaker(bind=engine)
session = Session()
query = select([column("created_at_timestamp")],
from_obj=githubEvents,
limit="10",
query = (
select(column("created_at_timestamp"))
.select_from(githubEvents)
.limit(10)
)
print(
f'\nSending SQL: "SELECT created_at_timestamp FROM githubEvents LIMIT 10" to Pinot'
f'\nResults:'
)
print(engine.execute(query).fetchall())
with engine.connect() as connection:
print(connection.execute(query).fetchall())


def run_main():
Expand Down
3 changes: 2 additions & 1 deletion examples/pinot_quickstart_multi_stage.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,9 @@ def run_pinot_quickstart_multi_stage_sqlalchemy_example() -> None:

def run_pinot_quickstart_multi_stage_sqlalchemy_example_2() -> None:

# Multi-stage engine requires /query/sql endpoint.
engine = create_engine(
"pinot://localhost:8000/query?controller=http://localhost:9000/",
"pinot://localhost:8000/query/sql?controller=http://localhost:9000/",
connect_args={"useMultistageEngine": "true"}
) # uses HTTP by default :(
# engine = create_engine('pinot+http://localhost:8000/query/sql?controller=http://localhost:9000/')
Expand Down
Loading
Loading