/** 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 ...) function. */ public static ByteString substring(ByteString c, int s) { return substring(c, s, c.length() + 1); }
/** SQL SUBSTRING(binary FROM ...) function. */ public static ByteString substring(ByteString c, int s) { return substring(c, s, c.length() + 1); }
/** 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())); }
/** Returns a byte-string padded with zero bytes to make it at least a given * length, */ private static ByteString padRight(ByteString s, int length) { if (s.length() >= length) { return s; } return new ByteString(Arrays.copyOf(s.getBytes(), length)); } }
/** Returns a byte-string padded with zero bytes to make it at least a given * length, */ private static ByteString padRight(ByteString s, int length) { if (s.length() >= length) { return s; } return new ByteString(Arrays.copyOf(s.getBytes(), length)); } }
/** * Creates a byte array literal. */ public RexLiteral makeBinaryLiteral(ByteString byteString) { return makeLiteral( byteString, typeFactory.createSqlType(SqlTypeName.BINARY, byteString.length()), SqlTypeName.BINARY); }
/** * Creates a byte array literal. */ public RexLiteral makeBinaryLiteral(ByteString byteString) { return makeLiteral( byteString, typeFactory.createSqlType(SqlTypeName.BINARY, byteString.length()), SqlTypeName.BINARY); }
/** 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 OVERLAY} function applied to binary strings. */ public static ByteString overlay(ByteString s, ByteString r, int start) { if (s == null || r == null) { return null; } return s.substring(0, start - 1).concat(r).concat(s.substring(start - 1 + r.length())); }
/** SQL {@code OVERLAY} function applied to binary strings. */ public static ByteString overlay(ByteString s, ByteString r, int start) { if (s == null || r == null) { return null; } return s.substring(0, start - 1) .concat(r) .concat(s.substring(start - 1 + r.length())); }
/** SQL {@code OVERLAY} function applied to binary strings. */ public static ByteString overlay(ByteString s, ByteString r, int start) { if (s == null || r == null) { return null; } return s.substring(0, start - 1) .concat(r) .concat(s.substring(start - 1 + r.length())); }