Skip to content

Commit

Permalink
Merge pull request #14406 from rapidsai/branch-23.12
Browse files Browse the repository at this point in the history
Forward-merge branch-23.12 to branch-24.02
  • Loading branch information
raydouglass authored Nov 16, 2023
2 parents 6b4deeb + f9c586d commit 427390f
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion java/src/main/java/ai/rapids/cudf/ast/Literal.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.charset.StandardCharsets;

/** A literal value in an AST expression. */
public final class Literal extends AstExpression {
Expand Down Expand Up @@ -205,7 +206,14 @@ public static Literal ofString(String value) {
if (value == null) {
return ofNull(DType.STRING);
}
byte[] stringBytes = value.getBytes();
return ofUTF8String(value.getBytes(StandardCharsets.UTF_8));
}

/** Construct a string literal directly with byte array to skip transcoding. */
public static Literal ofUTF8String(byte[] stringBytes) {
if (stringBytes == null) {
return ofNull(DType.STRING);
}
byte[] serializedValue = new byte[stringBytes.length + Integer.BYTES];
ByteBuffer.wrap(serializedValue).order(ByteOrder.nativeOrder()).putInt(stringBytes.length);
System.arraycopy(stringBytes, 0, serializedValue, Integer.BYTES, stringBytes.length);
Expand Down

0 comments on commit 427390f

Please sign in to comment.