You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@datafusion.apache.org by "lyne7-sc (via GitHub)" <gi...@apache.org> on 2026/05/27 12:40:11 UTC

[PR] fix: LIKE 'prefix%' pruning fails on Utf8View and LargeUtf8 columns [datafusion]

lyne7-sc opened a new pull request, #22562:
URL: https://github.com/apache/datafusion/pull/22562

   ## Which issue does this PR close?
   
   <!--
   We generally require a GitHub issue to be filed for all bug fixes and enhancements and this helps us generate change logs for our releases. You can link an issue to this PR using the GitHub syntax. For example `Closes #123` indicates that this PR will close issue #123.
   -->
   
   - Closes #22561.
   
   ## Rationale for this change
   
   <!--
    Why are you proposing this change? If this is already explained clearly in the issue then this section is not needed.
    Explaining clearly why changes are proposed helps reviewers understand your changes and offer better suggestions for fixes.  
   -->
   
   LIKE 'prefix%' predicates on `Utf8View` and `LargeUtf8` columns produce `predicate_evaluation_errors`, causing row group and page index pruning to be skipped entirely.
   
   The cause is `build_like_match` always synthesizes bound literals as `ScalarValue::Utf8`, regardless of the actual column type. When the column is `Utf8View` or `LargeUtf8`, the subsequent comparison between the Utf8-typed bound and the min/max statistics (which use the column's native type) fails with a type mismatch error.
   
   ## What changes are included in this PR?
   
   <!--
   There is no need to duplicate the description in the issue here but it is sometimes worth providing a summary of the individual changes in this PR.
   -->
   
   - Updated `build_like_match` to use `string_literal_as` with the column's data_type() instead of hardcoding `ScalarValue::Utf8` for the lower/upper bound literals.
   - Added a regression test (prune_like_prefix) that verifies LIKE prefix pruning works correctly on UTF8 columns with expected row group statistics pruning and zero predicate errors.
   
   ## Are these changes tested?
   
   Yes.
   
   <!--
   We typically require tests for all PRs in order to:
   1. Prevent the code from being accidentally broken by subsequent changes
   2. Serve as another way to document the expected behavior of the code
   
   If tests are not included in your PR, please explain why (for example, are they covered by existing tests)?
   -->
   
   ## Are there any user-facing changes?
   
   No.
   
   <!--
   If there are user-facing changes then we may require documentation to be updated before approving the PR.
   -->
   
   <!--
   If there are any breaking changes to public APIs, please add the `api change` label.
   -->
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] fix: LIKE 'prefix%' pruning fails on Utf8View and LargeUtf8 columns [datafusion]

Posted by "lyne7-sc (via GitHub)" <gi...@apache.org>.
lyne7-sc commented on PR #22562:
URL: https://github.com/apache/datafusion/pull/22562#issuecomment-4560256938

   Thank you @alamb 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] fix: LIKE 'prefix%' pruning fails on Utf8View and LargeUtf8 columns [datafusion]

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on code in PR #22562:
URL: https://github.com/apache/datafusion/pull/22562#discussion_r3312274584


##########
datafusion/core/tests/parquet/row_group_pruning.rs:
##########
@@ -2078,3 +2078,26 @@ async fn test_limit_pruning_exceeds_fully_matched() -> datafusion_common::error:
         .await;
     Ok(())
 }
+
+#[tokio::test]
+async fn prune_like_prefix() {

Review Comment:
   I verified that this test fails like this without the code chnage
   
   ```
   thread 'parquet::row_group_pruning::prune_like_prefix' (83571793) panicked at datafusion/core/tests/parquet/row_group_pruning.rs:138:9:
   assertion `left == right` failed: mismatched predicate_evaluation error
     left: Some(5)
    right: Some(0)
   note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
   ```



##########
datafusion/pruning/src/pruning_predicate.rs:
##########
@@ -1816,6 +1817,13 @@ fn extract_string_literal(expr: &Arc<dyn PhysicalExpr>) -> Option<&str> {
     None
 }
 
+/// Wrap a string in a `Literal` whose `ScalarValue` matches `target_type`
+fn string_literal_as(value: String, target_type: &DataType) -> Arc<dyn PhysicalExpr> {
+    let utf8 = ScalarValue::Utf8(Some(value));
+    let scalar = try_cast_literal_to_type(&utf8, target_type).unwrap_or(utf8);

Review Comment:
   👍 
   
   It is sad that this potentially results in a new allocation -- maybe as a follow on PR we can avoid the allocation in `try_cast_literal_to_type`



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] fix: LIKE 'prefix%' pruning fails on Utf8View and LargeUtf8 columns [datafusion]

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb merged PR #22562:
URL: https://github.com/apache/datafusion/pull/22562


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org