Class ClickHouseValues


  • public final class ClickHouseValues
    extends Object
    Help class for dealing with values.
    • Method Detail

      • convertToBigInteger

        public static BigInteger convertToBigInteger​(Inet4Address value)
        Converts IP address to big integer.
        Parameters:
        value - IP address
        Returns:
        big integer
      • convertToBigInteger

        public static BigInteger convertToBigInteger​(Inet6Address value)
        Converts IP address to big integer.
        Parameters:
        value - IP address
        Returns:
        big integer
      • convertToBigInteger

        public static BigInteger convertToBigInteger​(UUID value)
        Converts UUID to big integer.
        Parameters:
        value - UUID
        Returns:
        big integer
      • convertToHexString

        public static String convertToHexString​(byte[] bytes)
        Converts given byte array to string in hexadecimal format.
        Parameters:
        bytes - byte array
        Returns:
        non-null string
      • convertToUnhexExpression

        public static String convertToUnhexExpression​(byte[] bytes)
        Converts given byte array to unhex() expression.
        Parameters:
        bytes - byte array
        Returns:
        non-null expression
      • convertToInstant

        public static Instant convertToInstant​(BigDecimal value)
        Converts big decimal to instant.
        Parameters:
        value - big decimal
        Returns:
        instant
      • convertToDateTime

        public static LocalDateTime convertToDateTime​(BigDecimal value)
        Converts big decimal to date time.
        Parameters:
        value - big decimal
        Returns:
        date time
      • convertToDateTime

        public static ZonedDateTime convertToDateTime​(BigDecimal value,
                                                      TimeZone tz)
        Converts big decimal to date time.
        Parameters:
        value - big decimal
        tz - time zone, null is treated as UTC
        Returns:
        date time
      • convertToDateTime

        public static ZonedDateTime convertToDateTime​(BigDecimal value,
                                                      ZoneId zone)
        Converts big decimal to date time.
        Parameters:
        value - big decimal
        zone - zone id, null is treated as UTC
        Returns:
        date time
      • convertToDateTime

        public static OffsetDateTime convertToDateTime​(BigDecimal value,
                                                       ZoneOffset offset)
        Converts big decimal to date time.
        Parameters:
        value - big decimal
        offset - zone offset, null is treated as ZoneOffset.UTC
        Returns:
        date time
      • convertToIpv4

        public static Inet4Address convertToIpv4​(Inet6Address value)
        Converts IPv6 address to IPv4 address if applicable.
        Parameters:
        value - IPv6 address
        Returns:
        IPv4 address
        Throws:
        IllegalArgumentException - when failed to convert to IPv4 address
      • convertToIpv4

        public static Inet4Address convertToIpv4​(int value)
        Converts integer to IPv4 address.
        Parameters:
        value - integer
        Returns:
        IPv4 address
      • convertToIpv4

        public static Inet4Address convertToIpv4​(String value)
        Converts string to IPv4 address.
        Parameters:
        value - string
        Returns:
        IPv4 address
        Throws:
        IllegalArgumentException - when failed to convert to IPv4 address
      • convertToIpv6

        public static Inet6Address convertToIpv6​(BigInteger value)
        Converts big integer to IPv6 address.
        Parameters:
        value - big integer
        Returns:
        IPv6 address
        Throws:
        IllegalArgumentException - when failed to convert to IPv6 address
      • convertToIpv6

        public static Inet6Address convertToIpv6​(Inet4Address value)
        Converts IPv4 address to IPv6 address.
        Parameters:
        value - IPv4 address
        Returns:
        IPv6 address
        Throws:
        IllegalArgumentException - when failed to convert to IPv6 address
      • convertToIpv6

        public static Inet6Address convertToIpv6​(String value)
        Converts string to IPv6 address.
        Parameters:
        value - string
        Returns:
        IPv6 address
        Throws:
        IllegalArgumentException - when failed to convert to IPv6 address
      • convertToSqlExpression

        public static String convertToSqlExpression​(Object value)
        Converts abitrary object to an expression that can be used in SQL query.
        Parameters:
        value - value may or may not be null
        Returns:
        escaped SQL expression
      • convertToString

        public static String convertToString​(boolean[] value)
        Converts boolean array to compact string. Similar as Arrays.toString() but without any whitespace.
        Parameters:
        value - boolean array
        Returns:
        string
      • convertToString

        public static String convertToString​(char[] value)
        Converts character array to compact string. Similar as Arrays.toString() but without any whitespace.
        Parameters:
        value - character array
        Returns:
        string
      • convertToString

        public static String convertToString​(byte[] value)
        Converts byte array to compact string. Similar as Arrays.toString() but without any whitespace.
        Parameters:
        value - byte array
        Returns:
        string
      • convertToString

        public static String convertToString​(short[] value)
        Converts short array to compact string. Similar as Arrays.toString() but without any whitespace.
        Parameters:
        value - short array
        Returns:
        string
      • convertToString

        public static String convertToString​(int[] value)
        Converts integer array to compact string. Similar as Arrays.toString() but without any whitespace.
        Parameters:
        value - integer array
        Returns:
        string
      • convertToString

        public static String convertToString​(long[] value)
        Converts long array to compact string. Similar as Arrays.toString() but without any whitespace.
        Parameters:
        value - long array
        Returns:
        string
      • convertToString

        public static String convertToString​(float[] value)
        Converts float array to compact string. Similar as Arrays.toString() but without any whitespace.
        Parameters:
        value - float array
        Returns:
        string
      • convertToString

        public static String convertToString​(double[] value)
        Converts double array to compact string. Similar as Arrays.toString() but without any whitespace.
        Parameters:
        value - double array
        Returns:
        string
      • convertToString

        public static String convertToString​(ClickHouseValue value)
        Converts given value object to string.
        Parameters:
        value - value object
        Returns:
        string
      • convertToString

        public static String convertToString​(Object value)
        Converts object to string. Same as String.valueOf().
        Parameters:
        value - object may or may not be null
        Returns:
        string representation of the object
      • convertToUuid

        public static UUID convertToUuid​(BigInteger value)
        Converts big integer to UUID.
        Parameters:
        value - big integer
        Returns:
        UUID
      • convertToQuotedString

        public static String convertToQuotedString​(Object value)
        Converts object to quoted string.
        Parameters:
        value - object may or may not be null
        Returns:
        quoted string representing the object
      • createObjectArray

        public static <T> T[] createObjectArray​(Class<T> clazz,
                                                int length,
                                                int level)
        Creates an object array. Primitive types will be converted to corresponding wrapper types, also Boolean / boolean will be converted to Byte, and Character / char to Integer.
        Type Parameters:
        T - type of the base element
        Parameters:
        clazz - class of the base element, null is treated as Object.class
        length - length of the array, negative is treated as zero
        level - level of the array, must between 1 and 255
        Returns:
        a non-null object array
      • createPrimitiveArray

        public static Object createPrimitiveArray​(Class<?> clazz,
                                                  int length,
                                                  int level)
        Creates a primitive array if applicable. Wrapper types will be converted to corresponding primitive types, also Boolean / boolean will be converted to byte, and Character / char to int.
        Parameters:
        clazz - class of the base element
        length - length of the array, negative is treated as zero
        level - level of the array, must between 1 and 255
        Returns:
        a primitive array if applicable; an object array otherwise
      • extractSingleValue

        public static Object extractSingleValue​(Collection<?> value)
        Extract one and only value from singleton collection.
        Parameters:
        value - singleton collection
        Returns:
        value
        Throws:
        IllegalArgumentException - if the given collection is null or contains zero or more than one element
      • extractSingleValue

        public static Object extractSingleValue​(Enumeration<?> value)
        Extract one and only value from singleton enumeration.
        Parameters:
        value - singleton enumeration
        Returns:
        value
        Throws:
        IllegalArgumentException - if the given enumeration is null or contains zero or more than one element
      • extractSingleValue

        public static Object extractSingleValue​(Map<?,​?> value)
        Extract one and only value from singleton map - key will be ignored.
        Parameters:
        value - singleton map
        Returns:
        value
        Throws:
        IllegalArgumentException - if the given map is null or contains zero or more than one element
      • newValue

        public static ClickHouseValue newValue​(ClickHouseConfig config,
                                               ClickHouseColumn column)
        Creates a value object based on given column.
        Parameters:
        config - non-null configuration
        column - non-null column
        Returns:
        value object with default value, either null or empty
      • newValue

        public static ClickHouseValue newValue​(ClickHouseConfig config,
                                               ClickHouseDataType type)
        Creates a value object based on given data type.
        Parameters:
        config - non-null configuration
        type - non-null data type
        Returns:
        value object with default value, either null or empty