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+ """
20+
1421 def __init__ (self ) -> None :
1522 warnings .warn (
1623 "QueryBuilder is experimental and subject to change" ,
@@ -19,13 +26,38 @@ def __init__(self) -> None:
1926 self ._query_builder = PyQueryBuilder ()
2027
2128 def register (self , table_name : str , delta_table : DeltaTable ) -> QueryBuilder :
22- """Add a table to the query builder."""
29+ """
30+ Add a table to the query builder instance by name. The `table_name`
31+ will be how the referenced `DeltaTable` can be referenced in SQL
32+ queries.
33+
34+ For example:
35+
36+ >>> tmp = getfixture('tmp_path')
37+ >>> import pyarrow as pa
38+ >>> from deltalake import DeltaTable, QueryBuilder
39+ >>> dt = DeltaTable.create(table_uri=tmp, schema=pa.schema([pa.field('name', pa.string())]))
40+ >>> qb = QueryBuilder().register('test', dt)
41+ >>> assert qb is not None
42+ """
2343 self ._query_builder .register (
2444 table_name = table_name ,
2545 delta_table = delta_table ._table ,
2646 )
2747 return self
2848
2949 def execute (self , sql : str ) -> List [pyarrow .RecordBatch ]:
30- """Execute the query and return a list of record batches."""
50+ """
51+ Execute the query and return a list of record batches
52+
53+ For example:
54+
55+ >>> tmp = getfixture('tmp_path')
56+ >>> import pyarrow as pa
57+ >>> from deltalake import DeltaTable, QueryBuilder
58+ >>> dt = DeltaTable.create(table_uri=tmp, schema=pa.schema([pa.field('name', pa.string())]))
59+ >>> qb = QueryBuilder().register('test', dt)
60+ >>> results = qb.execute('SELECT * FROM test')
61+ >>> assert results is not None
62+ """
3163 return self ._query_builder .execute (sql )
0 commit comments