/** SQL SUBSTRING(binary FROM ...) function. */ public static ByteString substring(ByteString b, int from) { return b.substring(from - 1); }
/** Helper for CAST(... AS VARBINARY(maxLength)). */ public static ByteString truncate(ByteString s, int maxLength) { if (s == null) { return null; } else if (s.length() > maxLength) { return s.substring(0, maxLength); } else { return s; } }
/** Helper for CAST(... AS VARBINARY(maxLength)). */ public static ByteString truncate(ByteString s, int maxLength) { if (s == null) { return null; } else if (s.length() > maxLength) { return s.substring(0, maxLength); } else { return s; } }
/** * Returns a ByteString that starts at a given position. * * @param start Start of range * @return Substring */ public ByteString substring(int start) { return substring(start, length()); }
/** Helper for CAST(... AS VARBINARY(maxLength)). */ public static ByteString truncate(ByteString s, int maxLength) { if (s == null) { return null; } else if (s.length() > maxLength) { return s.substring(0, maxLength); } else { return s; } }
/** * Returns a ByteString that starts at a given position. * * @param start Start of range * @return Substring */ public ByteString substring(int start) { return substring(start, length()); }
/** * Returns a ByteString that starts at a given position. * * @param start Start of range * @return Substring */ public ByteString substring(int start) { return substring(start, length()); }
/** SQL SUBSTRING(binary FROM ... FOR ...) function. */ public static ByteString substring(ByteString b, int from, int for_) { return b.substring(from - 1, Math.min(from - 1 + for_, b.length())); }
/** Helper for CAST(... AS BINARY(maxLength)). */ public static ByteString truncateOrPad(ByteString s, int maxLength) { if (s == null) { return null; } else { final int length = s.length(); if (length > maxLength) { return s.substring(0, maxLength); } else if (length < maxLength) { return s.concat(new ByteString(new byte[maxLength - length])); } else { return s; } } }
/** Helper for CAST(... AS BINARY(maxLength)). */ public static ByteString truncateOrPad(ByteString s, int maxLength) { if (s == null) { return null; } else { final int length = s.length(); if (length > maxLength) { return s.substring(0, maxLength); } else if (length < maxLength) { return s.concat(new ByteString(new byte[maxLength - length])); } else { return s; } } }
/** SQL {@code POSITION(seek IN string FROM integer)} function for byte * strings. */ public static int position(ByteString seek, ByteString s, int from) { final int from0 = from - 1; if (from0 > s.length() || from0 < 0) { return 0; } // ByteString doesn't have indexOf(ByteString, int) until avatica-1.9 // (see [CALCITE-1423]), so apply substring and find from there. Bug.upgrade("in avatica-1.9, use ByteString.substring(ByteString, int)"); final int p = s.substring(from0).indexOf(seek); if (p < 0) { return 0; } return p + from; }
/** Helper for CAST(... AS BINARY(maxLength)). */ public static ByteString truncateOrPad(ByteString s, int maxLength) { if (s == null) { return null; } else { final int length = s.length(); if (length > maxLength) { return s.substring(0, maxLength); } else if (length < maxLength) { return s.concat(new ByteString(new byte[maxLength - length])); } else { return s; } } }
/** SQL {@code POSITION(seek IN string FROM integer)} function for byte * strings. */ public static int position(ByteString seek, ByteString s, int from) { final int from0 = from - 1; if (from0 > s.length() || from0 < 0) { return 0; } // ByteString doesn't have indexOf(ByteString, int) until avatica-1.9 // (see [CALCITE-1423]), so apply substring and find from there. Bug.upgrade("in avatica-1.9, use ByteString.substring(ByteString, int)"); final int p = s.substring(from0).indexOf(seek); if (p < 0) { return 0; } return p + from; }
/** SQL {@code POSITION(seek IN string FROM integer)} function for byte * strings. */ public static int position(ByteString seek, ByteString s, int from) { final int from0 = from - 1; if (from0 > s.length() || from0 < 0) { return 0; } // ByteString doesn't have indexOf(ByteString, int) until avatica-1.9 // (see [CALCITE-1423]), so apply substring and find from there. Bug.upgrade("in avatica-1.9, use ByteString.substring(ByteString, int)"); final int p = s.substring(from0).indexOf(seek); if (p < 0) { return 0; } return p + from; }