Package com.clickhouse.data
Interface ClickHouseValue
- All Superinterfaces:
Serializable
- All Known Subinterfaces:
ClickHouseArraySequence
- All Known Implementing Classes:
ClickHouseArrayValue,ClickHouseBigDecimalValue,ClickHouseBigIntegerValue,ClickHouseBitmapValue,ClickHouseBoolValue,ClickHouseByteValue,ClickHouseDateTimeValue,ClickHouseDateValue,ClickHouseDoubleValue,ClickHouseEmptyValue,ClickHouseEnumValue,ClickHouseFloatValue,ClickHouseGeoMultiPolygonValue,ClickHouseGeoPointValue,ClickHouseGeoPolygonValue,ClickHouseGeoRingValue,ClickHouseInstantValue,ClickHouseIntegerValue,ClickHouseIpv4Value,ClickHouseIpv6Value,ClickHouseLongValue,ClickHouseMapValue,ClickHouseNestedValue,ClickHouseObjectValue,ClickHouseOffsetDateTimeValue,ClickHouseShortValue,ClickHouseStringValue,ClickHouseTupleValue,ClickHouseUuidValue
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. use
asDateTime() to
convert an integer to LocalDateTime).-
Method Summary
Modifier and TypeMethodDescriptiondefault Object[]asArray()Gets value as an object array.default <T> T[]Gets value as an array.default BigDecimalGets value asBigDecimal, using default scale(usually 0).asBigDecimal(int scale) Gets value asBigDecimal.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[]Gets binary value as byte array.default byte[]Gets binary value as byte array.default booleanGets value as boolean.byteasByte()Gets value as byte.default InputStreamGets value as byte stream.default charGets value as character.default ReaderGets value as character stream.default LocalDateasDate()Gets value asLocalDate.default LocalDateTimeGets value asLocalDateTime, using default scale(usually 0).default LocalDateTimeasDateTime(int scale) Gets value asLocalDateTime.doubleasDouble()Gets value as double.default <T extends Enum<T>>
TGets value as enum.floatasFloat()Gets value as float.default Inet4AddressGets value asInet4Address.default Inet6AddressGets value asInet6Address.default InstantGets value asInstant, using default scale(usually 0).default InstantasInstant(int scale) Gets value asInstant.intGets value as integer.longasLong()Gets value as long.asMap()Gets value as a map.default <K,V> Map<K, V> Gets value as a map.asObject()Gets value as an object.default <T,E extends Enum<E>>
TGets value as a typed object.default OffsetDateTimeGets value asOffsetDateTime, using default scale(usually 0).default OffsetDateTimeasOffsetDateTime(int scale) Gets value asOffsetDateTime.default ObjectGets raw value as an object.shortasShort()Gets value as short.default StringasString()Gets value as unbounded string, using default charset(usually UTF-8).default LocalTimeasTime()Gets value asLocalTime.default LocalTimeasTime(int scale) Gets value asLocalTime.asTuple()Gets value as ordered list(tuple).default UUIDasUuid()Gets value as UUID.default ZonedDateTimeGets value asZonedDateTime, using default scale(usually 0).default ZonedDateTimeasZonedDateTime(int scale) Gets value asZonedDateTime.default ClickHouseValuecopy()Gets a shallow copy of this value object.copy(boolean deep) Gets a copy of this value object.default booleanChecks if the value is either positive or negative infinity as defined inDouble.default booleanisNaN()Checks if the value is Not-a-Number (NaN).default booleanChecks whether the value is nullable.booleanChecks 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.Resets to default value of corresponding data type.Resets value to null, or empty when null is not supported(e.g.Converts the value to escaped SQL expression.default ClickHouseValueupdate(boolean value) Updates value.default ClickHouseValueupdate(boolean[] value) Updates value.update(byte value) Updates value.default ClickHouseValueupdate(byte[] value) Updates value.default ClickHouseValueupdate(char value) Updates value.default ClickHouseValueupdate(char[] value) Updates value.update(double value) Updates value.default ClickHouseValueupdate(double[] value) Updates value.update(float value) Updates value.default ClickHouseValueupdate(float[] value) Updates value.update(int value) Updates value.default ClickHouseValueupdate(int[] value) Updates value.update(long value) Updates value.default ClickHouseValueupdate(long[] value) Updates value.update(short value) Updates value.default ClickHouseValueupdate(short[] value) Updates value.update(ClickHouseValue value) Updates value.default ClickHouseValueupdate(InputStream value) Updates value.default ClickHouseValueUpdates value.default ClickHouseValueUpdates value.default ClickHouseValueUpdates value.default ClickHouseValueUpdates value.Updates value.update(BigDecimal value) Updates value.update(BigInteger value) Updates value.default ClickHouseValueupdate(Inet4Address value) Updates value.default ClickHouseValueupdate(Inet6Address value) Updates value.default ClickHouseValueUpdates value.default ClickHouseValueUpdates value.default ClickHouseValueupdate(LocalDateTime value) Updates value.default ClickHouseValueUpdates 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 ClickHouseValueUpdates value.default ClickHouseValueUpdates value.default ClickHouseValueupdateUnknown(Object value) Updates value when the type is not supported.
-
Method Details
-
newUnsupportedException
Create a customized exception for unsupported type conversion.- Parameters:
from- type to convert fromto- type to convert to- Returns:
- customized exception
-
copy
Gets a shallow copy of this value object. Same ascopy(false).- Returns:
- shallow copy of this value object
-
copy
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
-
isNullable
default boolean isNullable()Checks whether the value is nullable. This always returnsfalsefor nested value type.- Returns:
- true if the value is nullable; 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
Gets value as an object array.- Returns:
- non-null object array
-
asArray
Gets value as an array.- Type Parameters:
T- type of the element- Parameters:
clazz- class of the element- Returns:
- non-null array
-
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
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
Gets value asBigDecimal, using default scale(usually 0).- Returns:
- big decimal, could be null
-
asBigDecimal
Gets value asBigDecimal.- Parameters:
scale- scale of the decimal- Returns:
- big decimal, could be null
-
asDate
Gets value asLocalDate.- Returns:
- date, could be null
-
asTime
Gets value asLocalTime.- Returns:
- time, could be null
-
asTime
Gets value asLocalTime.- Parameters:
scale- scale of the date time, between 0 (second) and 9 (nano second)- Returns:
- time, could be null
-
asDateTime
Gets value asLocalDateTime, using default scale(usually 0).- Returns:
- date time, could be null
-
asInstant
Gets value asInstant, using default scale(usually 0).- Returns:
- date time, could be null
-
asOffsetDateTime
Gets value asOffsetDateTime, using default scale(usually 0).- Returns:
- date time, could be null
-
asZonedDateTime
Gets value asZonedDateTime, using default scale(usually 0).- Returns:
- date time, could be null
-
asDateTime
Gets value asLocalDateTime.- Parameters:
scale- scale of the date time, between 0 (second) and 9 (nano second)- Returns:
- date time, could be null
-
asInstant
Gets value asInstant.- Parameters:
scale- scale of the date time, between 0 (second) and 9 (nano second)- Returns:
- instant, could be null
-
asOffsetDateTime
Gets value asOffsetDateTime.- Parameters:
scale- scale of the date time, between 0 (second) and 9 (nano second)- Returns:
- date time, could be null
-
asZonedDateTime
Gets value asZonedDateTime.- Parameters:
scale- scale of the date time, between 0 (second) and 9 (nano second)- Returns:
- date time, could be null
-
asEnum
Gets value as enum.- Type Parameters:
T- type of the enum- Parameters:
enumType- enum class- Returns:
- enum, could be null
-
asInet4Address
Gets value asInet4Address.- Returns:
- IPv4 address, could be null
-
asInet6Address
Gets value asInet6Address.- Returns:
- IPv6 address, could be null
-
asMap
Gets value as a map.- Returns:
- non-null map value
-
asMap
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
-
asRawObject
Gets raw value as an object. This method is probably only useful forStringas it can be either a byte array or text.- Returns:
- an object representing the raw value, could be null
-
asObject
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
Gets binary value as byte array.- Parameters:
charset- charset, null is same as default(UTF-8)- Returns:
- byte array which could be null
-
asBinary
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
Gets value as unbounded string, using default charset(usually UTF-8).- Returns:
- string value, could be null
-
asTuple
Gets value as ordered list(tuple).- Returns:
- non-null list
-
asUuid
Gets value as UUID.- Returns:
- uuid, could be null
-
resetToDefault
ClickHouseValue resetToDefault()Resets to default value of corresponding data type.- Returns:
- this object
-
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
Updates value.- Parameters:
value- value to update- Returns:
- this object
-
update
Updates value.- Parameters:
value- value to update- Returns:
- this object
-
update
Updates value.- Parameters:
value- value to update- Returns:
- this object
-
update
Updates value.- Parameters:
value- value to update- Returns:
- this object
-
update
Updates value.- Parameters:
value- value to update- Returns:
- this object
-
update
Updates value.- Parameters:
value- value to update- Returns:
- this object
-
update
Updates value.- Parameters:
value- value to update- Returns:
- this object
-
update
Updates value.- Parameters:
value- value to update- Returns:
- this object
-
update
Updates value.- Parameters:
value- value to update- Returns:
- this object
-
update
Updates value.- Parameters:
value- value to update- Returns:
- this object
-
update
Updates value.- Parameters:
value- value to update- Returns:
- this object
-
update
Updates value.- Parameters:
value- value to update- Returns:
- this object
-
update
Updates value.- Parameters:
value- value to update- Returns:
- this object
-
update
Updates value.- Parameters:
value- value to update- Returns:
- this object
-
update
Updates value.- Parameters:
value- value to update- Returns:
- this object
-
update
Updates value.- Parameters:
value- value to update- Returns:
- this object
-
update
Updates value.- Parameters:
value- value to update- Returns:
- this object
-
update
Updates value.- Parameters:
value- value to update- Returns:
- this object
-
update
Updates value.- Parameters:
value- value to update- Returns:
- this object
-
update
Updates value.- Parameters:
value- value to update- Returns:
- this object
-
update
Updates value.- Parameters:
value- value to update- Returns:
- this object
-
update
Updates value.- Parameters:
value- value to update- Returns:
- this object
-
update
Updates value.- Parameters:
value- value to update- Returns:
- this object
-
update
Updates value.- Parameters:
value- value to update- Returns:
- this object
-
update
Updates value.- Parameters:
value- value to update- Returns:
- this object
-
update
Updates value.- Parameters:
value- value to update- Returns:
- this object
-
update
Updates value.- Parameters:
value- value to update- Returns:
- this object
-
update
Updates value.- Parameters:
value- value to update- Returns:
- this object
-
update
Updates value.- Parameters:
value- value to update- Returns:
- this object
-
update
Updates value.- Parameters:
value- value to update- Returns:
- this object
-
update
Updates value.- Parameters:
value- value to update- Returns:
- this object
-
update
Updates value.- Parameters:
value- value to update- Returns:
- this object
-
update
Updates value.- Parameters:
value- value to update- Returns:
- this object
-
update
Updates value.- Parameters:
value- value to update- Returns:
- this object
-
update
Updates value.- Parameters:
value- value to update- Returns:
- this object
-
update
Updates value.- Parameters:
value- value to update- Returns:
- this object
-
updateUnknown
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
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
-