Package com.clickhouse.client
Interface ClickHouseValue
-
- All Superinterfaces:
Serializable
- All Known Implementing Classes:
ClickHouseArrayValue,ClickHouseBigDecimalValue,ClickHouseBigIntegerValue,ClickHouseBitmapValue,ClickHouseBoolValue,ClickHouseByteArrayValue,ClickHouseByteValue,ClickHouseDateTimeValue,ClickHouseDateValue,ClickHouseDoubleArrayValue,ClickHouseDoubleValue,ClickHouseEmptyValue,ClickHouseEnumValue,ClickHouseFloatArrayValue,ClickHouseFloatValue,ClickHouseGeoMultiPolygonValue,ClickHouseGeoPointValue,ClickHouseGeoPolygonValue,ClickHouseGeoRingValue,ClickHouseInstantValue,ClickHouseIntArrayValue,ClickHouseIntegerValue,ClickHouseIpv4Value,ClickHouseIpv6Value,ClickHouseLongArrayValue,ClickHouseLongValue,ClickHouseMapValue,ClickHouseNestedValue,ClickHouseObjectValue,ClickHouseOffsetDateTimeValue,ClickHouseShortArrayValue,ClickHouseShortValue,ClickHouseStringValue,ClickHouseTupleValue,ClickHouseUuidValue
public interface ClickHouseValue extends Serializable
Wrapper of a value returned from ClickHouse. It could be as simple as one single byte or in a complex structure like nested arrays. It also provides convenient methods for type conversion(e.g. useasDateTime()to convert an integer toLocalDateTime).
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default Object[]asArray()Gets value as an object array.default <T> T[]asArray(Class<T> clazz)Gets value as an array.default BigDecimalasBigDecimal()Gets value asBigDecimal, using default scale(usually 0).BigDecimalasBigDecimal(int scale)Gets value asBigDecimal.BigIntegerasBigInteger()Gets value asBigInteger.default booleanasBoolean()Gets value as boolean.byteasByte()Gets value as byte.default InputStreamasByteStream()Gets value as byte stream.default charasCharacter()Gets value as character.default ReaderasCharacterStream()Gets value as character stream.default LocalDateasDate()Gets value asLocalDate.default LocalDateTimeasDateTime()Gets value asLocalDateTime, using default scale(usually 0).default LocalDateTimeasDateTime(int scale)Gets value asLocalDateTime.doubleasDouble()Gets value as double.default <T extends Enum<T>>
TasEnum(Class<T> enumType)Gets value as enum.floatasFloat()Gets value as float.default Inet4AddressasInet4Address()Gets value asInet4Address.default Inet6AddressasInet6Address()Gets value asInet6Address.default InstantasInstant()Gets value asInstant, using default scale(usually 0).default InstantasInstant(int scale)Gets value asInstant.intasInteger()Gets value as integer.longasLong()Gets value as long.default Map<Object,Object>asMap()Gets value as a map.default <K,V>
Map<K,V>asMap(Class<K> keyClass, Class<V> valueClass)Gets value as a map.ObjectasObject()Gets value as an object.default <T,E extends Enum<E>>
TasObject(Class<T> clazz)Gets value as a typed object.default OffsetDateTimeasOffsetDateTime()Gets value asOffsetDateTime, using default scale(usually 0).default OffsetDateTimeasOffsetDateTime(int scale)Gets value asOffsetDateTime.shortasShort()Gets value as short.default StringasString()Gets value as unbounded string, using default charset(usually UTF-8).default StringasString(int length)Gets value as fixed length(in bytes) string, using default charset(usually UTF-8).default StringasString(int length, Charset charset)Gets value as fixed length(in bytes) string.default StringasString(Charset charset)Gets value as unbounded string.default LocalTimeasTime()Gets value asLocalTime.default LocalTimeasTime(int scale)Gets value asLocalTime.default List<Object>asTuple()Gets value as ordered list(tuple).default UUIDasUuid()Gets value as UUID.default ZonedDateTimeasZonedDateTime()Gets value asZonedDateTime, using default scale(usually 0).default ZonedDateTimeasZonedDateTime(int scale)Gets value asZonedDateTime.default ClickHouseValuecopy()Gets a shallow copy of this value object.ClickHouseValuecopy(boolean deep)Gets a copy of this value object.default booleanisInfinity()Checks if the value is either positive or negative infinity as defined inDouble.default booleanisNaN()Checks if the value is Not-a-Number (NaN).booleanisNullOrEmpty()Checks if the value is null, or empty for non-null types like Array, Tuple and Map.default UnsupportedOperationExceptionnewUnsupportedException(String from, String to)Create a customized exception for unsupported type conversion.ClickHouseValueresetToNullOrEmpty()Resets value to null, or empty when null is not supported(e.g.StringtoSqlExpression()Converts the value to escaped SQL expression.default ClickHouseValueupdate(boolean value)Updates value.default ClickHouseValueupdate(boolean[] value)Updates value.ClickHouseValueupdate(byte value)Updates value.default ClickHouseValueupdate(byte[] value)Updates value.default ClickHouseValueupdate(char value)Updates value.default ClickHouseValueupdate(char[] value)Updates value.ClickHouseValueupdate(double value)Updates value.default ClickHouseValueupdate(double[] value)Updates value.ClickHouseValueupdate(float value)Updates value.default ClickHouseValueupdate(float[] value)Updates value.ClickHouseValueupdate(int value)Updates value.default ClickHouseValueupdate(int[] value)Updates value.ClickHouseValueupdate(long value)Updates value.default ClickHouseValueupdate(long[] value)Updates value.ClickHouseValueupdate(short value)Updates value.default ClickHouseValueupdate(short[] value)Updates value.ClickHouseValueupdate(ClickHouseValue value)Updates value.default ClickHouseValueupdate(InputStream value)Updates value.default ClickHouseValueupdate(Reader value)Updates value.default ClickHouseValueupdate(Enum<?> value)Updates value.default ClickHouseValueupdate(Object value)Updates value.default ClickHouseValueupdate(Object[] value)Updates value.ClickHouseValueupdate(String value)Updates value.ClickHouseValueupdate(BigDecimal value)Updates value.ClickHouseValueupdate(BigInteger value)Updates value.default ClickHouseValueupdate(Inet4Address value)Updates value.default ClickHouseValueupdate(Inet6Address value)Updates value.default ClickHouseValueupdate(Instant value)Updates value.default ClickHouseValueupdate(LocalDate value)Updates value.default ClickHouseValueupdate(LocalDateTime value)Updates value.default ClickHouseValueupdate(LocalTime value)Updates value.default ClickHouseValueupdate(OffsetDateTime value)Updates value.default ClickHouseValueupdate(ZonedDateTime value)Updates value.default ClickHouseValueupdate(Collection<?> value)Updates value.default ClickHouseValueupdate(Enumeration<?> value)Updates value.default ClickHouseValueupdate(Map<?,?> value)Updates value.default ClickHouseValueupdate(UUID value)Updates value.default ClickHouseValueupdateUnknown(Object value)Updates value when the type is not supported.
-
-
-
Method Detail
-
newUnsupportedException
default UnsupportedOperationException newUnsupportedException(String from, String to)
Create a customized exception for unsupported type conversion.- Parameters:
from- type to convert fromto- type to convert to- Returns:
- customized exception
-
copy
default ClickHouseValue copy()
Gets a shallow copy of this value object. Same ascopy(false).- Returns:
- shallow copy of this value object
-
copy
ClickHouseValue copy(boolean deep)
Gets a copy of this value object.- Parameters:
deep- true to create a deep copy; false for a shallow copy- Returns:
- copy of this value object
-
isInfinity
default boolean isInfinity()
Checks if the value is either positive or negative infinity as defined inDouble.- Returns:
- true if it's infinity; false otherwise
-
isNaN
default boolean isNaN()
Checks if the value is Not-a-Number (NaN).- Returns:
- true if the value is NaN; false otherwise
-
isNullOrEmpty
boolean isNullOrEmpty()
Checks if the value is null, or empty for non-null types like Array, Tuple and Map.Please pay attention that only nullability will be considered for String, meaning this method will return
falsefor an empty string. This is because String is treated as value-based type instead of a container like Array.- Returns:
- true if the value is null or empty; false otherwise
-
asArray
default Object[] asArray()
Gets value as an object array.- Returns:
- non-null object array
-
asArray
default <T> T[] asArray(Class<T> clazz)
Gets value as an array.- Type Parameters:
T- type of the element- Parameters:
clazz- class of the element- Returns:
- non-null array
-
asByteStream
default InputStream asByteStream()
Gets value as byte stream. It's caller's responsibility to close the stream at the end of reading.- Returns:
- non-null byte stream for reading
-
asCharacterStream
default Reader asCharacterStream()
Gets value as character stream. It's caller's responsibility to close the tream at the end of reading.- Returns:
- non-null character stream for reading
-
asBoolean
default boolean asBoolean()
Gets value as boolean.- Returns:
- boolean value
-
asCharacter
default char asCharacter()
Gets value as character.- Returns:
- character value
-
asByte
byte asByte()
Gets value as byte.- Returns:
- byte value
-
asShort
short asShort()
Gets value as short.- Returns:
- short value
-
asInteger
int asInteger()
Gets value as integer.- Returns:
- integer value
-
asLong
long asLong()
Gets value as long.- Returns:
- long value
-
asBigInteger
BigInteger asBigInteger()
Gets value asBigInteger.- Returns:
- big integer, could be null
-
asFloat
float asFloat()
Gets value as float.- Returns:
- float value
-
asDouble
double asDouble()
Gets value as double.- Returns:
- double value
-
asBigDecimal
default BigDecimal asBigDecimal()
Gets value asBigDecimal, using default scale(usually 0).- Returns:
- big decimal, could be null
-
asBigDecimal
BigDecimal asBigDecimal(int scale)
Gets value asBigDecimal.- Parameters:
scale- scale of the decimal- Returns:
- big decimal, could be null
-
asTime
default LocalTime asTime(int scale)
Gets value asLocalTime.- Parameters:
scale- scale of the date time, between 0 (second) and 9 (nano second)- Returns:
- time, could be null
-
asDateTime
default LocalDateTime asDateTime()
Gets value asLocalDateTime, using default scale(usually 0).- Returns:
- date time, could be null
-
asInstant
default Instant asInstant()
Gets value asInstant, using default scale(usually 0).- Returns:
- date time, could be null
-
asOffsetDateTime
default OffsetDateTime asOffsetDateTime()
Gets value asOffsetDateTime, using default scale(usually 0).- Returns:
- date time, could be null
-
asZonedDateTime
default ZonedDateTime asZonedDateTime()
Gets value asZonedDateTime, using default scale(usually 0).- Returns:
- date time, could be null
-
asDateTime
default LocalDateTime asDateTime(int scale)
Gets value asLocalDateTime.- Parameters:
scale- scale of the date time, between 0 (second) and 9 (nano second)- Returns:
- date time, could be null
-
asInstant
default Instant asInstant(int scale)
Gets value asInstant.- Parameters:
scale- scale of the date time, between 0 (second) and 9 (nano second)- Returns:
- instant, could be null
-
asOffsetDateTime
default OffsetDateTime asOffsetDateTime(int scale)
Gets value asOffsetDateTime.- Parameters:
scale- scale of the date time, between 0 (second) and 9 (nano second)- Returns:
- date time, could be null
-
asZonedDateTime
default ZonedDateTime asZonedDateTime(int scale)
Gets value asZonedDateTime.- Parameters:
scale- scale of the date time, between 0 (second) and 9 (nano second)- Returns:
- date time, could be null
-
asEnum
default <T extends Enum<T>> T asEnum(Class<T> enumType)
Gets value as enum.- Type Parameters:
T- type of the enum- Parameters:
enumType- enum class- Returns:
- enum, could be null
-
asInet4Address
default Inet4Address asInet4Address()
Gets value asInet4Address.- Returns:
- IPv4 address, could be null
-
asInet6Address
default Inet6Address asInet6Address()
Gets value asInet6Address.- Returns:
- IPv6 address, could be null
-
asMap
default <K,V> Map<K,V> asMap(Class<K> keyClass, Class<V> valueClass)
Gets value as a map.- Type Parameters:
K- type of keyV- type of value- Parameters:
keyClass- non-null class of keyvalueClass- non-null class of value- Returns:
- non-null map value
-
asObject
Object asObject()
Gets value as an object.- Returns:
- an object representing the value, could be null
-
asObject
default <T,E extends Enum<E>> T asObject(Class<T> clazz)
Gets value as a typed object.- Type Parameters:
T- type of the objectE- type of the enum- Parameters:
clazz- class of the object- Returns:
- a typed object representing the value, could be null
-
asString
default String asString()
Gets value as unbounded string, using default charset(usually UTF-8).- Returns:
- string value, could be null
-
asString
default String asString(int length)
Gets value as fixed length(in bytes) string, using default charset(usually UTF-8).- Parameters:
length- byte length of the string, 0 or negative number means unbounded- Returns:
- string value, could be null
-
asString
default String asString(Charset charset)
Gets value as unbounded string.- Parameters:
charset- charset, null is same as default(UTF-8)- Returns:
- string value, could be null
-
asString
default String asString(int length, Charset charset)
Gets value as fixed length(in bytes) string.- Parameters:
length- byte length of the string, 0 or negative number means unboundedcharset- charset, null is same as default(UTF-8)- Returns:
- string value, could be null
-
asUuid
default UUID asUuid()
Gets value as UUID.- Returns:
- uuid, could be null
-
resetToNullOrEmpty
ClickHouseValue resetToNullOrEmpty()
Resets value to null, or empty when null is not supported(e.g. Array, Tuple and Map etc.).Keep in mind that String is value-based type, so this method will change its value to null instead of an empty string.
- Returns:
- this object
-
toSqlExpression
String toSqlExpression()
Converts the value to escaped SQL expression. For example, number 123 will be converted to123, while string "12'3" will be converted to @{code '12\'3'}.- Returns:
- escaped SQL expression
-
update
default ClickHouseValue update(InputStream value)
Updates value.- Parameters:
value- value to update- Returns:
- this object
-
update
default ClickHouseValue update(Reader value)
Updates value.- Parameters:
value- value to update- Returns:
- this object
-
update
default ClickHouseValue update(boolean value)
Updates value.- Parameters:
value- value to update- Returns:
- this object
-
update
default ClickHouseValue update(boolean[] value)
Updates value.- Parameters:
value- value to update- Returns:
- this object
-
update
default ClickHouseValue update(char value)
Updates value.- Parameters:
value- value to update- Returns:
- this object
-
update
default ClickHouseValue update(char[] value)
Updates value.- Parameters:
value- value to update- Returns:
- this object
-
update
ClickHouseValue update(byte value)
Updates value.- Parameters:
value- value to update- Returns:
- this object
-
update
default ClickHouseValue update(byte[] value)
Updates value.- Parameters:
value- value to update- Returns:
- this object
-
update
ClickHouseValue update(short value)
Updates value.- Parameters:
value- value to update- Returns:
- this object
-
update
default ClickHouseValue update(short[] value)
Updates value.- Parameters:
value- value to update- Returns:
- this object
-
update
ClickHouseValue update(int value)
Updates value.- Parameters:
value- value to update- Returns:
- this object
-
update
default ClickHouseValue update(int[] value)
Updates value.- Parameters:
value- value to update- Returns:
- this object
-
update
ClickHouseValue update(long value)
Updates value.- Parameters:
value- value to update- Returns:
- this object
-
update
default ClickHouseValue update(long[] value)
Updates value.- Parameters:
value- value to update- Returns:
- this object
-
update
ClickHouseValue update(float value)
Updates value.- Parameters:
value- value to update- Returns:
- this object
-
update
default ClickHouseValue update(float[] value)
Updates value.- Parameters:
value- value to update- Returns:
- this object
-
update
ClickHouseValue update(double value)
Updates value.- Parameters:
value- value to update- Returns:
- this object
-
update
default ClickHouseValue update(double[] value)
Updates value.- Parameters:
value- value to update- Returns:
- this object
-
update
ClickHouseValue update(BigInteger value)
Updates value.- Parameters:
value- value to update- Returns:
- this object
-
update
ClickHouseValue update(BigDecimal value)
Updates value.- Parameters:
value- value to update- Returns:
- this object
-
update
default ClickHouseValue update(Enum<?> value)
Updates value.- Parameters:
value- value to update- Returns:
- this object
-
update
default ClickHouseValue update(Inet4Address value)
Updates value.- Parameters:
value- value to update- Returns:
- this object
-
update
default ClickHouseValue update(Inet6Address value)
Updates value.- Parameters:
value- value to update- Returns:
- this object
-
update
default ClickHouseValue update(LocalDate value)
Updates value.- Parameters:
value- value to update- Returns:
- this object
-
update
default ClickHouseValue update(LocalTime value)
Updates value.- Parameters:
value- value to update- Returns:
- this object
-
update
default ClickHouseValue update(LocalDateTime value)
Updates value.- Parameters:
value- value to update- Returns:
- this object
-
update
default ClickHouseValue update(Instant value)
Updates value.- Parameters:
value- value to update- Returns:
- this object
-
update
default ClickHouseValue update(OffsetDateTime value)
Updates value.- Parameters:
value- value to update- Returns:
- this object
-
update
default ClickHouseValue update(ZonedDateTime value)
Updates value.- Parameters:
value- value to update- Returns:
- this object
-
update
default ClickHouseValue update(Collection<?> value)
Updates value.- Parameters:
value- value to update- Returns:
- this object
-
update
default ClickHouseValue update(Enumeration<?> value)
Updates value.- Parameters:
value- value to update- Returns:
- this object
-
update
default ClickHouseValue update(Map<?,?> value)
Updates value.- Parameters:
value- value to update- Returns:
- this object
-
update
ClickHouseValue update(String value)
Updates value.- Parameters:
value- value to update- Returns:
- this object
-
update
default ClickHouseValue update(UUID value)
Updates value.- Parameters:
value- value to update- Returns:
- this object
-
update
ClickHouseValue update(ClickHouseValue value)
Updates value.- Parameters:
value- value to update- Returns:
- this object
-
update
default ClickHouseValue update(Object[] value)
Updates value.- Parameters:
value- value to update- Returns:
- this object
-
updateUnknown
default ClickHouseValue updateUnknown(Object value)
Updates value when the type is not supported. This method will be called at the end ofupdate(Object)after trying all known classes. By default, it's same asupdate(String.valueOf(value)).Please avoid to call
update(Object)here as it will create endless loop.- Parameters:
value- value to update- Returns:
- this object
-
update
default ClickHouseValue update(Object value)
Updates value. This method tries to identify type ofvalueand then use corresponding update method to proceed. Unknown value will be passed toupdateUnknown(Object).- Parameters:
value- value to update, could be null- Returns:
- this object
-
-