|
1 | 1 | //! A compiled model's analysis outcomes as Rust data: views read their owner, records their fields. |
2 | 2 |
|
3 | | -use pyo3::prelude::{Bound, PyAny, PyAnyMethods, PyResult}; |
| 3 | +use pyo3::prelude::{Bound, PyAny, PyAnyMethods, PyResult, Python}; |
4 | 4 |
|
5 | 5 | use crate::bindings::_helpers::compile_driver::stage_work::{COMPILED_VIEW_FALLBACKS, count_stage}; |
6 | 6 | use crate::bindings::_helpers::compiled_views::compiled_model_view::{ |
@@ -252,3 +252,56 @@ pub(crate) fn name_object<'py>(model: &Bound<'py, PyAny>) -> PyResult<Bound<'py, |
252 | 252 | } |
253 | 253 | native_field(model, "name") |
254 | 254 | } |
| 255 | + |
| 256 | +/// The model's attached `SchemaModelEntry`, or `None`. |
| 257 | +pub(crate) fn schema_entry<'py>(model: &Bound<'py, PyAny>) -> PyResult<Bound<'py, PyAny>> { |
| 258 | + let py: Python<'py> = model.py(); |
| 259 | + if let Some(view) = native_model(model)? { |
| 260 | + return Ok(view.schema_entry(py)?.into_bound(py)); |
| 261 | + } |
| 262 | + native_field(model, "schema_entry") |
| 263 | +} |
| 264 | + |
| 265 | +/// The model's `CompileModelConfig`. |
| 266 | +pub(crate) fn config<'py>(model: &Bound<'py, PyAny>) -> PyResult<Bound<'py, PyAny>> { |
| 267 | + let py: Python<'py> = model.py(); |
| 268 | + if let Some(view) = native_model(model)? { |
| 269 | + return Ok(view.config(py)?.into_bound(py)); |
| 270 | + } |
| 271 | + native_field(model, "config") |
| 272 | +} |
| 273 | + |
| 274 | +/// The model's `CompileSqlReference` tuple. |
| 275 | +pub(crate) fn references<'py>(model: &Bound<'py, PyAny>) -> PyResult<Bound<'py, PyAny>> { |
| 276 | + let py: Python<'py> = model.py(); |
| 277 | + if let Some(view) = native_model(model)? { |
| 278 | + return Ok(view.references(py)?.into_bound(py).into_any()); |
| 279 | + } |
| 280 | + native_field(model, "references") |
| 281 | +} |
| 282 | + |
| 283 | +/// The model file's relative path. |
| 284 | +pub(crate) fn relative_path<'py>(model: &Bound<'py, PyAny>) -> PyResult<Bound<'py, PyAny>> { |
| 285 | + let py: Python<'py> = model.py(); |
| 286 | + if let Some(view) = native_model(model)? { |
| 287 | + return Ok(view.relative_path(py)?.into_bound(py)); |
| 288 | + } |
| 289 | + native_field(model, "relative_path") |
| 290 | +} |
| 291 | + |
| 292 | +/// The model's `InferredColumn` tuple, or `None`. |
| 293 | +pub(crate) fn inferred_columns<'py>(model: &Bound<'py, PyAny>) -> PyResult<Bound<'py, PyAny>> { |
| 294 | + let py: Python<'py> = model.py(); |
| 295 | + if let Some(view) = native_model(model)? { |
| 296 | + return Ok(view.inferred_columns(py)?.into_bound(py)); |
| 297 | + } |
| 298 | + native_field(model, "inferred_columns") |
| 299 | +} |
| 300 | + |
| 301 | +/// `(resource type, name)` of each dependency. |
| 302 | +pub(crate) fn dep_rows(model: &Bound<'_, PyAny>) -> PyResult<Vec<(String, String)>> { |
| 303 | + if let Some(view) = native_model(model)? { |
| 304 | + return view.dep_rows(model.py()); |
| 305 | + } |
| 306 | + native_field(model, "dep_rows")?.extract() |
| 307 | +} |
0 commit comments