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 BigDecimal
asBigDecimal()
Gets value asBigDecimal
, using default scale(usually 0).BigDecimal
asBigDecimal(int scale)
Gets value asBigDecimal
.BigInteger
asBigInteger()
Gets value asBigInteger
.default byte[]
asBinary()
Gets binary value as byte array.default byte[]
asBinary(int length)
Gets binary value as fixed length byte array.default byte[]
asBinary(int length, Charset charset)
Gets binary value as byte array.default byte[]
asBinary(Charset charset)
Gets binary value as byte array.default boolean
asBoolean()
Gets value as boolean.byte
asByte()
Gets value as byte.default InputStream
asByteStream()
Gets value as byte stream.default char
asCharacter()
Gets value as character.default Reader
asCharacterStream()
Gets value as character stream.default LocalDate
asDate()
Gets value asLocalDate
.default LocalDateTime
asDateTime()
Gets value asLocalDateTime
, using default scale(usually 0).default LocalDateTime
asDateTime(int scale)
Gets value asLocalDateTime
.double
asDouble()
Gets value as double.default <T extends Enum<T>>
TasEnum(Class<T> enumType)
Gets value as enum.float
asFloat()
Gets value as float.default Inet4Address
asInet4Address()
Gets value asInet4Address
.default Inet6Address
asInet6Address()
Gets value asInet6Address
.default Instant
asInstant()
Gets value asInstant
, using default scale(usually 0).default Instant
asInstant(int scale)
Gets value asInstant
.int
asInteger()
Gets value as integer.long
asLong()
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.Object
asObject()
Gets value as an object.default <T,E extends Enum<E>>
TasObject(Class<T> clazz)
Gets value as a typed object.default OffsetDateTime
asOffsetDateTime()
Gets value asOffsetDateTime
, using default scale(usually 0).default OffsetDateTime
asOffsetDateTime(int scale)
Gets value asOffsetDateTime
.short
asShort()
Gets value as short.default String
asString()
Gets value as unbounded string, using default charset(usually UTF-8).default String
asString(int length)
Gets value as fixed length(in bytes) string, using default charset(usually UTF-8).default String
asString(int length, Charset charset)
Gets value as fixed length(in bytes) string.default String
asString(Charset charset)
Gets value as unbounded string.default LocalTime
asTime()
Gets value asLocalTime
.default LocalTime
asTime(int scale)
Gets value asLocalTime
.default List<Object>
asTuple()
Gets value as ordered list(tuple).default UUID
asUuid()
Gets value as UUID.default ZonedDateTime
asZonedDateTime()
Gets value asZonedDateTime
, using default scale(usually 0).default ZonedDateTime
asZonedDateTime(int scale)
Gets value asZonedDateTime
.default ClickHouseValue
copy()
Gets a shallow copy of this value object.ClickHouseValue
copy(boolean deep)
Gets a copy of this value object.default boolean
isInfinity()
Checks if the value is either positive or negative infinity as defined inDouble
.default boolean
isNaN()
Checks if the value is Not-a-Number (NaN).boolean
isNullOrEmpty()
Checks if the value is null, or empty for non-null types like Array, Tuple and Map.default UnsupportedOperationException
newUnsupportedException(String from, String to)
Create a customized exception for unsupported type conversion.ClickHouseValue
resetToNullOrEmpty()
Resets value to null, or empty when null is not supported(e.g.String
toSqlExpression()
Converts the value to escaped SQL expression.default ClickHouseValue
update(boolean value)
Updates value.default ClickHouseValue
update(boolean[] value)
Updates value.ClickHouseValue
update(byte value)
Updates value.default ClickHouseValue
update(byte[] value)
Updates value.default ClickHouseValue
update(char value)
Updates value.default ClickHouseValue
update(char[] value)
Updates value.ClickHouseValue
update(double value)
Updates value.default ClickHouseValue
update(double[] value)
Updates value.ClickHouseValue
update(float value)
Updates value.default ClickHouseValue
update(float[] value)
Updates value.ClickHouseValue
update(int value)
Updates value.default ClickHouseValue
update(int[] value)
Updates value.ClickHouseValue
update(long value)
Updates value.default ClickHouseValue
update(long[] value)
Updates value.ClickHouseValue
update(short value)
Updates value.default ClickHouseValue
update(short[] value)
Updates value.ClickHouseValue
update(ClickHouseValue value)
Updates value.default ClickHouseValue
update(InputStream value)
Updates value.default ClickHouseValue
update(Reader value)
Updates value.default ClickHouseValue
update(Enum<?> value)
Updates value.default ClickHouseValue
update(Object value)
Updates value.default ClickHouseValue
update(Object[] value)
Updates value.ClickHouseValue
update(String value)
Updates value.ClickHouseValue
update(BigDecimal value)
Updates value.ClickHouseValue
update(BigInteger value)
Updates value.default ClickHouseValue
update(Inet4Address value)
Updates value.default ClickHouseValue
update(Inet6Address value)
Updates value.default ClickHouseValue
update(Instant value)
Updates value.default ClickHouseValue
update(LocalDate value)
Updates value.default ClickHouseValue
update(LocalDateTime value)
Updates value.default ClickHouseValue
update(LocalTime value)
Updates value.default ClickHouseValue
update(OffsetDateTime value)
Updates value.default ClickHouseValue
update(ZonedDateTime value)
Updates value.default ClickHouseValue
update(Collection<?> value)
Updates value.default ClickHouseValue
update(Enumeration<?> value)
Updates value.default ClickHouseValue
update(Map<?,?> value)
Updates value.default ClickHouseValue
update(UUID value)
Updates value.default ClickHouseValue
updateUnknown(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
false
for 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
-
asBinary
default byte[] asBinary()
Gets binary value as byte array.- Returns:
- byte array which could be null
-
asBinary
default byte[] asBinary(int length)
Gets binary value as fixed length byte array.- Parameters:
length
- byte length of value, 0 or negative number means no limit- Returns:
- byte array which could be null
-
asBinary
default byte[] asBinary(Charset charset)
Gets binary value as byte array.- Parameters:
charset
- charset, null is same as default(UTF-8)- Returns:
- byte array which could be null
-
asBinary
default byte[] asBinary(int length, Charset charset)
Gets binary value as byte array.- Parameters:
length
- byte length of value, 0 or negative number means no limitcharset
- charset, null is same as default(UTF-8)- Returns:
- byte array which 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 ofvalue
and 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
-
-