Skip to content

Commit

Permalink
Simple Functions WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
findepi committed Feb 14, 2025
1 parent 7873e5c commit 58935e2
Show file tree
Hide file tree
Showing 30 changed files with 1,582 additions and 0 deletions.
86 changes: 86 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ members = [
"datafusion/catalog",
"datafusion/catalog-listing",
"datafusion/core",
"datafusion/excalibur/lib",
"datafusion/excalibur/macros",
"datafusion/expr",
"datafusion/expr-common",
"datafusion/execution",
Expand Down Expand Up @@ -104,6 +106,8 @@ datafusion-common = { path = "datafusion/common", version = "45.0.0", default-fe
datafusion-common-runtime = { path = "datafusion/common-runtime", version = "45.0.0" }
datafusion-datasource = { path = "datafusion/datasource", version = "45.0.0", default-features = false }
datafusion-doc = { path = "datafusion/doc", version = "45.0.0" }
datafusion-excalibur = { path = "datafusion/excalibur/lib", version = "45.0.0" }
datafusion-excalibur-macros = { path = "datafusion/excalibur/macros", version = "45.0.0" }
datafusion-execution = { path = "datafusion/execution", version = "45.0.0" }
datafusion-expr = { path = "datafusion/expr", version = "45.0.0" }
datafusion-expr-common = { path = "datafusion/expr-common", version = "45.0.0" }
Expand Down
35 changes: 35 additions & 0 deletions datafusion/excalibur/lib/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# 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.

[package]
name = "datafusion-excalibur"
version = { workspace = true }
edition = { workspace = true }
homepage = { workspace = true }
repository = { workspace = true }
license = { workspace = true }
authors = { workspace = true }
rust-version = { workspace = true }

[lints]
workspace = true

[dependencies]
arrow = { workspace = true }
datafusion-common = { workspace = true }
datafusion-excalibur-macros = { workspace = true }
datafusion-expr = { workspace = true }
42 changes: 42 additions & 0 deletions datafusion/excalibur/lib/src/bridge.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// 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.

//! Contract between the macro and the library
pub trait ExcaliburScalarUdf {
// for example "my_function"
const SQL_NAME: &'static str;
// for example 2 for my_function(a, b)
const RUST_ARGUMENT_COUNT: u8;
// for example 2 for my_function(a, b). This currently needs to be te same as RUST_ARGUMENT_COUNT
const SQL_ARGUMENT_COUNT: u8;

// for example
// - (i32, (u64, ()) for my_function(a: i32, b: u64)
// - (i32, (u64, ()) for my_function(a: i32, b: u64, out: &mut X)
// excludes the out arg
type ArgumentRustTypes;
// T for `&mut T` passed to the function or () is there is no out argument
type OutArgRustType;
// for example i32 for my_function(..) -> i32
type ReturnRustType;

fn invoke(
regular_args: Self::ArgumentRustTypes,
out_arg: &mut Self::OutArgRustType,
) -> Self::ReturnRustType;
}
41 changes: 41 additions & 0 deletions datafusion/excalibur/lib/src/builder/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// 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.

mod option;
mod primitive;
mod result;

use arrow::array::ArrayRef;
use datafusion_common::Result;

pub trait ExFullResultType {
type BuilderType: ExArrayBuilder;
fn builder_with_capacity(number_rows: usize) -> Self::BuilderType;
}

pub trait ExArrayBuilder {
type OutArg;
type Return;

fn get_out_arg(&mut self, position: usize) -> Self::OutArg;

fn append(&mut self, out_arg: Self::OutArg, fn_ret: Self::Return) -> Result<()>;

fn append_null(&mut self) -> Result<()>;

fn build(self) -> Result<ArrayRef>;
}
71 changes: 71 additions & 0 deletions datafusion/excalibur/lib/src/builder/option.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
// 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.

// impl<T> ExFullResultType for ((), Option<T>)
// where
// ((), T): ExFullResultType,
// {
// type BuilderType =
// ResultBuilderWithOptionSupport<<((), T) as ExFullResultType>::BuilderType>;
//
// fn builder_with_capacity(number_rows: usize) -> Self::BuilderType {
// Self::BuilderType {
// delegate: <((), T) as ExFullResultType>::builder_with_capacity(
// number_rows,
// ),
// }
// }
// }
//
// struct ResultBuilderWithOptionSupport<Delegate>
// where
// Delegate: ExArrayBuilder,
// {
// delegate: Delegate,
// }
//
// impl<Delegate> ExArrayBuilder for ResultBuilderWithOptionSupport<Delegate>
// where
// Delegate: ExArrayBuilder,
// {
// type OutArgRustType = Delegate::OutArgRustType;
// type ReturnRustType = Option<Delegate::ReturnRustType>;
//
// fn get_out_arg(&mut self, position: usize) -> Self::OutArgRustType {
// self.delegate.get_out_arg(position)
// }
//
// fn append(
// &mut self,
// out_arg: Self::OutArgRustType,
// fn_ret: Self::ReturnRustType,
// ) -> Result<()> {
// if fn_ret.is_some() {
// self.delegate.append(out_arg, fn_ret.unwrap())
// } else {
// self.append_null()
// }
// }
//
// fn append_null(&mut self) -> Result<()> {
// self.delegate.append_null()
// }
//
// fn build(self) -> Result<ArrayRef> {
// self.delegate.build()
// }
// }
Loading

0 comments on commit 58935e2

Please sign in to comment.