|
57 | 57 |
|
58 | 58 | from __future__ import annotations |
59 | 59 |
|
| 60 | +import importlib |
60 | 61 | import importlib.metadata as importlib_metadata |
| 62 | +import warnings |
61 | 63 | from typing import Any |
62 | 64 |
|
63 | 65 | # Public submodules |
64 | 66 | from . import functions, ipc, object_store, substrait, unparser |
65 | | - |
66 | | -# The following imports are okay to remain as opaque to the user. |
67 | | -from .catalog import ( |
68 | | - Catalog, |
69 | | - Table, |
70 | | - TableProviderFactory, |
71 | | - TableProviderFactoryExportable, |
72 | | -) |
| 67 | +from .catalog import Table |
73 | 68 | from .col import col, column |
74 | | -from .common import DFSchema |
75 | 69 | from .context import ( |
76 | 70 | RuntimeEnvBuilder, |
77 | 71 | SessionConfig, |
78 | 72 | SessionContext, |
79 | | - SQLOptions, |
80 | | -) |
81 | | -from .dataframe import ( |
82 | | - DataFrame, |
83 | | - DataFrameWriteOptions, |
84 | | - ExplainFormat, |
85 | | - InsertOp, |
86 | | - ParquetColumnOptions, |
87 | | - ParquetWriterOptions, |
88 | 73 | ) |
| 74 | +from .dataframe import DataFrame |
89 | 75 | from .dataframe_formatter import configure_formatter |
90 | | -from .expr import Expr, WindowFrame |
| 76 | +from .expr import Expr |
91 | 77 | from .extensions import SessionExtensionComponents |
92 | 78 | from .io import read_avro, read_csv, read_json, read_parquet |
93 | 79 | from .options import CsvReadOptions |
94 | | -from .plan import ( |
95 | | - ExecutionPlan, |
96 | | - LogicalPlan, |
97 | | - Metric, |
98 | | - MetricsSet, |
99 | | - PhysicalPartitioning, |
100 | | -) |
101 | | -from .record_batch import RecordBatch, RecordBatchStream |
| 80 | +from .record_batch import RecordBatch |
102 | 81 | from .user_defined import ( |
103 | 82 | Accumulator, |
104 | 83 | AggregateUDF, |
105 | 84 | ScalarUDF, |
106 | | - TableFunction, |
107 | 85 | WindowUDF, |
108 | 86 | udaf, |
109 | 87 | udf, |
|
116 | 94 | __all__ = [ |
117 | 95 | "Accumulator", |
118 | 96 | "AggregateUDF", |
119 | | - "Catalog", |
120 | 97 | "CsvReadOptions", |
121 | | - "DFSchema", |
122 | 98 | "DataFrame", |
123 | | - "DataFrameWriteOptions", |
124 | | - "ExecutionPlan", |
125 | | - "ExplainFormat", |
126 | 99 | "Expr", |
127 | | - "InsertOp", |
128 | | - "LogicalPlan", |
129 | | - "Metric", |
130 | | - "MetricsSet", |
131 | | - "ParquetColumnOptions", |
132 | | - "ParquetWriterOptions", |
133 | | - "PhysicalPartitioning", |
134 | 100 | "RecordBatch", |
135 | | - "RecordBatchStream", |
136 | 101 | "RuntimeEnvBuilder", |
137 | | - "SQLOptions", |
138 | 102 | "ScalarUDF", |
139 | 103 | "SessionConfig", |
140 | 104 | "SessionContext", |
141 | 105 | "SessionExtensionComponents", |
142 | 106 | "Table", |
143 | | - "TableFunction", |
144 | | - "TableProviderFactory", |
145 | | - "TableProviderFactoryExportable", |
146 | | - "WindowFrame", |
147 | 107 | "WindowUDF", |
148 | | - "catalog", |
149 | 108 | "col", |
150 | 109 | "column", |
151 | | - "common", |
152 | 110 | "configure_formatter", |
153 | | - "expr", |
154 | | - "extensions", |
155 | 111 | "functions", |
156 | 112 | "ipc", |
157 | 113 | "lit", |
| 114 | + "lit_with_metadata", |
158 | 115 | "literal", |
| 116 | + "literal_with_metadata", |
159 | 117 | "object_store", |
160 | | - "options", |
161 | 118 | "read_avro", |
162 | 119 | "read_csv", |
163 | 120 | "read_json", |
|
170 | 127 | "unparser", |
171 | 128 | ] |
172 | 129 |
|
| 130 | +_DEPRECATED_ROOT_NAMES: dict[str, tuple[str, str]] = { |
| 131 | + # datafusion.dataframe |
| 132 | + "DataFrameWriteOptions": ("datafusion.dataframe", "DataFrameWriteOptions"), |
| 133 | + "ExplainFormat": ("datafusion.dataframe", "ExplainFormat"), |
| 134 | + "InsertOp": ("datafusion.dataframe", "InsertOp"), |
| 135 | + "ParquetColumnOptions": ("datafusion.dataframe", "ParquetColumnOptions"), |
| 136 | + "ParquetWriterOptions": ("datafusion.dataframe", "ParquetWriterOptions"), |
| 137 | + # datafusion.plan |
| 138 | + "ExecutionPlan": ("datafusion.plan", "ExecutionPlan"), |
| 139 | + "LogicalPlan": ("datafusion.plan", "LogicalPlan"), |
| 140 | + "Metric": ("datafusion.plan", "Metric"), |
| 141 | + "MetricsSet": ("datafusion.plan", "MetricsSet"), |
| 142 | + "PhysicalPartitioning": ("datafusion.plan", "PhysicalPartitioning"), |
| 143 | + # datafusion.catalog |
| 144 | + "Catalog": ("datafusion.catalog", "Catalog"), |
| 145 | + "TableProviderFactory": ("datafusion.catalog", "TableProviderFactory"), |
| 146 | + "TableProviderFactoryExportable": ( |
| 147 | + "datafusion.catalog", |
| 148 | + "TableProviderFactoryExportable", |
| 149 | + ), |
| 150 | + # datafusion.common |
| 151 | + "DFSchema": ("datafusion.common", "DFSchema"), |
| 152 | + # datafusion.expr |
| 153 | + "WindowFrame": ("datafusion.expr", "WindowFrame"), |
| 154 | + # datafusion.context |
| 155 | + "SQLOptions": ("datafusion.context", "SQLOptions"), |
| 156 | + # datafusion.record_batch |
| 157 | + "RecordBatchStream": ("datafusion.record_batch", "RecordBatchStream"), |
| 158 | + # datafusion.user_defined |
| 159 | + "TableFunction": ("datafusion.user_defined", "TableFunction"), |
| 160 | +} |
| 161 | + |
| 162 | +_SUBMODULES: set[str] = { |
| 163 | + "catalog", |
| 164 | + "col", |
| 165 | + "common", |
| 166 | + "context", |
| 167 | + "dataframe", |
| 168 | + "dataframe_formatter", |
| 169 | + "expr", |
| 170 | + "extensions", |
| 171 | + "functions", |
| 172 | + "input", |
| 173 | + "io", |
| 174 | + "ipc", |
| 175 | + "object_store", |
| 176 | + "options", |
| 177 | + "plan", |
| 178 | + "record_batch", |
| 179 | + "substrait", |
| 180 | + "unparser", |
| 181 | + "user_defined", |
| 182 | +} |
| 183 | + |
| 184 | + |
| 185 | +def __getattr__(name: str) -> Any: |
| 186 | + if name in _DEPRECATED_ROOT_NAMES: |
| 187 | + module_path, target_name = _DEPRECATED_ROOT_NAMES[name] |
| 188 | + warnings.warn( |
| 189 | + f"`datafusion.{name}` is deprecated and will be removed in a future " |
| 190 | + f"release. Import `{target_name}` from `{module_path}` instead.", |
| 191 | + category=DeprecationWarning, |
| 192 | + stacklevel=2, |
| 193 | + ) |
| 194 | + module = importlib.import_module(module_path) |
| 195 | + return getattr(module, target_name) |
| 196 | + if name in _SUBMODULES: |
| 197 | + return importlib.import_module(f".{name}", __name__) |
| 198 | + msg = f"module '{__name__}' has no attribute '{name}'" |
| 199 | + raise AttributeError(msg) |
| 200 | + |
| 201 | + |
| 202 | +def __dir__() -> list[str]: |
| 203 | + return sorted(__all__) |
| 204 | + |
173 | 205 |
|
174 | 206 | def literal(value: Any) -> Expr: |
175 | 207 | """Create a literal expression.""" |
|
0 commit comments