public class BinaryStringDataUtil extends Object
BinaryStringData
.Modifier and Type | Field and Description |
---|---|
static BinaryStringData[] |
EMPTY_STRING_ARRAY |
static BinaryStringData |
FALSE_STRING |
static BinaryStringData |
NULL_STRING |
static BinaryStringData |
TRUE_STRING |
Constructor and Description |
---|
BinaryStringDataUtil() |
Modifier and Type | Method and Description |
---|---|
static BinaryStringData |
concat(BinaryStringData... inputs)
Concatenates input strings together into a single string.
|
static BinaryStringData |
concat(Iterable<BinaryStringData> inputs) |
static BinaryStringData |
concatWs(BinaryStringData separator,
BinaryStringData... inputs)
Concatenates input strings together into a single string using the separator.
|
static BinaryStringData |
concatWs(BinaryStringData separator,
Iterable<BinaryStringData> inputs) |
static BinaryStringData |
hash(BinaryStringData str,
MessageDigest md)
Calculate the hash value of a given string use
MessageDigest . |
static BinaryStringData |
hash(BinaryStringData str,
String algorithm) |
static BinaryStringData |
hash(byte[] bytes,
MessageDigest md)
Calculate the hash value of the given bytes use
MessageDigest . |
static boolean |
isSpaceString(BinaryStringData str) |
static BinaryStringData |
keyValue(BinaryStringData str,
byte split1,
byte split2,
BinaryStringData keyName)
Parse target string as key-value string and return the value matches key name.
|
static BinaryStringData |
reverse(BinaryStringData str)
Reverse each character in current string.
|
static String |
safeToString(BinaryStringData str) |
static BinaryStringData[] |
splitByWholeSeparatorPreserveAllTokens(BinaryStringData str,
BinaryStringData separator)
Splits the provided text into an array, separator string specified.
|
static BinaryStringData |
substringSQL(BinaryStringData str,
int pos) |
static BinaryStringData |
substringSQL(BinaryStringData str,
int pos,
int length) |
static boolean |
toBoolean(BinaryStringData str)
Parse a
StringData to boolean. |
static byte |
toByte(BinaryStringData str) |
static int |
toDate(BinaryStringData input) |
static DecimalData |
toDecimal(BinaryStringData str,
int precision,
int scale)
Parses a
BinaryStringData to DecimalData . |
static double |
toDouble(BinaryStringData str) |
static float |
toFloat(BinaryStringData str) |
static int |
toInt(BinaryStringData str)
Parses this BinaryStringData to Int.
|
static long |
toLong(BinaryStringData str)
Parses this BinaryStringData to Long.
|
static short |
toShort(BinaryStringData str) |
static int |
toTime(BinaryStringData input) |
static TimestampData |
toTimestamp(BinaryStringData input,
int precision)
Used by
CAST(x as TIMESTAMP) . |
static TimestampData |
toTimestamp(BinaryStringData input,
int precision,
TimeZone timeZone)
Used by
CAST(x as TIMESTAMP_LTZ) . |
static BinaryStringData |
trim(BinaryStringData str,
BinaryStringData trimStr)
Walk each character of current string from both ends, remove the character if it is in trim
string.
|
static BinaryStringData |
trim(BinaryStringData str,
boolean leading,
boolean trailing,
BinaryStringData seek) |
static BinaryStringData |
trimLeft(BinaryStringData str) |
static BinaryStringData |
trimLeft(BinaryStringData str,
BinaryStringData trimStr)
Walk each character of current string from left end, remove the character if it is in trim
string.
|
static BinaryStringData |
trimRight(BinaryStringData str) |
static BinaryStringData |
trimRight(BinaryStringData str,
BinaryStringData trimStr)
Walk each character of current string from right end, remove the character if it is in trim
string.
|
public static final BinaryStringData NULL_STRING
public static final BinaryStringData TRUE_STRING
public static final BinaryStringData FALSE_STRING
public static final BinaryStringData[] EMPTY_STRING_ARRAY
public static BinaryStringData[] splitByWholeSeparatorPreserveAllTokens(BinaryStringData str, BinaryStringData separator)
The separator is not included in the returned String array. Adjacent separators are treated as separators for empty tokens.
A null
separator splits on whitespace.
"".splitByWholeSeparatorPreserveAllTokens(*) = [] "ab de fg".splitByWholeSeparatorPreserveAllTokens(null) = ["ab", "de", "fg"] "ab de fg".splitByWholeSeparatorPreserveAllTokens(null) = ["ab", "", "", "de", "fg"] "ab:cd:ef".splitByWholeSeparatorPreserveAllTokens(":") = ["ab", "cd", "ef"] "ab-!-cd-!-ef".splitByWholeSeparatorPreserveAllTokens("-!-") = ["ab", "cd", "ef"]
Note: returned binary strings reuse memory segments from the input str.
separator
- String containing the String to be used as a delimiter, null
splits
on whitespacenull
if null String was inputpublic static boolean toBoolean(BinaryStringData str) throws TableException
StringData
to boolean.TableException
public static BinaryStringData hash(byte[] bytes, MessageDigest md)
MessageDigest
.public static BinaryStringData hash(BinaryStringData str, MessageDigest md)
MessageDigest
.public static BinaryStringData hash(BinaryStringData str, String algorithm) throws NoSuchAlgorithmException
NoSuchAlgorithmException
public static DecimalData toDecimal(BinaryStringData str, int precision, int scale) throws NumberFormatException
BinaryStringData
to DecimalData
.NumberFormatException
public static long toLong(BinaryStringData str) throws NumberFormatException
Note that, in this method we accumulate the result in negative format, and convert it to positive format at the end, if this string is not started with '-'. This is because min value is bigger than max value in digits, e.g. Long.MAX_VALUE is '9223372036854775807' and Long.MIN_VALUE is '-9223372036854775808'.
This code is mostly copied from LazyLong.parseLong in Hive.
NumberFormatException
public static int toInt(BinaryStringData str) throws NumberFormatException
Note that, in this method we accumulate the result in negative format, and convert it to positive format at the end, if this string is not started with '-'. This is because min value is bigger than max value in digits, e.g. Integer.MAX_VALUE is '2147483647' and Integer.MIN_VALUE is '-2147483648'.
This code is mostly copied from LazyInt.parseInt in Hive.
Note that, this method is almost same as `toLong`, but we leave it duplicated for performance reasons, like Hive does.
NumberFormatException
public static short toShort(BinaryStringData str) throws NumberFormatException
NumberFormatException
public static byte toByte(BinaryStringData str) throws NumberFormatException
NumberFormatException
public static double toDouble(BinaryStringData str) throws NumberFormatException
NumberFormatException
public static float toFloat(BinaryStringData str) throws NumberFormatException
NumberFormatException
public static int toDate(BinaryStringData input) throws java.time.DateTimeException
java.time.DateTimeException
public static int toTime(BinaryStringData input) throws java.time.DateTimeException
java.time.DateTimeException
public static TimestampData toTimestamp(BinaryStringData input, int precision) throws java.time.DateTimeException
CAST(x as TIMESTAMP)
.java.time.DateTimeException
public static TimestampData toTimestamp(BinaryStringData input, int precision, TimeZone timeZone) throws java.time.DateTimeException
CAST(x as TIMESTAMP_LTZ)
.java.time.DateTimeException
public static BinaryStringData keyValue(BinaryStringData str, byte split1, byte split2, BinaryStringData keyName)
split1
- separator between key-value tuple.split2
- separator between key and value.keyName
- name of the key whose value you want return.public static BinaryStringData substringSQL(BinaryStringData str, int pos)
public static BinaryStringData substringSQL(BinaryStringData str, int pos, int length)
public static BinaryStringData concat(BinaryStringData... inputs)
public static BinaryStringData concat(Iterable<BinaryStringData> inputs)
public static BinaryStringData concatWs(BinaryStringData separator, BinaryStringData... inputs)
Note: CONCAT_WS() does not skip any empty strings, however it does skip any NULL values after the separator. For example, concat_ws(",", "a", null, "c") would yield "a,c".
public static BinaryStringData concatWs(BinaryStringData separator, Iterable<BinaryStringData> inputs)
public static BinaryStringData reverse(BinaryStringData str)
public static BinaryStringData trim(BinaryStringData str, BinaryStringData trimStr)
trimStr
- the trim stringpublic static BinaryStringData trimLeft(BinaryStringData str)
public static boolean isSpaceString(BinaryStringData str)
public static BinaryStringData trimLeft(BinaryStringData str, BinaryStringData trimStr)
trimStr
- the trim stringpublic static BinaryStringData trimRight(BinaryStringData str)
public static BinaryStringData trimRight(BinaryStringData str, BinaryStringData trimStr)
trimStr
- the trim stringpublic static BinaryStringData trim(BinaryStringData str, boolean leading, boolean trailing, BinaryStringData seek)
public static String safeToString(BinaryStringData str)
Copyright © 2014–2024 The Apache Software Foundation. All rights reserved.