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: add TO_BYTES/FROM_BYTES functions for bytes/string conversions #7831

Merged
merged 4 commits into from
Jul 21, 2021

Conversation

spena
Copy link
Member

@spena spena commented Jul 20, 2021

Description

Adds TO_BYTES and FROM_BYTES functions. Supported encodings are hex, ascii, utf8, and base64.

Testing done

Describe the testing strategy. Unit and integration tests are expected for any behavior changes.

Reviewer checklist

  • Ensure docs are updated if necessary. (eg. if a user visible feature is being added or changed).
  • Ensure relevant issues are linked (description should include text like "Fixes #")

@spena spena requested review from jzaralim and a team July 20, 2021 16:23
@spena spena requested a review from JimGalasyn as a code owner July 20, 2021 16:23
```

Converts a STRING column in the specified encoding type to a BYTES column.
Supported encoding types are: 'hex', 'utf8', 'ascii', 'base64'.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
Supported encoding types are: 'hex', 'utf8', 'ascii', 'base64'.
Supported encoding types are: `hex`, `utf8`, `ascii`, `base64`.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

Copy link
Member

@JimGalasyn JimGalasyn left a comment

Choose a reason for hiding this comment

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

LGTM, with a couple of suggestions.

@@ -35,7 +35,6 @@
* with your change. Otherwise, {@link PlannedTestsUpToDateTest} fill fail if there are missing
* or changed query plans.
*/
@Ignore("Comment me out to regenerate the historic plans")
Copy link
Contributor

Choose a reason for hiding this comment

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

Revert

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

@Udf(description = "Converts a BYTES value to STRING in the specified encoding. "
+ "The accepted encoders are 'hex', 'utf8', 'ascii', and 'base64'.")
public String fromBytes(final ByteBuffer value, final String encoding) {
return (value == null) ? null : BytesUtils.encode(value.array(), encoding);
Copy link
Contributor

Choose a reason for hiding this comment

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

The Protobuf deserializer deserializes to a read-only byte buffer, so value.array() might throw.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

import static org.hamcrest.Matchers.nullValue;
import static org.junit.Assert.assertThrows;

public class FromBytesTest {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we also have a test for an empty byte array?

Copy link
Member Author

Choose a reason for hiding this comment

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

Done


import java.nio.ByteBuffer;

public class ToBytesTest {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we also have a test for an empty string?

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

Copy link
Contributor

@jzaralim jzaralim left a comment

Choose a reason for hiding this comment

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

LGTM

@spena spena merged commit cea0989 into confluentinc:master Jul 21, 2021
@spena spena deleted the to_from_bytes branch July 21, 2021 01:04
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.

4 participants