Skip to content

Add INITCAP scalar function for string case transformation#17642

Merged
xiangfu0 merged 1 commit intoapache:masterfrom
Akanksha-kedia:add-initcap-function
Feb 20, 2026
Merged

Add INITCAP scalar function for string case transformation#17642
xiangfu0 merged 1 commit intoapache:masterfrom
Akanksha-kedia:add-initcap-function

Conversation

@Akanksha-kedia
Copy link
Copy Markdown
Contributor

@Akanksha-kedia Akanksha-kedia commented Feb 5, 2026

before :

Screenshot 2026-02-05 at 6 09 06 PM

Description

Adds the INITCAP function 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

  • Implemented initcap() function in StringFunctions.java
  • Added comprehensive unit tests with 40+ test cases
  • Handles edge cases: empty strings, multiple spaces, special characters, Unicode

Example Usage

SELECT INITCAP('hello world') FROM myTable
-- Returns: 'Hello World'

- 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
@Akanksha-kedia
Copy link
Copy Markdown
Contributor Author

@xiangfu0 please review.

@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Feb 5, 2026

Codecov Report

❌ Patch coverage is 92.85714% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 63.21%. Comparing base (ca952da) to head (b1deb85).

Files with missing lines Patch % Lines
.../pinot/common/function/scalar/StringFunctions.java 92.85% 0 Missing and 1 partial ⚠️
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     
Flag Coverage Δ
custom-integration1 100.00% <ø> (ø)
integration 100.00% <ø> (ø)
integration1 100.00% <ø> (ø)
integration2 0.00% <ø> (ø)
java-11 63.18% <92.85%> (+0.01%) ⬆️
java-21 63.15% <92.85%> (-0.01%) ⬇️
temurin 63.21% <92.85%> (+<0.01%) ⬆️
unittests 63.21% <92.85%> (+<0.01%) ⬆️
unittests1 55.62% <92.85%> (+0.02%) ⬆️
unittests2 34.01% <0.00%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@Akanksha-kedia
Copy link
Copy Markdown
Contributor Author

@yashmayya @Jackie-Jiang @xiangfu0 please review

@Akanksha-kedia
Copy link
Copy Markdown
Contributor Author

@Jackie-Jiang please review.

@Akanksha-kedia
Copy link
Copy Markdown
Contributor Author

@xiangfu0 please review

@Akanksha-kedia
Copy link
Copy Markdown
Contributor Author

@Jackie-Jiang please review

@xiangfu0 xiangfu0 added the functions Related to scalar or aggregation functions label Feb 20, 2026
@xiangfu0 xiangfu0 merged commit 6d0eb45 into apache:master Feb 20, 2026
20 checks passed
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 in StringFunctions.java with 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

Comment on lines +86 to +89
if (input == null || input.isEmpty()) {
return input;
}

Copy link

Copilot AI Feb 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
if (input == null || input.isEmpty()) {
return input;
}

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

functions Related to scalar or aggregation functions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants