Skip to content

Commit 8d6b885

Browse files
fetch data from cassandra
1 parent 79fab40 commit 8d6b885

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

ingestr/src/cassandra/__init__.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import dlt
2+
3+
from cassandra.auth import PlainTextAuthProvider # type: ignore
4+
from cassandra.cluster import Cluster # type: ignore
5+
6+
7+
@dlt.source(max_table_nesting=0)
8+
def cassandra_source(
9+
host: str,
10+
port: int,
11+
keyspace: str | None = None,
12+
table: str | None = None,
13+
username: str | None = None,
14+
password: str | None = None,
15+
):
16+
@dlt.resource()
17+
def fetch_data():
18+
auth_provider = PlainTextAuthProvider(username=username, password=password)
19+
cluster = Cluster(contact_points=[host], port=port, auth_provider=auth_provider)
20+
session = cluster.connect(keyspace)
21+
22+
rows = session.execute(f"SELECT * FROM {table}")
23+
24+
for row in rows:
25+
yield row
26+
27+
return fetch_data

0 commit comments

Comments
 (0)