Skip to content

lambda type coercion [Test - Do Not Review]#26192

Draft
Dilli-Babu-Godari wants to merge 1 commit intoprestodb:masterfrom
Dilli-Babu-Godari:coerc_fixes
Draft

lambda type coercion [Test - Do Not Review]#26192
Dilli-Babu-Godari wants to merge 1 commit intoprestodb:masterfrom
Dilli-Babu-Godari:coerc_fixes

Conversation

@Dilli-Babu-Godari
Copy link
Contributor

Description

Motivation and Context

Impact

Test Plan

Contributor checklist

  • Please make sure your submission complies with our contributing guide, in particular code style and commit standards.
  • PR description addresses the issue accurately and concisely. If the change is non-trivial, a GitHub Issue is referenced.
  • Documented new properties (with its default value), SQL syntax, functions, or other functionality.
  • If release notes are required, they follow the release notes guidelines.
  • Adequate tests were added if applicable.
  • CI passed.

Release Notes

Please follow release notes guidelines and fill in the release notes below.

== RELEASE NOTES ==

General Changes
* ... 
* ... 

Hive Connector Changes
* ... 
* ... 

If release note is NOT required, use:

== NO RELEASE NOTE ==

@prestodb-ci prestodb-ci added the from:IBM PR from IBM label Sep 30, 2025
@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Sep 30, 2025

Reviewer's Guide

Enhance lambda handling to support return type coercion during SQL function analysis: introduce exception handling for invalid lambda argument counts, normalize dependent function signature arguments, apply coercion to lambda return types when actual and expected types differ but are coercible, update the signature binder to allow coercion, and add corresponding tests for array_sort lambdas.

Class diagram for updated lambda handling in ExpressionAnalyzer

classDiagram
class ExpressionAnalyzer {
  +analyze(expression, baseScope, context)
  +process(expression, context)
  +addOrReplaceExpressionCoercion(expression, fromType, toType)
  +setExpressionType(expression, type)
}
class LambdaArgumentCountMismatchException {
  +LambdaArgumentCountMismatchException(Node node, String message)
}
ExpressionAnalyzer --> LambdaArgumentCountMismatchException : throws
Loading

Class diagram for SignatureBinder update to allow lambda return type coercion

classDiagram
class SignatureBinder {
  +update(BoundVariables.Builder bindings)
  -appendTypeRelationshipConstraintSolver(..., allowCoercion)
  -appendConstraintSolvers(..., allowCoercion)
}
SignatureBinder --> "TypeConstraintSolver"
Loading

File-Level Changes

Change Details Files
Catch invalid lambda argument counts and return UNKNOWN signature
  • Introduce LambdaArgumentCountMismatchException extending SemanticException
  • Wrap inner ExpressionAnalyzer setup/analyze block for lambdas in try/catch
  • Return UNKNOWN type signature when mismatch exception is thrown
presto-main-base/src/main/java/com/facebook/presto/sql/analyzer/ExpressionAnalyzer.java
Add coercion logic for lambda return types in ExpressionAnalyzer
  • After processing a lambda expression, detect if actual return type differs from expected
  • Verify if actual type can be coerced to expected and, if so, add or replace expression coercion on the lambda body
  • Update the expression’s inferred type to the expected function type
presto-main-base/src/main/java/com/facebook/presto/sql/analyzer/ExpressionAnalyzer.java
Normalize function signature arguments to handle lambda dependencies
  • Build a normalized argument list in resolveFunction
  • Treat null or dependent TypeSignatureProviders as UNKNOWN to prevent resolution errors
presto-main-base/src/main/java/com/facebook/presto/sql/analyzer/ExpressionAnalyzer.java
Allow coercion for lambda return types in SignatureBinder
  • Change appendTypeRelationshipConstraintSolver call to pass allowCoercion flag instead of always false
presto-main-base/src/main/java/com/facebook/presto/metadata/SignatureBinder.java
Add array_sort lambda return type coercion tests
  • Implement testArraySortLambdaReturnTypeCoercion with multiple assertFunction scenarios covering numeric, string, null, and mixed-type cases
presto-main-base/src/test/java/com/facebook/presto/type/TestArrayOperators.java

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@Dilli-Babu-Godari Dilli-Babu-Godari force-pushed the coerc_fixes branch 2 times, most recently from 36cc810 to f1986fc Compare October 1, 2025 08:58
@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Oct 1, 2025

CLA Signed

The committers listed above are authorized under a signed CLA.

  • ✅ login: Dilli-Babu-Godari / name: Dilli-Babu-Godari (b20a0ba)

@Dilli-Babu-Godari Dilli-Babu-Godari force-pushed the coerc_fixes branch 5 times, most recently from 30df2b5 to 95387f7 Compare October 6, 2025 05:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

from:IBM PR from IBM

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants