Skip to content

Commit

Permalink
add a hleper function to list all sql functions
Browse files Browse the repository at this point in the history
  • Loading branch information
universalmind303 committed Sep 26, 2024
1 parent a5cb55d commit 94c72ca
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 3 deletions.
5 changes: 5 additions & 0 deletions daft/daft/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -1195,8 +1195,13 @@ def minhash(
ngram_size: int,
seed: int = 1,
) -> PyExpr: ...

# -----
# SQL functions
# -----
def sql(sql: str, catalog: PyCatalog, daft_planning_config: PyDaftPlanningConfig) -> LogicalPlanBuilder: ...
def sql_expr(sql: str) -> PyExpr: ...
def list_sql_functions() -> list[str]: ...
def utf8_count_matches(expr: PyExpr, patterns: PyExpr, whole_words: bool, case_sensitive: bool) -> PyExpr: ...
def to_struct(inputs: list[PyExpr]) -> PyExpr: ...

Expand Down
4 changes: 2 additions & 2 deletions src/daft-sql/src/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use crate::{
};

/// [SQL_FUNCTIONS] is a singleton that holds all the registered SQL functions.
static SQL_FUNCTIONS: Lazy<SQLFunctions> = Lazy::new(|| {
pub(crate) static SQL_FUNCTIONS: Lazy<SQLFunctions> = Lazy::new(|| {
let mut functions = SQLFunctions::new();
functions.register::<SQLModuleAggs>();
functions.register::<SQLModuleFloat>();
Expand Down Expand Up @@ -88,7 +88,7 @@ pub trait SQLFunction: Send + Sync {
/// - Use multimap for function variants.
/// - Add more functions..
pub struct SQLFunctions {
map: HashMap<String, Arc<dyn SQLFunction>>,
pub(crate) map: HashMap<String, Arc<dyn SQLFunction>>,
}

pub(crate) struct SQLFunctionArguments {
Expand Down
1 change: 1 addition & 0 deletions src/daft-sql/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ pub fn register_modules(parent: &Bound<PyModule>) -> PyResult<()> {
parent.add_class::<python::PyCatalog>()?;
parent.add_function(wrap_pyfunction_bound!(python::sql, parent)?)?;
parent.add_function(wrap_pyfunction_bound!(python::sql_expr, parent)?)?;
parent.add_function(wrap_pyfunction_bound!(python::list_sql_functions, parent)?)?;
Ok(())
}

Expand Down
7 changes: 6 additions & 1 deletion src/daft-sql/src/python.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use daft_dsl::python::PyExpr;
use daft_plan::{LogicalPlanBuilder, PyLogicalPlanBuilder};
use pyo3::prelude::*;

use crate::{catalog::SQLCatalog, planner::SQLPlanner};
use crate::{catalog::SQLCatalog, functions::SQL_FUNCTIONS, planner::SQLPlanner};

#[pyfunction]
pub fn sql(
Expand All @@ -22,6 +22,11 @@ pub fn sql_expr(sql: &str) -> PyResult<PyExpr> {
Ok(PyExpr { expr })
}

#[pyfunction]
pub fn list_sql_functions() -> Vec<String> {
SQL_FUNCTIONS.map.keys().cloned().collect()
}

/// PyCatalog is the Python interface to the Catalog.
#[pyclass(module = "daft.daft")]
#[derive(Debug, Clone)]
Expand Down

0 comments on commit 94c72ca

Please sign in to comment.