apache / apache/pinot

[Feature] Support dynamic return type in function such as CAST

Open
#8,610 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
6.1k
Forks
1.5k
Avg merge
1d 21h
Merged PRs (30d)
189

Description

Background
===
Following #8597 to support argument-type-based function lookup, it is possible that argument types themselves is not sufficient to determine the result type, for example `CAST(intCol AS 'long')` and `CAST(intCol AS 'int')` will have the same argument types `int, string` but different return type `long` vs. `int`.

Proposal
===
Propose to allow annotation of `@ScalarFunction` to annotate classes which have various function/method name, signature, class will look like this
```
@ScalarFunction(name = 'cast')
public class CastFunction implements FunctionDefinition {

@Override
public Method getMethod(Collection argumentType, Collection literalArguments) {
// ...
}

// actual function methods:
public int castToInt(Object o, String literalCastType) { // ... }
public long castToLong(Object o , String literalCastType) { // ... }
}
```
Similar architecture is adopted in many sql-like systems to support UDF/UDAF/UDTF etc. thus I think the design should be sufficient.

Note
====
* type inference is not discussed in this document
* whether to use codegen or hand-written method is up for discussion.

Contributor guide

Open the contributing guide

Research direction

Start by reviewing the argument-type-based function lookup from #8597 and the @ScalarFunction and FunctionDefinition entry points described here. Clarify how literal arguments affect return-type inference for CAST, then resolve whether the design uses code generation or hand-written methods. Done means the dynamic return-type architecture and inference behavior are specified and implemented.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
databases
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.