Skip to content

HIVE-27370: support 4 bytes characters #5624

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 6 commits into
base: master
Choose a base branch
from

Conversation

ryukobayashi
Copy link
Contributor

What changes were proposed in this pull request?

If a SUBSTR UDF has a 4-byte characters in its parameter, the behavior is different between vectorized and non-vectorized. The vectorized version handles 4-byte characters properly, but the non-vectorized version does not, so similar logic is needed.
And these fixes use vectorized logic:
https://github.com/apache/hive/blob/master/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/StringSubstrColStartLen.java#L89-L130
https://github.com/apache/hive/blob/master/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/StringSubstrColStart.java#L78-L109

Why are the changes needed?

Vectorized and non-vectorized have different results.

Does this PR introduce any user-facing change?

No.

How was this patch tested?

Added pattern tests to itest for these to work correctly.

Copy link

@deniskuzZ
Copy link
Member

@difin, please take a look when you have time

@ryukobayashi
Copy link
Contributor Author

@deniskuzZ Sorry, I also overlooked this comments. I fixed it.

Copy link

return b;
}

private int craetePos(int pos) {
Copy link
Member

@deniskuzZ deniskuzZ Jun 21, 2025

Choose a reason for hiding this comment

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

typo: createPos(), maybe better rename to adjustStartPos()

}

@Override
public StatEstimator getStatEstimator() {
return new SubStrStatEstimator();
}

private byte[] arrayCopy(byte[] src, int pos, int len) {
Copy link
Member

Choose a reason for hiding this comment

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

can you use Arrays.copyOfRange(T[] original, int from, int to) ?

if (len <= 0) {
return new BytesWritable();
}

int[] index = makeIndex(pos, len, bw.getLength());
if (index == null) {
byte[] b = Arrays.copyOf(bw.getBytes(), bw.getLength());
Copy link
Member

Choose a reason for hiding this comment

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

why do we need to create copy of bw?

}

private BytesWritable evaluateInternal(BytesWritable bw, int pos) {
byte[] b = Arrays.copyOf(bw.getBytes(), bw.getLength());
Copy link
Member

Choose a reason for hiding this comment

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

same, why do we need copy?

}

private final IntWritable maxValue = new IntWritable(Integer.MAX_VALUE);

// Even though we are using longs, substr can only deal with ints, so we use
Copy link
Member

@deniskuzZ deniskuzZ Jun 21, 2025

Choose a reason for hiding this comment

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

please keep this comment where you check the range

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

Successfully merging this pull request may close these issues.

3 participants