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 18, 2025
1 parent 19fe44c commit a277aa0
Show file tree
Hide file tree
Showing 39 changed files with 3,228 additions and 0 deletions.
87 changes: 87 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
36 changes: 36 additions & 0 deletions datafusion/excalibur/lib/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# 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 }
datafusion-expr-common = { workspace = true }
47 changes: 47 additions & 0 deletions datafusion/excalibur/lib/src/arg_type.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// 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.

use crate::reader::ExArrayReaderConsumer;
use datafusion_common::types::NativeType;
use datafusion_common::Result;
use datafusion_expr::ColumnarValue;

pub trait ExInstantiable {
type StackType<'a>;
}

pub trait ExArgType: ExInstantiable {
fn logical_type() -> NativeType;

fn decode(
arg: ColumnarValue,
consumer: impl for<'a> ExArrayReaderConsumer<ValueType<'a> = Self::StackType<'a>>,
) -> Result<()>;
}

pub type FindExArgType<T> = <T as ExFindImplementation>::Type;

pub trait ExFindImplementation {
type Type: ExArgType;
}

impl<T> ExFindImplementation for T
where
T: ExArgType,
{
type Type = T;
}
43 changes: 43 additions & 0 deletions datafusion/excalibur/lib/src/arg_type_list.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// 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.

use crate::arg_type::ExArgType;
use datafusion_expr::TypeSignatureClass;
use std::sync::Arc;

pub trait ExArgTypeList {
fn type_signature() -> Vec<TypeSignatureClass>;
}

impl ExArgTypeList for () {
fn type_signature() -> Vec<TypeSignatureClass> {
vec![]
}
}

impl<Head, Tail> ExArgTypeList for (Head, Tail)
where
Head: ExArgType,
Tail: ExArgTypeList,
{
fn type_signature() -> Vec<TypeSignatureClass> {
let mut signature =
vec![TypeSignatureClass::Native(Arc::new(Head::logical_type()))];
signature.extend(Tail::type_signature());
signature
}
}
72 changes: 72 additions & 0 deletions datafusion/excalibur/lib/src/boolean.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
// 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.

use crate::builder::{ExArrayBuilder, ExFullResultType};
use crate::primitive_type;
use crate::reader::ExArrayReader;
use arrow::array::{Array, ArrayRef, BooleanArray, BooleanBuilder};
use arrow::datatypes::DataType;
use datafusion_common::cast::as_boolean_array;
use datafusion_common::Result;
use std::sync::Arc;

primitive_type!(bool, Boolean, BooleanArray, as_boolean_array);

impl<'a> ExArrayReader<'a> for &'a BooleanArray {
type ValueType = bool;

fn is_valid(&self, position: usize) -> bool {
Array::is_valid(self, position)
}

fn get(&self, position: usize) -> Self::ValueType {
self.value(position)
}
}

impl ExFullResultType for ((), bool) {
type BuilderType = BooleanBuilder;

fn data_type() -> DataType {
DataType::Boolean
}

fn builder_with_capacity(number_rows: usize) -> Self::BuilderType {
Self::BuilderType::with_capacity(number_rows)
}
}

impl ExArrayBuilder for BooleanBuilder {
type OutArg = ();
type Return = bool;

fn get_out_arg(&mut self, _position: usize) -> Self::OutArg {}

fn append(&mut self, fn_ret: Self::Return) -> Result<()> {
self.append_value(fn_ret);
Ok(())
}

fn append_null(&mut self) -> Result<()> {
self.append_null();
Ok(())
}

fn build(mut self) -> Result<ArrayRef> {
Ok(Arc::new(self.finish()))
}
}
Loading

0 comments on commit a277aa0

Please sign in to comment.