Class TruncateUtil

java.lang.Object
org.apache.iceberg.util.TruncateUtil

public class TruncateUtil extends Object
Contains the logic for various truncate transformations for various types.

This utility class allows for the logic to be reused in different scenarios where input validation is done at different times either in org.apache.iceberg.transforms.Truncate and within defined SQL functions for different compute engines for usage in SQL.

In general, the inputs to the functions should have already been validated by the calling code, as different classes use truncate with different preprocessing. This generally means that the truncation width is positive and the value to truncate is non-null.

Thus, none of these utility functions validate their input. It is the responsibility of the calling code to validate input.

See also UnicodeUtil.truncateString(CharSequence, int) and BinaryUtil.truncateBinaryUnsafe(ByteBuffer, int) for similar methods for Strings and ByteBuffers.

  • Method Details

    • truncateByte

      public static byte truncateByte(int width, byte value)
    • truncateShort

      public static short truncateShort(int width, short value)
    • truncateInt

      public static int truncateInt(int width, int value)
    • truncateLong

      public static long truncateLong(int width, long value)
    • truncateDecimal

      public static BigDecimal truncateDecimal(BigInteger unscaledWidth, BigDecimal value)