apache / apache/arrow

[C++][Gandiva] Duplicate function aliases with same parameters

Open
#49,985 0 comments 0 reactions 1 assignee Claimed by @lriggs View on GitHub
Component: Gandiva Type: bug
Dominant language
C++
Stars
17.1k
Forks
4.3k
Avg merge
3d 13h
Merged PRs (30d)
88

Description

### Describe the bug, including details regarding any error messages, version, and platform.

### Problem
It is possible to register different Gandiva functions with the same alias and parameters but different return types, resulting in confusing function overloads.

For example, **DATE_EXTRACTION_TRUNCATION_FNS** in [cpp/src/gandiva/function_registry_datetime.cc] was invoked twice with the same SQL alias lists — once for extract* (returns int64) and once for date_trunc_* (returns the input date/timestamp type):

```
DATE_EXTRACTION_TRUNCATION_FNS(EXTRACT_SAFE_NULL_IF_NULL, extract)
DATE_EXTRACTION_TRUNCATION_FNS(TRUNCATE_SAFE_NULL_IF_NULL, date_trunc_)
```
As a result the registry contained four entries for day(...) where there should have been two:
```
int64 day(timestamp) → extractDay_timestamp
int64 day(date) → extractDay_date64
timestamp day(timestamp) → date_trunc_Day_timestamp
date day(date) → date_trunc_Day_date64
```

The same problem existed for every calendar-unit alias: year, month, quarter, week, weekofyear, yearweek, dayofmonth, hour, minute, second. Resolution behavior depended on the caller's inferred return type, which is not the SQL semantics anyone expects from day(timestamp_col).

FunctionRegistry::Add was silently allowing these registrations: unordered_map::emplace keeps the first entry and discards subsequent ones with no warning.

### Component(s)

Gandiva

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.