You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@datafusion.apache.org by "eddietejeda (via GitHub)" <gi...@apache.org> on 2026/08/29 03:32:30 UTC
[I] `octet_length` should accept binary types [datafusion]
eddietejeda opened a new issue, #24765:
URL: https://github.com/apache/datafusion/issues/24765
### Is your feature request related to a problem or challenge?
`octet_length` only accepts string types. When we use a binary column, the plan fails:
```text
Function 'octet_length' requires String, but received Binary (DataType: BinaryView)
```
A workaround for `SUM(octet_length(col))` over binary is:
```sql
SUM(length(encode(col, 'hex')) / 2)
```
But this materializes 2x the column's bytes just to count it.
### Describe the solution you'd like
Extend `octet_length` to natively accept `Binary`, `LargeBinary`, and `BinaryView`, returning the byte length.
- SQL:1999 defines `OCTET_LENGTH` for string values, including binary strings.
- PostgreSQL, DuckDB, Spark, MySQL, and SQLite accept binary values.
- `utf8_to_int_type` already maps `Binary -> Int32`, `LargeBinary -> Int64`, and `BinaryView -> Int32`.
We've implemented the solution internally and happy to submit PR.
`datafusion/functions/src/string/octet_length.rs`
Before:
```rust
impl OctetLengthFunc {
pub fn new() -> Self {
Self {
signature: Signature::coercible(
vec![
Coercion::new_exact(TypeSignatureClass::Native(logical_string()))
.with_encoding_preservation(EncodingPreservation::dictionary()),
],
Volatility::Immutable,
),
}
}
}
```
After: the two-branch string|binary select that `md5` uses:
```rust
impl OctetLengthFunc {
pub fn new() -> Self {
Self {
signature: Signature::one_of(
vec![
TypeSignature::Coercible(vec![
Coercion::new_exact(TypeSignatureClass::Native(logical_string()))
.with_encoding_preservation(
EncodingPreservation::dictionary(),
),
]),
TypeSignature::Coercible(vec![
Coercion::new_exact(TypeSignatureClass::Native(logical_binary()))
.with_encoding_preservation(
EncodingPreservation::dictionary(),
),
]),
],
Volatility::Immutable,
),
}
}
}
```
### Describe alternatives you've considered
```rust
length(encode(col, 'hex')) / 2 // works but doubles the data to count it
```
### Additional context
`bit_length` has the same gap and could be part in the same PR.
--
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.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: [I] `octet_length` should accept binary types [datafusion]
Posted by "getChan (via GitHub)" <gi...@apache.org>.
getChan commented on issue #24765:
URL: https://github.com/apache/datafusion/issues/24765#issuecomment-5467169043
Thanks for documenting this. `bit_length` has the same gap in DataFusion: it currently accepts string types but does not accept binary types (`Binary`, `LargeBinary`, and `BinaryView`).
SQL:1999 defines `BIT_LENGTH` for string values, including binary strings. We plan to implement similar native binary support for `bit_length`, following the same approach as the proposed `octet_length` change.
--
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: [I] `octet_length` should accept binary types [datafusion]
Posted by "comphead (via GitHub)" <gi...@apache.org>.
comphead closed issue #24765: `octet_length` should accept binary types
URL: https://github.com/apache/datafusion/issues/24765
--
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