andygrove commented on code in PR #2588: URL: https://github.com/apache/datafusion-ballista/pull/2588#discussion_r4303459452
########## python/src/config.rs: ########## @@ -0,0 +1,81 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +use ballista_core::config::BallistaConfig; +use datafusion::config::{ConfigExtension, ExtensionOptions}; +use datafusion_ffi::config::extension_options::FFI_ExtensionOptions; +use pyo3::exceptions::PyValueError; +use pyo3::prelude::*; +use pyo3::types::PyCapsule; +use std::collections::HashMap; + +/// Ballista configuration exposed as a DataFusion config extension, to be +/// registered with `SessionConfig.with_extension(...)`. +/// +/// Once registered, `ballista.*` keys are listed in +/// `information_schema.df_settings` and can be changed with `SET`. +#[pyclass( + name = "BallistaConfigExtension", + module = "ballista._internal_ballista", + skip_from_py_object +)] +pub(crate) struct PyBallistaConfigExtension { + config: BallistaConfig, +} + +#[pymethods] +impl PyBallistaConfigExtension { + #[new] + #[pyo3(signature = (settings=None))] + fn new(settings: Option<HashMap<String, String>>) -> PyResult<Self> { + let mut config = BallistaConfig::default(); + for (key, value) in settings.unwrap_or_default() { + let Some(inner_key) = key + .strip_prefix(BallistaConfig::PREFIX) + .and_then(|k| k.strip_prefix('.')) + else { + return Err(PyValueError::new_err(format!( + "unsupported Ballista configuration key: {key}" + ))); + }; + config + .set(inner_key, &value) + .map_err(|error| PyValueError::new_err(error.to_string()))?; + } + Ok(Self { config }) + } + + fn __datafusion_extension_options__<'py>( Review Comment: Thanks for checking. `job.name` and `force_remote_read` do reach the scheduler because they ride along in the settings list. `use_tls` and `pull` are different because `DistributedQueryExec::execute` reads them from `context.session_config().ballista_config()` (distributed_query.rs, around the `client_pull()` check and in `execute_query_pull`). That getter looks up a native `BallistaConfig` extension. After the FFI round trip the task context only holds an `FFI_ExtensionOptions`, so the lookup returns `None` and falls back to the defaults. I haven't run this against a TLS cluster, but a quick check would be `ctx.sql(...)` with `cluster_config={"ballista.client.use_tls": True}` against a plain-text scheduler. If the setting were honored it would fail to connect, and if it is ignored the query will succeed. Could `execute()` fall back to `self.config` when the context has no `BallistaConfig`? `self.config` is already restored from the plan settings in your codec, so it should have the right values. ########## ballista/core/src/serde/mod.rs: ########## @@ -1044,6 +1044,10 @@ impl PhysicalExtensionCodec for BallistaPhysicalExtensionCodec { input.clone(), )?)) } + PhysicalPlanType::DistributedQuery(_) => Err(DataFusionError::Internal( Review Comment: That makes sense, thanks for explaining. Keeping the tonic dependency out of the Python crate is a good reason, and the new variants are additive on the wire, so I'm fine with this as is. The reworded errors help too. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
