Add INITCAP scalar function for string case transformation#17642
Add INITCAP scalar function for string case transformation#17642xiangfu0 merged 1 commit intoapache:masterfrom
Conversation
- Implements INITCAP function that converts the first letter of each word to uppercase and the rest to lowercase - Words are delimited by whitespace characters (space, tab, newline, etc.) - Handles edge cases: empty strings, single characters, multiple spaces, special characters - Includes comprehensive unit tests with 40+ test cases covering various scenarios - Follows existing code patterns and includes proper Javadoc documentation
178669c to
b1deb85
Compare
|
@xiangfu0 please review. |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #17642 +/- ##
=========================================
Coverage 63.20% 63.21%
Complexity 1499 1499
=========================================
Files 3173 3173
Lines 190257 190271 +14
Branches 29072 29075 +3
=========================================
+ Hits 120261 120285 +24
+ Misses 60662 60649 -13
- Partials 9334 9337 +3
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
@yashmayya @Jackie-Jiang @xiangfu0 please review |
|
@Jackie-Jiang please review. |
|
@xiangfu0 please review |
|
@Jackie-Jiang please review |
There was a problem hiding this comment.
Pull request overview
This PR adds the INITCAP scalar function to Apache Pinot's string function library, implementing a standard SQL function for title case transformation. The function capitalizes the first letter of each word (delimited by whitespace) and converts the rest to lowercase.
Changes:
- Implemented
initcap()method inStringFunctions.javawith comprehensive documentation - Added 40+ test cases covering edge cases, Unicode, special characters, and real-world examples
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| pinot-common/src/main/java/org/apache/pinot/common/function/scalar/StringFunctions.java | Adds the initcap() scalar function with proper @ScalarFunction annotation and Javadoc |
| pinot-common/src/test/java/org/apache/pinot/common/function/scalar/StringFunctionsTest.java | Adds comprehensive test suite with data provider for 40+ test cases covering various scenarios |
| if (input == null || input.isEmpty()) { | ||
| return input; | ||
| } | ||
|
|
There was a problem hiding this comment.
The null check is inconsistent with other string functions in this class (e.g., lower(), upper(), trim(), concat()). According to the codebase conventions, methods and parameters are non-null by default unless annotated with @Nullable. Consider removing the null check to maintain consistency. The isEmpty() check provides a minor optimization but is not strictly necessary since the loop would handle empty strings correctly.
| if (input == null || input.isEmpty()) { | |
| return input; | |
| } |
before :
Description
Adds the
INITCAPfunction to Apache Pinot's scalar function library. This is a standard SQL function that converts the first letter of each word to uppercase and the rest to lowercase.Changes
initcap()function inStringFunctions.javaExample Usage