Skip to content

feat: add VARBINARY type support #812

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

jcamachor
Copy link
Contributor

Substrait currently supports FIXEDBINARY and BINARY types. However, it does not support VARBINARY (BINARY VARYING), which is part of the ANSI SQL and supported by many other systems (SQL Server family, MySQL, Oracle, etc.)

This PR adds the VARBINARY type and corresponding literal to the spec.

@jacques-n
Copy link
Contributor

I'm supportive of this. Is their clear behavior when doing binary operations around length? I'm assuming a collection of functions will be coming after this? Have any examples?

@jcamachor
Copy link
Contributor Author

Thanks, @jacques-n . I was looking into this in more detail and I'm not sure truncation behavior will be consistent across engines. For example, in SQL Server, when converting to VARBINARY from other types, padding/truncation happens on either the left or right depending on the source type (see here). So maybe we shouldn't define trimming behavior in the docs and instead leave it to the function implementations? But CAST is a special function type, so we probably need to define some standard behavior. As for useful functions, bitwise operations, encoding/decoding (e.g., base64), and cryptographic (MD5, SHA-2) could be good candidates.

Copy link
Member

@vbarua vbarua left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The introduction of this type make sense to me. I'm happy to have this merged in by itself and then add functions that use them later.

One thing that we should do @jcamachor is define the https://substrait.io/extensions/#function-signature-compound-names for it.

@@ -35,6 +35,7 @@ Compound type classes are type classes that need to be configured by means of a
| FIXEDCHAR<L> | A fixed-length unicode string of L characters. L must be within [1..2,147,483,647]. | L-character `string`
| VARCHAR<L> | A unicode string of at most L characters.L must be within [1..2,147,483,647]. | `string` with at most L characters
| FIXEDBINARY<L> | A binary string of L bytes. When casting, values shorter than L are padded with zeros, and values longer than L are right-trimmed. | L-byte `bytes`
| VARBINARY<L> | A binary string of L bytes. L must be within [1..2,147,483,647]. When casting, values longer than L are right-trimmed. | byte `bytes` with at most L bytes
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea clarifying the CAST behaviour. As you point out, this can be system dependent.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants