Skip to content
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

feat: support UDT literals using bytestring/binary representation in calcite #232

Conversation

cheikhachraf
Copy link
Contributor

calcite does not accept RelDatatypes with sqltypename.OTHER and has no way of representing it as of now.
It will reject it at different steps such as RexLiteral Precondition type check or when building using the RexBuilder.

There's a ticket for this on Calcite's board but nothing as of of now.

one hacky solution would be:

  1. convert the substrait Expression.UDTLiteral into a VARBINARY/ByteString type. (the issue with this is that the Userdatatype.getsqlName would have to be set to sqlname.varbinary, otherwise the type check in calcite will fail)
  2. and then when converting back, just check if the RelDatatype inherits from our UserDataType and use that to do the conversion correctly.

@CLAassistant
Copy link

CLAassistant commented Feb 14, 2024

CLA assistant check
All committers have signed the CLA.

@cheikhachraf cheikhachraf changed the title [initial draft] feat: Using bytestring/binary representation for UDT literals in calcite [initial draft] feat: support UDT literals using bytestring/binary representation in calcite Feb 14, 2024
@vbarua
Copy link
Member

vbarua commented Feb 14, 2024

Thanks for working on this!

One thing I think would be helpful would be to add a full roundtrip test to verify that Substrait inputs with user-defined type literals can go from PROTO -> POJO -> CALCITE and back fully.

There's an example for testing user-defined types in CustomFunctionTest, it could make sense to add a test to this class (maybe with a rename) or make a new class.

There is code for something like this in assertFullRoundTrip(Rel pojo1), however that assumes that only standard extensions and functions are loaded (for now).

@vbarua vbarua marked this pull request as draft February 15, 2024 05:54
@vbarua vbarua changed the title [initial draft] feat: support UDT literals using bytestring/binary representation in calcite feat: support UDT literals using bytestring/binary representation in calcite Feb 15, 2024
@cheikhachraf cheikhachraf force-pushed the achraf.cheikhmohamed/add-support-for-udt=literals branch from 5b8f857 to 9329550 Compare February 16, 2024 15:01
@vbarua vbarua marked this pull request as ready for review February 16, 2024 22:33
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.

Nice work finding the REINTERPRET code in Calcite, that works really well for this ✨

Overall the changes look good. I did spruce things up a bit by:

  • Updating the test to include a check going from POJO -> PROTO -> POJO
  • Turned your comment into a docstring on the REINTERPRET converter to be able to link to the code in question.

var binaryLiteral = rexBuilder.makeBinaryLiteral(new ByteString(expr.value().toByteArray()));
return rexBuilder.makeReinterpretCast(
typeConverter.toCalcite(typeFactory, expr.getType()), binaryLiteral, null);
}
Copy link
Member

Choose a reason for hiding this comment

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

This works really well! We can store the binary data blob AND wrap it with the correct type ✨

@vbarua vbarua force-pushed the achraf.cheikhmohamed/add-support-for-udt=literals branch from 786a010 to fed5a7c Compare February 17, 2024 02:33
@vbarua
Copy link
Member

vbarua commented Feb 17, 2024

We've had enough activity this week for there to have been merge conflicts 😅
I rebased this PR off of the current main branch to deal with this.

@vbarua vbarua merged commit ca8187f into substrait-io:main Feb 17, 2024
7 of 8 checks passed
ajegou pushed a commit to ajegou/substrait-java that referenced this pull request Mar 29, 2024
substrait-java AND isthmus can now handle user-defined type literals
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