You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@datafusion.apache.org by "Jefffrey (via GitHub)" <gi...@apache.org> on 2025/09/12 04:17:41 UTC

[PR] Introduce wildcard const for FixedSizeBinary type signature [datafusion]

Jefffrey opened a new pull request, #17531:
URL: https://github.com/apache/datafusion/pull/17531

   ## 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 #17291
   
   ## 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.  
   -->
   
   Currently not able to easily represent arbitrary sized `FixedSizeBinary`s in type signature API.
   
   ## 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.
   -->
   
   Introduce new `FIXED_SIZE_BINARY_WILDCARD` const that allows specifying type signatures which accept arbitrarily sized fixed size binary, similar to `FIXED_SIZE_LIST_WILDCARD`. Also modify `bitmap_count` signature to use this new signature.
   
   ## Are these changes tested?
   
   <!--
   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?
   
   <!--
   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] Introduce wildcard const for FixedSizeBinary type signature [datafusion]

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

   fyi @SparkApplicationMaster 


-- 
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] Introduce `TypeSignatureClass::Binary` to allow accepting arbitrarily sized `FixedSizeBinary` arguments [datafusion]

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


-- 
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] Introduce wildcard const for FixedSizeBinary type signature [datafusion]

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


##########
datafusion/expr-common/src/signature.rs:
##########
@@ -43,6 +43,13 @@ pub const TIMEZONE_WILDCARD: &str = "+TZ";
 /// valid length. It exists to avoid the need to enumerate all possible fixed size list lengths.
 pub const FIXED_SIZE_LIST_WILDCARD: i32 = i32::MIN;
 
+/// Constant that is used as a placeholder for any valid fixed size binary.
+/// This is used where a function can accept a fixed size binary type with any
+/// valid length. It exists to avoid the need to enumerate all possible fixed size binary lengths.
+///
+/// The value is offset by 1 to make it distinct from [`FIXED_SIZE_LIST_WILDCARD`].
+pub const FIXED_SIZE_BINARY_WILDCARD: i32 = i32::MIN + 1;

Review Comment:
   Just in case someone puts `FIXED_SIZE_LIST_WILDCARD` when they meant `FIXED_SIZE_BINARY_WILDCARD`, as otherwise they would be interchangeable



-- 
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] Introduce wildcard const for FixedSizeBinary type signature [datafusion]

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

   > I realized we may get away without introducing a generic type concept. The existing `TypeSignature::Coercible`'s `TypeSignatureClass` seems to be more or less it. did you try to use it?
   > 
   > cc @jayzhan211
   
   Let me take a look 👍 


-- 
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] Introduce wildcard const for FixedSizeBinary type signature [datafusion]

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

   I realized we may get away without introducing a generic type concept.
   The existing `TypeSignature::Coercible`'s `TypeSignatureClass` seems to be more or less it.
   did you try to use it?
   
   cc @jayzhan211 


-- 
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] Introduce wildcard const for FixedSizeBinary type signature [datafusion]

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


##########
datafusion/expr/src/type_coercion/functions.rs:
##########
@@ -913,6 +916,10 @@ fn coerced_from<'a>(
             Some(_) => Some(FixedSizeList(Arc::clone(f_into), *size_from)),
             _ => None,
         },
+        // should be able to coerce wildcard fixed size binary to non wildcard fixed size binary
+        (FixedSizeBinary(FIXED_SIZE_BINARY_WILDCARD), FixedSizeBinary(size_from)) => {

Review Comment:
   technically speaking, `FixedSizeBinary(-2147483647)` is not a valid type, so it's not meaningful to define a coercion between it and any other type. I can see how it may be useful in case of function signatures though. What we actually want is generic signatures in functions. i.e. a signature that is not a type itself, but matches a type.



##########
datafusion/expr-common/src/signature.rs:
##########
@@ -43,6 +43,13 @@ pub const TIMEZONE_WILDCARD: &str = "+TZ";
 /// valid length. It exists to avoid the need to enumerate all possible fixed size list lengths.
 pub const FIXED_SIZE_LIST_WILDCARD: i32 = i32::MIN;
 
+/// Constant that is used as a placeholder for any valid fixed size binary.
+/// This is used where a function can accept a fixed size binary type with any
+/// valid length. It exists to avoid the need to enumerate all possible fixed size binary lengths.
+///
+/// The value is offset by 1 to make it distinct from [`FIXED_SIZE_LIST_WILDCARD`].

Review Comment:
   Doesn't have to be different?



##########
datafusion/spark/src/function/bitmap/bitmap_count.rs:
##########
@@ -48,8 +49,16 @@ impl Default for BitmapCount {
 impl BitmapCount {
     pub fn new() -> Self {
         Self {
-            // TODO: add definitive TypeSignature after https://github.com/apache/datafusion/issues/17291 is done
-            signature: Signature::any(1, Volatility::Immutable),
+            signature: Signature::uniform(
+                1,
+                vec![
+                    Binary,
+                    BinaryView,
+                    LargeBinary,
+                    FixedSizeBinary(FIXED_SIZE_BINARY_WILDCARD),

Review Comment:
   Rather than use this invalid type hack, i'd recommend implementing this for now as a "user defined signature"
   
   long term solution is to have `Signature::uniform` accept generic types (type patterns).



-- 
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] Introduce wildcard const for FixedSizeBinary type signature [datafusion]

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

   > What we actually want is generic signatures in functions. i.e. a signature that is not a type itself, but matches a type.
   
   > long term solution is to have `Signature::uniform` accept generic types (type patterns).
   
   Do we have any tracking issues for these atm?


-- 
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] Introduce `TypeSignatureClass::Binary` to allow accepting arbitrarily sized `FixedSizeBinary` arguments [datafusion]

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

   @jayzhan211 @jayzhan-synnada PTAL


-- 
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] Introduce `TypeSignatureClass::Binary` to allow accepting arbitrarily sized `FixedSizeBinary` arguments [datafusion]

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

   Thanks @findepi & @jayzhan211 for the review :bow:


-- 
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] Introduce `TypeSignatureClass::Binary` to allow accepting arbitrarily sized `FixedSizeBinary` arguments [datafusion]

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

   I'll tag as API change since adding a new enum member


-- 
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] Introduce wildcard const for FixedSizeBinary type signature [datafusion]

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

   > I realized we may get away without introducing a generic type concept. The existing `TypeSignature::Coercible`'s `TypeSignatureClass` seems to be more or less it. did you try to use it?
   > 
   > cc @jayzhan211
   
   As it currently is I don't think it can support this case without modification. Types in `TypeSignatureClass` don't include anything for binary:
   
   https://github.com/apache/datafusion/blob/685f5d6c07868c8e47d6ffd11fb8134ca6aa405d/datafusion/expr-common/src/signature.rs#L259-L269
   
   In `NativeType`, `Binary` is a distinct type from `FixedSizeBinary` which still requires an explicit size:
   
   https://github.com/apache/datafusion/blob/685f5d6c07868c8e47d6ffd11fb8134ca6aa405d/datafusion/common/src/types/native.rs#L146-L150
   
   I suppose I could modify this `FixedSizeBinary` to make the size an `Option` where `None` represents "any" size, instead of doing this invalid negative size hack; would that be preferable?
   
   As an aside I believe decimal would have the same problem, in that it's not possible to define a signature that accepts decimals of any precision/scale unless you do it as user defined (numeric is possible but it's not limited to decimals only), so would be nice if we could solve that too 🤔 


-- 
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] Introduce `TypeSignatureClass::Binary` to allow accepting arbitrarily sized `FixedSizeBinary` arguments [datafusion]

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


##########
datafusion/spark/src/function/bitmap/bitmap_count.rs:
##########
@@ -48,8 +49,10 @@ impl Default for BitmapCount {
 impl BitmapCount {
     pub fn new() -> Self {
         Self {
-            // TODO: add definitive TypeSignature after https://github.com/apache/datafusion/issues/17291 is done
-            signature: Signature::any(1, Volatility::Immutable),
+            signature: Signature::coercible(
+                vec![Coercion::new_exact(TypeSignatureClass::Binary)],

Review Comment:
   👍 



-- 
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] Introduce `TypeSignatureClass::Binary` to allow accepting arbitrarily sized `FixedSizeBinary` arguments [datafusion]

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

   @findepi are these changes more in line with your thoughts?


-- 
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