You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@datafusion.apache.org by "Chen-Yuan-Lai (via GitHub)" <gi...@apache.org> on 2025/02/22 15:08:15 UTC

[PR] refactor: use TypeSignature::Coercible for crypto functions [datafusion]

Chen-Yuan-Lai opened a new pull request, #14826:
URL: https://github.com/apache/datafusion/pull/14826

   ## 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 #14762 .
   
   ## 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.  
   -->
   
   ## 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.
   -->
   
   ## 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] refactor: use TypeSignature::Coercible for crypto functions [datafusion]

Posted by "Chen-Yuan-Lai (via GitHub)" <gi...@apache.org>.
Chen-Yuan-Lai commented on code in PR #14826:
URL: https://github.com/apache/datafusion/pull/14826#discussion_r2013574522


##########
datafusion/functions/src/crypto/basic.rs:
##########
@@ -328,6 +322,37 @@ impl DigestAlgorithm {
             }
         }
     }
+
+    pub fn digest_binary_array_impl<'a, BinaryArrType>(
+        self,
+        input_value: BinaryArrType,
+    ) -> ArrayRef
+    where
+        BinaryArrType: BinaryArrayType<'a>,
+    {
+        match self {
+            Self::Md5 => digest_to_array!(Md5, input_value),
+            Self::Sha224 => digest_to_array!(Sha224, input_value),
+            Self::Sha256 => digest_to_array!(Sha256, input_value),
+            Self::Sha384 => digest_to_array!(Sha384, input_value),
+            Self::Sha512 => digest_to_array!(Sha512, input_value),
+            Self::Blake2b => digest_to_array!(Blake2b512, input_value),
+            Self::Blake2s => digest_to_array!(Blake2s256, input_value),
+            Self::Blake3 => {
+                let binary_array: BinaryArray = input_value
+                    .iter()
+                    .map(|opt| {
+                        opt.map(|x| {
+                            let mut digest = Blake3::default();
+                            digest.update(x);
+                            Blake3::finalize(&digest).as_bytes().to_vec()
+                        })
+                    })
+                    .collect();
+                Arc::new(binary_array)
+            }
+        }
+    }

Review Comment:
   I found that these two array types don't share a common trait that would allow implementing a single generic function. Since the key difference is in how bytes are accessed, I'll keep these functions separate to maintain type safety.



-- 
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] refactor: use TypeSignature::Coercible for crypto functions [datafusion]

Posted by "Chen-Yuan-Lai (via GitHub)" <gi...@apache.org>.
Chen-Yuan-Lai commented on code in PR #14826:
URL: https://github.com/apache/datafusion/pull/14826#discussion_r1988897840


##########
datafusion/functions/src/crypto/sha512.rs:
##########
@@ -52,11 +56,16 @@ impl Default for SHA512Func {
 
 impl SHA512Func {
     pub fn new() -> Self {
-        use DataType::*;
         Self {
-            signature: Signature::uniform(
-                1,
-                vec![Utf8View, Utf8, LargeUtf8, Binary, LargeBinary],
+            signature: Signature::one_of(
+                vec![
+                    TypeSignature::Coercible(vec![Coercion::new_exact(

Review Comment:
   I met another error after I used new_`new_implicit` 😭 
   ```bash
   External error: query failed: DataFusion error: Arrow error: Compute error: Internal Error: Cannot cast BinaryView to BinaryArray of expected type
   [SQL] select sha512(ascii_1) from test_basic_operator;
   at test_files/string/./string_query.slt.part:1732
   at test_files/string/dictionary_utf8.slt:58
   ```
   
   I think the error came from `arrow-rs`
   https://github.com/apache/arrow-rs/blob/5b04ca7bf756c5ca9edfba220060017684e2ecc6/arrow-cast/src/cast/dictionary.rs#L107-#L128
   ```rust
   BinaryView => {
               // `unpack_dictionary` can handle Utf8View/BinaryView types, but incurs unnecessary data copy of the value buffer.
               // we handle it here to avoid the copy.
               let dict_array = array
                   .as_dictionary::<K>()
                   .downcast_dict::<BinaryArray>()
                   .ok_or_else(|| {
                       ArrowError::ComputeError(
                           "Internal Error: Cannot cast BinaryView to BinaryArray of expected type"
                               .to_string(),
                       )
                   })?;
   
               let binary_view = view_from_dict_values::<K, BinaryViewType, BinaryType>(
                   dict_array.values(),
                   dict_array.keys(),
               )?;
               Ok(Arc::new(binary_view))
           }
           _ => unpack_di
   ```
   
   When the dictionary is coverted to `BinaryView`, it can't be cast to `BinaryArray`



-- 
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] refactor: use TypeSignature::Coercible for crypto functions [datafusion]

Posted by "Chen-Yuan-Lai (via GitHub)" <gi...@apache.org>.
Chen-Yuan-Lai commented on code in PR #14826:
URL: https://github.com/apache/datafusion/pull/14826#discussion_r1988897840


##########
datafusion/functions/src/crypto/sha512.rs:
##########
@@ -52,11 +56,16 @@ impl Default for SHA512Func {
 
 impl SHA512Func {
     pub fn new() -> Self {
-        use DataType::*;
         Self {
-            signature: Signature::uniform(
-                1,
-                vec![Utf8View, Utf8, LargeUtf8, Binary, LargeBinary],
+            signature: Signature::one_of(
+                vec![
+                    TypeSignature::Coercible(vec![Coercion::new_exact(

Review Comment:
   I met another error after I used new_`new_implicit` 😭 
   ```
   External error: query failed: DataFusion error: Arrow error: Compute error: Internal Error: Cannot cast BinaryView to BinaryArray of expected type
   [SQL] select sha512(ascii_1) from test_basic_operator;
   at test_files/string/./string_query.slt.part:1732
   at test_files/string/dictionary_utf8.slt:58
   ```
   
   I think the error came from `arrow-rs`
   https://github.com/apache/arrow-rs/blob/5b04ca7bf756c5ca9edfba220060017684e2ecc6/arrow-cast/src/cast/dictionary.rs#L107-#L128
   ```rust
   BinaryView => {
               // `unpack_dictionary` can handle Utf8View/BinaryView types, but incurs unnecessary data copy of the value buffer.
               // we handle it here to avoid the copy.
               let dict_array = array
                   .as_dictionary::<K>()
                   .downcast_dict::<BinaryArray>()
                   .ok_or_else(|| {
                       ArrowError::ComputeError(
                           "Internal Error: Cannot cast BinaryView to BinaryArray of expected type"
                               .to_string(),
                       )
                   })?;
   
               let binary_view = view_from_dict_values::<K, BinaryViewType, BinaryType>(
                   dict_array.values(),
                   dict_array.keys(),
               )?;
               Ok(Arc::new(binary_view))
           }
           _ => unpack_di
   ```
   
   When the dictionary is coverted to `BinaryView`, it can't be cast to `BinaryArray`



-- 
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] refactor: use TypeSignature::Coercible for crypto functions [datafusion]

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


##########
datafusion/functions/src/crypto/basic.rs:
##########
@@ -342,22 +367,27 @@ pub fn digest_process(
             DataType::LargeBinary => {
                 digest_algorithm.digest_binary_array::<i64>(a.as_ref())
             }
-            other => exec_err!(
-                "Unsupported data type {other:?} for function {digest_algorithm}"
-            ),
-        },
-        ColumnarValue::Scalar(scalar) => match scalar {
-            ScalarValue::Utf8View(a)
-            | ScalarValue::Utf8(a)
-            | ScalarValue::LargeUtf8(a) => {
-                Ok(digest_algorithm
-                    .digest_scalar(a.as_ref().map(|s: &String| s.as_bytes())))
+            DataType::BinaryView => {
+                digest_algorithm.digest_binary_array::<i32>(a.as_ref())

Review Comment:
   should be i32



-- 
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] refactor: use TypeSignature::Coercible for crypto functions [datafusion]

Posted by "Chen-Yuan-Lai (via GitHub)" <gi...@apache.org>.
Chen-Yuan-Lai commented on PR #14826:
URL: https://github.com/apache/datafusion/pull/14826#issuecomment-2708900254

   > Hi @jayzhan211, It seems all the CI checks were passed (including sqlogicaltest), but when I created and printed a table by datafusion-cli , I got empty result
   > 
   > ```shell
   > DataFusion CLI v45.0.0
   > > CREATE TABLE t_source(
   >     column1 String,
   >     column2 String,
   >     column3 String,
   >     column4 String
   > ) AS VALUES
   > ('one', 'one', 'one', 'one'),
   > ('two', 'two', '', 'two'),
   > (NULL, NULL, NULL, NULL),
   > ('', '', '', ''),
   > ('three', 'three', 'three', '');
   > 
   > 0 row(s) fetched. 
   > Elapsed 0.005 seconds.
   > 
   > > select * from t_source;
   > +---------+---------+---------+---------+
   > | column1 | column2 | column3 | column4 |
   > +---------+---------+---------+---------+
   > +---------+---------+---------+---------+
   > 5 row(s) fetched. 
   > Elapsed 0.001 seconds.
   > ```
   > 
   > That is weird because I only modified the implementation of crypto functions. Why is the display for the basic operation is changed? Could you give me some help or suggestions? Thx!
   
   Oh! I found the problem is solved after I reinstall datafusion-cli 😆 


-- 
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] refactor: use TypeSignature::Coercible for crypto functions [datafusion]

Posted by "Chen-Yuan-Lai (via GitHub)" <gi...@apache.org>.
Chen-Yuan-Lai commented on PR #14826:
URL: https://github.com/apache/datafusion/pull/14826#issuecomment-2708661495

   Hi @jayzhan211, It seems all the CI checks were passed (including sqlogicaltest), but when I created and printed a table table by datafusion-cli , I got empty result
   
   ```bash
   DataFusion CLI v45.0.0
   > CREATE TABLE t_source(
       column1 String,
       column2 String,
       column3 String,
       column4 String
   ) AS VALUES
   ('one', 'one', 'one', 'one'),
   ('two', 'two', '', 'two'),
   (NULL, NULL, NULL, NULL),
   ('', '', '', ''),
   ('three', 'three', 'three', '');
   
   0 row(s) fetched. 
   Elapsed 0.005 seconds.
   
   > select * from t_source;
   +---------+---------+---------+---------+
   | column1 | column2 | column3 | column4 |
   +---------+---------+---------+---------+
   +---------+---------+---------+---------+
   5 row(s) fetched. 
   Elapsed 0.001 seconds.
   ``` 
   
   That is weird because I only modified the implementation of crypto functions. Why was the display for the basic operation was changed? Could you give me some help or suggestions? Thx!


-- 
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] refactor: use TypeSignature::Coercible for crypto functions [datafusion]

Posted by "Chen-Yuan-Lai (via GitHub)" <gi...@apache.org>.
Chen-Yuan-Lai commented on code in PR #14826:
URL: https://github.com/apache/datafusion/pull/14826#discussion_r1988897840


##########
datafusion/functions/src/crypto/sha512.rs:
##########
@@ -52,11 +56,16 @@ impl Default for SHA512Func {
 
 impl SHA512Func {
     pub fn new() -> Self {
-        use DataType::*;
         Self {
-            signature: Signature::uniform(
-                1,
-                vec![Utf8View, Utf8, LargeUtf8, Binary, LargeBinary],
+            signature: Signature::one_of(
+                vec![
+                    TypeSignature::Coercible(vec![Coercion::new_exact(

Review Comment:
   I met another error after I used `new_implicit` 😭 
   ```
   External error: query failed: DataFusion error: Arrow error: Compute error: Internal Error: Cannot cast BinaryView to BinaryArray of expected type
   [SQL] select sha512(ascii_1) from test_basic_operator;
   at test_files/string/./string_query.slt.part:1732
   at test_files/string/dictionary_utf8.slt:58
   ```
   
   I think the error came from `arrow-rs`
   https://github.com/apache/arrow-rs/blob/5b04ca7bf756c5ca9edfba220060017684e2ecc6/arrow-cast/src/cast/dictionary.rs#L107-#L128
   ```rust
   BinaryView => {
               // `unpack_dictionary` can handle Utf8View/BinaryView types, but incurs unnecessary data copy of the value buffer.
               // we handle it here to avoid the copy.
               let dict_array = array
                   .as_dictionary::<K>()
                   .downcast_dict::<BinaryArray>()
                   .ok_or_else(|| {
                       ArrowError::ComputeError(
                           "Internal Error: Cannot cast BinaryView to BinaryArray of expected type"
                               .to_string(),
                       )
                   })?;
   
               let binary_view = view_from_dict_values::<K, BinaryViewType, BinaryType>(
                   dict_array.values(),
                   dict_array.keys(),
               )?;
               Ok(Arc::new(binary_view))
           }
           _ => unpack_di
   ```
   
   When the dictionary is coverted to `BinaryView`, it can't be cast to `BinaryArray`



-- 
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] refactor: use TypeSignature::Coercible for crypto functions [datafusion]

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

   > [SQL] EXPLAIN SELECT
     digest(column1_utf8view, 'md5') as c
   FROM test;
   [Diff] (-expected|+actual)
       logical_plan
   -   01)Projection: digest(test.column1_utf8view, Utf8View("md5")) AS c
   +   01)Projection: digest(test.column1_utf8view, Utf8("md5")) AS c
       02)--TableScan: test projection=[column1_utf8view]
   
   This looks like an improvement, we don't need to cast it to utf8view


-- 
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] refactor: use TypeSignature::Coercible for crypto functions [datafusion]

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


##########
datafusion/functions/src/crypto/basic.rs:
##########
@@ -328,6 +322,37 @@ impl DigestAlgorithm {
             }
         }
     }
+
+    pub fn digest_binary_array_impl<'a, BinaryArrType>(
+        self,
+        input_value: BinaryArrType,
+    ) -> ArrayRef
+    where
+        BinaryArrType: BinaryArrayType<'a>,
+    {
+        match self {
+            Self::Md5 => digest_to_array!(Md5, input_value),
+            Self::Sha224 => digest_to_array!(Sha224, input_value),
+            Self::Sha256 => digest_to_array!(Sha256, input_value),
+            Self::Sha384 => digest_to_array!(Sha384, input_value),
+            Self::Sha512 => digest_to_array!(Sha512, input_value),
+            Self::Blake2b => digest_to_array!(Blake2b512, input_value),
+            Self::Blake2s => digest_to_array!(Blake2s256, input_value),
+            Self::Blake3 => {
+                let binary_array: BinaryArray = input_value
+                    .iter()
+                    .map(|opt| {
+                        opt.map(|x| {
+                            let mut digest = Blake3::default();
+                            digest.update(x);
+                            Blake3::finalize(&digest).as_bytes().to_vec()
+                        })
+                    })
+                    .collect();
+                Arc::new(binary_array)
+            }
+        }
+    }

Review Comment:
   It would be nice to



-- 
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] refactor: use TypeSignature::Coercible for crypto functions [datafusion]

Posted by "Chen-Yuan-Lai (via GitHub)" <gi...@apache.org>.
Chen-Yuan-Lai commented on code in PR #14826:
URL: https://github.com/apache/datafusion/pull/14826#discussion_r1986347452


##########
datafusion/functions/src/crypto/basic.rs:
##########
@@ -328,6 +322,37 @@ impl DigestAlgorithm {
             }
         }
     }
+
+    pub fn digest_binary_array_impl<'a, BinaryArrType>(
+        self,
+        input_value: BinaryArrType,
+    ) -> ArrayRef
+    where
+        BinaryArrType: BinaryArrayType<'a>,
+    {
+        match self {
+            Self::Md5 => digest_to_array!(Md5, input_value),
+            Self::Sha224 => digest_to_array!(Sha224, input_value),
+            Self::Sha256 => digest_to_array!(Sha256, input_value),
+            Self::Sha384 => digest_to_array!(Sha384, input_value),
+            Self::Sha512 => digest_to_array!(Sha512, input_value),
+            Self::Blake2b => digest_to_array!(Blake2b512, input_value),
+            Self::Blake2s => digest_to_array!(Blake2s256, input_value),
+            Self::Blake3 => {
+                let binary_array: BinaryArray = input_value
+                    .iter()
+                    .map(|opt| {
+                        opt.map(|x| {
+                            let mut digest = Blake3::default();
+                            digest.update(x);
+                            Blake3::finalize(&digest).as_bytes().to_vec()
+                        })
+                    })
+                    .collect();
+                Arc::new(binary_array)
+            }
+        }
+    }

Review Comment:
   I found that `digest_binary_array_impl` and `digest_utf8_array_impl` are similar, should we integrate them into one?



-- 
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] refactor: use TypeSignature::Coercible for crypto functions [datafusion]

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


##########
datafusion/sqllogictest/test_files/string/string_view.slt:
##########
@@ -1068,7 +1068,7 @@ EXPLAIN SELECT
 FROM test;
 ----
 logical_plan
-01)Projection: digest(test.column1_utf8view, Utf8View("md5")) AS c
+01)Projection: digest(test.column1_utf8view, Utf8("md5")) AS c

Review Comment:
   we avoid casting from utf8 to utf8view



##########
datafusion/sqllogictest/test_files/array.slt:
##########
@@ -6120,14 +6120,14 @@ physical_plan
 09)----------------LazyMemoryExec: partitions=1, batch_generators=[generate_series: start=1, end=100000, batch_size=8192]
 
 query I
-with test AS (SELECT substr(md5(i)::text, 1, 32) as needle FROM generate_series(1, 100000) t(i))
+with test AS (SELECT substr(md5(i::text)::text, 1, 32) as needle FROM generate_series(1, 100000) t(i))
 select count(*) from test WHERE array_has([needle], needle);
 ----
 100000
 
 # TODO: this should probably be possible to completely remove the filter as always true?
 query TT
-explain with test AS (SELECT substr(md5(i)::text, 1, 32) as needle FROM generate_series(1, 100000) t(i))
+explain with test AS (SELECT substr(md5(i::text)::text, 1, 32) as needle FROM generate_series(1, 100000) t(i))

Review Comment:
   md5(int64) is not supported, so the test is casted to string explicitly



-- 
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] refactor: use TypeSignature::Coercible for crypto functions [datafusion]

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

   CI appears to be failing, so marking this one as a draft


-- 
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] refactor: use TypeSignature::Coercible for crypto functions [datafusion]

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


-- 
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] refactor: use TypeSignature::Coercible for crypto functions [datafusion]

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

   you can mark it ready for review


-- 
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] refactor: use TypeSignature::Coercible for crypto functions [datafusion]

Posted by "Chen-Yuan-Lai (via GitHub)" <gi...@apache.org>.
Chen-Yuan-Lai commented on code in PR #14826:
URL: https://github.com/apache/datafusion/pull/14826#discussion_r1986346839


##########
datafusion/functions/src/crypto/basic.rs:
##########
@@ -342,22 +367,27 @@ pub fn digest_process(
             DataType::LargeBinary => {
                 digest_algorithm.digest_binary_array::<i64>(a.as_ref())
             }
-            other => exec_err!(
-                "Unsupported data type {other:?} for function {digest_algorithm}"
-            ),
-        },
-        ColumnarValue::Scalar(scalar) => match scalar {
-            ScalarValue::Utf8View(a)
-            | ScalarValue::Utf8(a)
-            | ScalarValue::LargeUtf8(a) => {
-                Ok(digest_algorithm
-                    .digest_scalar(a.as_ref().map(|s: &String| s.as_bytes())))
+            DataType::BinaryView => {
+                digest_algorithm.digest_binary_array::<i32>(a.as_ref())

Review Comment:
   I'm not sure if `i32` makes sense?



-- 
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] refactor: use TypeSignature::Coercible for crypto functions [datafusion]

Posted by "Chen-Yuan-Lai (via GitHub)" <gi...@apache.org>.
Chen-Yuan-Lai commented on PR #14826:
URL: https://github.com/apache/datafusion/pull/14826#issuecomment-2679115258

   Hi @jayzhan211, I encountered some CI failures in the `digest` function. It seems the `Exact(vec![Utf8View, Utf8View])` case can't be replaced with `TypeSignature::Coercible` because `TypeSignature::Coercible` processes each parameter independently, without considering the types of other parameters
   
   ```bash
   [SQL] EXPLAIN SELECT
     digest(column1_utf8view, 'md5') as c
   FROM test;
   [Diff] (-expected|+actual)
       logical_plan
   -   01)Projection: digest(test.column1_utf8view, Utf8View("md5")) AS c
   +   01)Projection: digest(test.column1_utf8view, Utf8("md5")) AS c
       02)--TableScan: test projection=[column1_utf8view]
   ```
   
   Should we:
   
   1. Implement a new `TypeSignature::Coercible` method to support this feature?
   2. Mixing the usage `TypeSignature::Coercible` and `Exact(vec![Utf8View, Utf8View])` in `digest` function?
   
   I'm not sure which one is better, could you give me some suggestions or other best practices? thanks very much!! 


-- 
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] refactor: use TypeSignature::Coercible for crypto functions [datafusion]

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


##########
datafusion/functions/src/crypto/sha512.rs:
##########
@@ -52,11 +56,16 @@ impl Default for SHA512Func {
 
 impl SHA512Func {
     pub fn new() -> Self {
-        use DataType::*;
         Self {
-            signature: Signature::uniform(
-                1,
-                vec![Utf8View, Utf8, LargeUtf8, Binary, LargeBinary],
+            signature: Signature::one_of(
+                vec![
+                    TypeSignature::Coercible(vec![Coercion::new_exact(

Review Comment:
   the return type is `utf8_or_binary_to_binary_type`
   which means the signtaure of sha512 should be new_implicit(binary, string|binary)
   
   Target is binary, and allowed source types are string and binary



-- 
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] refactor: use TypeSignature::Coercible for crypto functions [datafusion]

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


##########
datafusion/functions/src/crypto/sha512.rs:
##########
@@ -52,11 +56,16 @@ impl Default for SHA512Func {
 
 impl SHA512Func {
     pub fn new() -> Self {
-        use DataType::*;
         Self {
-            signature: Signature::uniform(
-                1,
-                vec![Utf8View, Utf8, LargeUtf8, Binary, LargeBinary],
+            signature: Signature::one_of(
+                vec![
+                    TypeSignature::Coercible(vec![Coercion::new_exact(

Review Comment:
   the return type is `utf8_or_binary_to_binary_type`
   which means the signtaure of sha512 should be new_implicit(binary, string|binary)



-- 
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] refactor: use TypeSignature::Coercible for crypto functions [datafusion]

Posted by "Chen-Yuan-Lai (via GitHub)" <gi...@apache.org>.
Chen-Yuan-Lai commented on PR #14826:
URL: https://github.com/apache/datafusion/pull/14826#issuecomment-2753751909

   @jayzhan211 I think the PR is ready to be reviewed :)


-- 
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] refactor: use TypeSignature::Coercible for crypto functions [datafusion]

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

   Thanks @Chen-Yuan-Lai 


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