Interface ScalarFunction
Mirrors DataFusion's ScalarUDFImpl trait. Wrap an instance in a ScalarUdf and
register it via SessionContext.registerUdf(ScalarUdf) to make it callable from SQL or
DataFrame plans.
Implementations may be invoked concurrently by DataFusion on multiple worker threads. If the implementation carries mutable state, the implementation must synchronize it.
-
Method Summary
Modifier and TypeMethodDescriptionList<org.apache.arrow.vector.types.pojo.Field>Declared argument fields, in positional order.evaluate(org.apache.arrow.memory.BufferAllocator allocator, ScalarFunctionArgs args) Compute the function result for one input batch.name()SQL name under which this function is invoked (e.g.,"add_one").org.apache.arrow.vector.types.pojo.FieldDeclared return field.Volatility classification.
-
Method Details
-
name
String name()SQL name under which this function is invoked (e.g.,"add_one"). -
argFields
List<org.apache.arrow.vector.types.pojo.Field> argFields()Declared argument fields, in positional order. The function is registered with an exact signature; calls whose argument types do not match exactly are rejected.Each entry is an Arrow
Field-- a name plus aFieldTypeplus an optional list of child fields. UseField.nullable(String, org.apache.arrow.vector.types.pojo.ArrowType)for primitive types (e.g.Field.nullable("arg0", new ArrowType.Int(32, true))). Nested types likeList,Struct, andMaprequire the children list to carry element / member / key / value type information; constructing aFieldvianew Field(name, FieldType, children)is the canonical Arrow way to do that. -
returnField
org.apache.arrow.vector.types.pojo.Field returnField()Declared return field. The returnedColumnarValue's vector must have this exact type, including any nested children. Same construction rules asargFields(). -
volatility
Volatility volatility()Volatility classification. UseVolatility.IMMUTABLEfor pure functions,Volatility.STABLEfor functions deterministic within a query, andVolatility.VOLATILEfor non-deterministic functions. -
evaluate
Compute the function result for one input batch.- Parameters:
allocator- theBufferAllocatorthat MUST be used for any new Arrow vector allocation, including the result. Buffers allocated from other allocators will not survive the JNI handoff.args- the per-argColumnarValues and the batch row count. EachColumnarValueis a read-only view; the implementation must NOT close its underlying vector.- Returns:
- a
ColumnarValueof the declared return type. IfColumnarValue.Array, the underlying vector must have lengthargs.rowCount(); ifColumnarValue.Scalar, length 1. Ownership of the returned vector transfers to the framework; the implementation must NOT close it.
-