Skip to content

Commit 55bbf7a

Browse files
committed
Simple Functions WIP
1 parent 25b2a92 commit 55bbf7a

28 files changed

+1398
-0
lines changed

Cargo.lock

Lines changed: 86 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ members = [
2323
"datafusion/catalog",
2424
"datafusion/catalog-listing",
2525
"datafusion/core",
26+
"datafusion/excalibur/lib",
27+
"datafusion/excalibur/macros",
2628
"datafusion/expr",
2729
"datafusion/expr-common",
2830
"datafusion/execution",
@@ -104,6 +106,8 @@ datafusion-common = { path = "datafusion/common", version = "45.0.0", default-fe
104106
datafusion-common-runtime = { path = "datafusion/common-runtime", version = "45.0.0" }
105107
datafusion-datasource = { path = "datafusion/datasource", version = "45.0.0", default-features = false }
106108
datafusion-doc = { path = "datafusion/doc", version = "45.0.0" }
109+
datafusion-excalibur = { path = "datafusion/excalibur/lib", version = "45.0.0" }
110+
datafusion-excalibur-macros = { path = "datafusion/excalibur/macros", version = "45.0.0" }
107111
datafusion-execution = { path = "datafusion/execution", version = "45.0.0" }
108112
datafusion-expr = { path = "datafusion/expr", version = "45.0.0" }
109113
datafusion-expr-common = { path = "datafusion/expr-common", version = "45.0.0" }

datafusion/excalibur/lib/Cargo.toml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
[package]
19+
name = "datafusion-excalibur"
20+
version = { workspace = true }
21+
edition = { workspace = true }
22+
homepage = { workspace = true }
23+
repository = { workspace = true }
24+
license = { workspace = true }
25+
authors = { workspace = true }
26+
rust-version = { workspace = true }
27+
28+
[lints]
29+
workspace = true
30+
31+
[dependencies]
32+
arrow = { workspace = true }
33+
datafusion-common = { workspace = true }
34+
datafusion-excalibur-macros = { workspace = true }
35+
datafusion-expr = { workspace = true }
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
//! Contract between the macro and the library
19+
20+
pub trait ExcaliburScalarUdf {
21+
// for example "my_function"
22+
const SQL_NAME: &'static str;
23+
24+
// for example 2 for my_function(a, b)
25+
const RUST_ARGUMENT_COUNT: u8;
26+
27+
// for example 2 for my_function(a, b). This currently needs to be te same as RUST_ARGUMENT_COUNT
28+
const SQL_ARGUMENT_COUNT: u8;
29+
30+
// for example
31+
// - (i32, (u64, ()) for my_function(a: i32, b: u64)
32+
// - (i32, (u64, ()) for my_function(a: i32, b: u64, out: &mut X)
33+
// excludes the out arg
34+
type ArgumentRustTypes;
35+
36+
// T for `&mut T` passed to the function or () is there is no out argument
37+
type OutArgRustType;
38+
39+
// for example i32 for my_function(..) -> i32
40+
type ReturnRustType;
41+
42+
fn invoke(
43+
regular_args: Self::ArgumentRustTypes,
44+
out_arg: &mut Self::OutArgRustType,
45+
) -> Self::ReturnRustType;
46+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
mod primitive;
19+
20+
use arrow::array::ArrayRef;
21+
use datafusion_common::Result;
22+
23+
pub trait ExFullResultType {
24+
type BuilderType: ExArrayBuilder;
25+
fn builder_with_capacity(number_rows: usize) -> Self::BuilderType;
26+
}
27+
28+
pub trait ExArrayBuilder {
29+
type OutArg;
30+
type Return;
31+
32+
fn get_out_arg(&mut self, position: usize) -> Self::OutArg;
33+
34+
fn append(&mut self, out_arg: Self::OutArg, fn_ret: Self::Return) -> Result<()>;
35+
36+
fn append_null(&mut self) -> Result<()>;
37+
38+
fn build(self) -> Result<ArrayRef>;
39+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
use crate::builder::{ExArrayBuilder, ExFullResultType};
19+
use arrow::array::{ArrayRef, PrimitiveBuilder};
20+
use arrow::datatypes::{ArrowPrimitiveType, Int64Type, UInt64Type};
21+
use datafusion_common::Result;
22+
use std::sync::Arc;
23+
24+
macro_rules! primitive_result_type {
25+
($native_type:ty, $arrow_primitive_type:ty) => {
26+
impl ExFullResultType for ((), $native_type) {
27+
type BuilderType = PrimitiveBuilder<$arrow_primitive_type>;
28+
29+
fn builder_with_capacity(number_rows: usize) -> Self::BuilderType {
30+
Self::BuilderType::with_capacity(number_rows)
31+
}
32+
}
33+
};
34+
}
35+
36+
primitive_result_type!(i64, Int64Type);
37+
primitive_result_type!(u64, UInt64Type);
38+
39+
impl<T> ExArrayBuilder for PrimitiveBuilder<T>
40+
where
41+
T: ArrowPrimitiveType,
42+
{
43+
type OutArg = ();
44+
type Return = T::Native;
45+
46+
fn get_out_arg(&mut self, _position: usize) {}
47+
48+
fn append(&mut self, _out_arg: (), fn_ret: T::Native) -> Result<()> {
49+
self.append_value(fn_ret);
50+
Ok(())
51+
}
52+
53+
fn append_null(&mut self) -> Result<()> {
54+
self.append_null();
55+
Ok(())
56+
}
57+
58+
fn build(mut self) -> Result<ArrayRef> {
59+
Ok(Arc::new(self.finish()))
60+
}
61+
}

0 commit comments

Comments
 (0)