Skip to content

Commit

Permalink
Make Ballista API compact
Browse files Browse the repository at this point in the history
  • Loading branch information
milenkovicm committed Nov 27, 2024
1 parent 2e7ab1c commit eb83ece
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 15 deletions.
4 changes: 2 additions & 2 deletions python/ballista/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@
import pyarrow as pa

from .ballista_internal import (
BallistaBuilder,
Ballista,
)

__version__ = importlib_metadata.version(__name__)

__all__ = [
"BallistaBuilder",
"Ballista",
]
6 changes: 2 additions & 4 deletions python/examples/example.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,10 @@

# %%

from ballista import BallistaBuilder
from ballista import Ballista
from datafusion.context import SessionContext

# Ballista will initiate with an empty config
# set config variables with `config`
ctx: SessionContext = BallistaBuilder()\
ctx: SessionContext = Ballista.builder\
.config("ballista.job.name", "example ballista")\
.config("datafusion.execution.target_partitions", "4")\
.standalone()
Expand Down
29 changes: 29 additions & 0 deletions python/examples/experiment.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# 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
from datafusion.context import SessionContext

ctx: SessionContext = Ballista.builder\
.config("ballista.job.name", "example ballista")\
.config("datafusion.execution.target_partitions", "4")\
.standalone()

ctx.sql("SELECT 1").show()
# %%
5 changes: 3 additions & 2 deletions python/examples/readme.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,14 @@

# %%

from ballista import BallistaBuilder
from ballista import Ballista
from datafusion.context import SessionContext

ctx: SessionContext = BallistaBuilder()\
ctx: SessionContext = Ballista.builder\
.config("ballista.job.name", "Readme Examples")\
.config("datafusion.execution.target_partitions", "4")\
.standalone()

ctx.sql("create external table t stored as parquet location '../testdata/test.parquet'")

# %%
Expand Down
3 changes: 2 additions & 1 deletion python/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ classifier = [
"Programming Language :: Rust",
]
dependencies = [
"pyarrow>=11.0.0",
"pyarrow>=11.0.0",
"datafusion==42",
]

[project.urls]
Expand Down
15 changes: 9 additions & 6 deletions python/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ fn ballista_internal(_py: Python, m: Bound<'_, PyModule>) -> PyResult<()> {
// BallistaBuilder struct
m.add_class::<PyBallistaBuilder>()?;
// DataFusion struct
m.add_class::<datafusion_python::dataframe::PyDataFrame>()?;
// m.add_class::<datafusion_python::dataframe::PyDataFrame>()?;
Ok(())
}

// Ballista Builder will take a HasMap/Dict Cionfg
#[pyclass(name = "BallistaBuilder", module = "ballista", subclass)]
#[derive(Debug, Default)]
#[pyclass(name = "Ballista", module = "ballista", subclass)]
pub struct PyBallistaBuilder {
conf: HashMap<String, String>,
}
Expand All @@ -44,9 +44,12 @@ pub struct PyBallistaBuilder {
impl PyBallistaBuilder {
#[new]
pub fn new() -> Self {
Self {
conf: HashMap::new(),
}
Self::default()
}
//#[staticmethod]
#[classattr]
pub fn builder() -> Self {
Self::default()
}

pub fn config(
Expand Down

0 comments on commit eb83ece

Please sign in to comment.