Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable Function Registry Failed to Work #53

Open
xinlifoobar opened this issue Jul 15, 2024 · 1 comment
Open

Enable Function Registry Failed to Work #53

xinlifoobar opened this issue Jul 15, 2024 · 1 comment

Comments

@xinlifoobar
Copy link
Contributor

xinlifoobar commented Jul 15, 2024

Hi, while working on some prototype code to use arrow-udf with datafusion, even after several attempts, the code seems not to work. I want to request assistants to see what I missed. Thanks.

My Cargo.toml

arrow-udf = { version="0.3.0", features = ["global_registry"] }

#[function("eq(boolean, boolean) -> boolean")]
fn eq(lhs: bool, rhs: bool) -> bool {
    lhs == rhs
}

#[test]
fn test_eq() {
let bool_field = Field::new("", arrow::datatypes::DataType::Boolean, false);
let schema = Schema::new(vec![bool_field.clone()]);
let record_batch = RecordBatch::try_new(
    Arc::new(schema),
    vec![Arc::new(BooleanArray::from(vec![true, false, true]))],
)
.unwrap();

println!("Function signatures:");
REGISTRY.iter().for_each(|sig| {
    println!("{:?}", sig.name);
    println!("{:?}", sig.arg_types);
    println!("{:?}", sig.return_type);
});

let eval_eq_boolean = REGISTRY
    .get("eq", &[bool_field.clone(), bool_field.clone()], &bool_field)
    .unwrap()
    .function
    .as_scalar()
    .unwrap();

let result = eval_eq_boolean(&record_batch).unwrap();

assert!(result
    .column(0)
    .as_any()
    .downcast_ref::<BooleanArray>()
    .unwrap()
    .value(0));
}

Expected Behavior:

The code should print all functions in the registry and execute upon the record batch.

Actual behavior:

Output nothing and panic on unwrap.

Full code here: https://github.com/xinlifoobar/datafusion/pull/3/files#diff-80f6fc619b413359395ea967b66300724888683350eb23c1a9268ee095761903

@xinlifoobar
Copy link
Contributor Author

I resolved this by adding an additional feature to the crate. I'm still curious about why we need to define this as a calling package...

global_registry = [
    "arrow-udf"
]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant