Skip to content

coalesce PPL function (Enhancement - Calcite) #4005

Closed

Description

@aalva500-prog

coalesce (Enhancement - Calcite)

1. Overview

Description

This RFC proposes enhancements to the existing PPL coalesce function to improve usability and compatibility. Currently, PPL coalesce enforces strict type matching and requires existing fields. The proposed enhancements include: automatic type coercion for mixed data types, support for non-existent fields, and empty field handling. These improvements will make coalesce more flexible while maintaining its core functionality of returning the first non-null value from a list of arguments.

Use Cases

  • Field normalization across different data sources (e.g., "clientip" vs "ipaddress")
  • Handling missing data with fallback values
  • Consolidating similar fields from different systems into a unified field

2. Final Syntax

source=<index> | eval <field>=coalesce(<field1>, <field2>, ..., <fieldN>)

Parameters

  • <field>: The output field name to store the coalesced result
  • <field1>, <field2>, ..., <fieldN>: Field names or literal values to evaluate in order
  • Supports mixed data types with automatic type coercion
  • Can include literal values as fallback options
  • Allows non-existent fields and empty field handling

Options

  • Mixed field names and literal values (no type constraints)
  • Support for all data types (string, numeric, etc.) with automatic coercion
  • Unlimited number of arguments
  • Support for empty fields (" ")
  • Support for non-existent/dummy fields

3. Usage Examples

Basic Usage

PPL> source=accounts | eval result = coalesce(employer, firstname, lastname) | fields result, firstname, lastname, employer

Advanced Usage

PPL> source=firewall | eval src_ip = coalesce(src_ip,sourceip,source_ip,sip,ip) | fields src_ip
PPL> source=logs | eval ip = coalesce(clientip, ipaddress, "unknown") | fields ip
PPL> source=data | eval result = coalesce(field1, 123, "fallback") | fields result

Best Practices

  • Use coalesce for field normalization before aggregation operations
  • Mix field names and literal values as needed with automatic type handling
  • Place literal fallback values at the end of the argument list
  • Leverage empty field support for comprehensive data handling

Optimization Notes

  • Place coalesce operations early in the query pipeline when possible to reduce processing overhead
  • Consider using coalesce for field normalization before aggregation operations

4. Implementation Details

Technical Approach

PPL coalesce will implement flexible type handling with automatic type coercion, allowing mixed data types across arguments. This approach prioritizes usability and compatibility while maintaining data integrity through intelligent type conversion.

Dependencies

  • Automatic type coercion system for mixed data types
  • Support for non-existent field handling
  • Empty field processing capabilities
  • Flexible error handling for enhanced compatibility

Testing Strategy

  • Test with mixed data types and automatic coercion
  • Test with non-existent fields to verify proper handling
  • Test with empty fields to ensure support
  • Test type coercion scenarios (string to numeric, etc.)
  • Performance testing with early pipeline placement

Activity

  1. changed the title [-]`coalesce` function (Enhancement)[/-] [+]`coalesce` PPL function (Enhancement)[/+] on Aug 7, 2025
  2. added
    PPL
    on Aug 8, 2025
  3. changed the title [-]`coalesce` PPL function (Enhancement)[/-] [+]`coalesce` PPL function (Enhancement - Calcite)[/+] on Aug 14, 2025
  4. aalva500-prog commented on Sep 2, 2025

    @aalva500-prog
    ContributorAuthor

    PR implementation has been merged.

  5. moved this from Not Started to Done in PPL Trackeron Sep 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

PPLenhancementv3.3.0

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions