99from deltalake .table import DeltaTable
1010from deltalake .warnings import ExperimentalWarning
1111
12-
1312class QueryBuilder :
13+ """
14+ QueryBuilder is an experimental API which exposes Apache DataFusion SQL to Python users of the deltalake library.
15+
16+ This API is subject to change.
17+
18+ >>> qb = QueryBuilder()
19+ """
1420 def __init__ (self ) -> None :
1521 warnings .warn (
1622 "QueryBuilder is experimental and subject to change" ,
@@ -19,13 +25,38 @@ def __init__(self) -> None:
1925 self ._query_builder = PyQueryBuilder ()
2026
2127 def register (self , table_name : str , delta_table : DeltaTable ) -> QueryBuilder :
22- """Add a table to the query builder."""
28+ """
29+ Add a table to the query builder instance by name. The `table_name`
30+ will be how the referenced `DeltaTable` can be referenced in SQL
31+ queries.
32+
33+ For example:
34+
35+ >>> tmp = getfixture('tmp_path')
36+ >>> import pyarrow as pa
37+ >>> from deltalake import DeltaTable, QueryBuilder
38+ >>> dt = DeltaTable.create(table_uri=tmp, schema=pa.schema([pa.field('name', pa.string())]))
39+ >>> qb = QueryBuilder().register('test', dt)
40+ >>> assert qb is not None
41+ """
2342 self ._query_builder .register (
2443 table_name = table_name ,
2544 delta_table = delta_table ._table ,
2645 )
2746 return self
2847
2948 def execute (self , sql : str ) -> List [pyarrow .RecordBatch ]:
30- """Execute the query and return a list of record batches."""
49+ """
50+ Execute the query and return a list of record batches
51+
52+ For example:
53+
54+ >>> tmp = getfixture('tmp_path')
55+ >>> import pyarrow as pa
56+ >>> from deltalake import DeltaTable, QueryBuilder
57+ >>> dt = DeltaTable.create(table_uri=tmp, schema=pa.schema([pa.field('name', pa.string())]))
58+ >>> qb = QueryBuilder().register('test', dt)
59+ >>> results = qb.execute('SELECT * FROM test')
60+ >>> assert results is not None
61+ """
3162 return self ._query_builder .execute (sql )
0 commit comments