tbar4 commented on code in PR #1100:
URL: 
https://github.com/apache/datafusion-ballista/pull/1100#discussion_r1844733616


##########
python/src/lib.rs:
##########
@@ -15,18 +15,189 @@
 // specific language governing permissions and limitations
 // under the License.
 
+use ballista::prelude::*;
+use datafusion_python::context::PySessionContext as 
DataFusionPythonSessionContext;
+use datafusion_python::utils::wait_for_future;
+
+use std::collections::HashMap;
+
 use pyo3::prelude::*;
-pub mod context;
 mod utils;
-
-pub use crate::context::PySessionContext;
+use utils::to_pyerr;
 
 #[pymodule]
-fn pyballista_internal(_py: Python, m: Bound<'_, PyModule>) -> PyResult<()> {
+fn ballista_internal(_py: Python, m: Bound<'_, PyModule>) -> PyResult<()> {
     pyo3_log::init();
     // Ballista structs
-    m.add_class::<PySessionContext>()?;
+    m.add_class::<PyBallista>()?;
+    m.add_class::<PyBallistaBuilder>()?;
     // DataFusion structs
     m.add_class::<datafusion_python::dataframe::PyDataFrame>()?;
+    // Ballista Config
+    /*
+    // Future implementation will include more state and config options
+    m.add_class::<PySessionStateBuilder>()?;
+    m.add_class::<PySessionState>()?;
+    m.add_class::<PySessionConfig>()?;
+    */
     Ok(())
 }
+
+// Ballista Builder will take a HasMap/Dict Cionfg
+#[pyclass(name = "BallistaBuilder", module = "ballista", subclass)]
+pub struct PyBallistaBuilder {
+    conf: HashMap<String, String>,
+}
+
+#[pymethods]
+impl PyBallistaBuilder {
+    #[new]
+    pub fn new() -> Self {
+        Self { conf: HashMap::new() }
+    }
+
+    pub fn set(
+        mut slf: PyRefMut<'_, Self>,
+        k: &str,
+        v: &str,
+        py: Python,
+    ) -> PyResult<PyObject> {
+        slf.conf.insert(k.into(), v.into());
+
+        Ok(slf.into_py(py))
+    }
+
+    pub fn show_config(&self) {
+        println!("Ballista Config:");
+        for ele in self.conf.iter() {
+            println!("\t{}: {}", ele.0, ele.1)
+        }
+    }
+
+    pub fn build(slf: PyRef<'_, Self>) -> PyBallista {
+        PyBallista {
+            conf: PyBallistaBuilder {
+                conf: slf.conf.clone(),
+            },
+        }
+    }
+}
+
+#[pyclass(name = "Ballista", module = "ballista", subclass)]
+pub struct PyBallista {
+    pub conf: PyBallistaBuilder,
+}
+
+#[pymethods]
+impl PyBallista {
+    #[new]
+    pub fn new() -> Self {
+        Self {
+            conf: PyBallistaBuilder::new(),
+        }
+    }
+
+    pub fn show_config(&self) {
+        println!("Ballista Config:");
+        for ele in self.conf.conf.clone() {
+            println!("{:4}: {}", ele.0, ele.1)
+        }
+    }
+
+    /// Construct the standalone instance from the SessionContext
+    #[pyo3(signature = (concurrent_tasks = 4))]
+    pub fn standalone(
+        &self,
+        concurrent_tasks: usize,
+        py: Python,
+    ) -> PyResult<DataFusionPythonSessionContext> {
+        // Build the config
+        let config = 
&BallistaConfig::with_settings(self.conf.conf.clone()).unwrap();
+        // Define the SessionContext
+        let session_context = BallistaContext::standalone(&config, 
concurrent_tasks);
+        // SessionContext is an async function
+        let ctx = wait_for_future(py, session_context)
+            .map_err(to_pyerr)?
+            .context()
+            .clone();
+
+        // Convert the SessionContext into a Python SessionContext
+        Ok(ctx.into())
+    }
+
+    /// Construct the remote instance from the SessionContext
+    pub fn remote(
+        &self,
+        host: &str,
+        port: u16,
+        py: Python,
+    ) -> PyResult<DataFusionPythonSessionContext> {
+        // Build the config
+        let config = 
&BallistaConfig::with_settings(self.conf.conf.clone()).unwrap();
+        // Create the BallistaContext
+        let session_context = BallistaContext::remote(host, port, config);

Review Comment:
   using SessionContext now



##########
python/examples/example.py:
##########
@@ -0,0 +1,39 @@
+# 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.
+
+from ballista import Ballista, BallistaBuilder
+from datafusion.context import SessionContext
+
+# Ballista will initiate with an empty config
+# set config variables with `set()`
+ballista = BallistaBuilder()\
+    .set("ballista.job.name", "example ballista")\

Review Comment:
   changed to config



-- 
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: github-unsubscr...@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org
For additional commands, e-mail: github-h...@datafusion.apache.org

Reply via email to