Class TypedValue
java.lang.Object
org.apache.calcite.avatica.remote.TypedValue
Value and type.
There are 3 representations:
- JDBC - the representation used by JDBC get and set methods
- Serial - suitable for serializing using JSON
- Local - used by Calcite for efficient computation
The following table shows the Java type(s) that may represent each SQL type in each representation.
| Type | JDBC | Serial | Local |
|---|---|---|---|
| BOOLEAN | boolean | boolean | boolean |
| BINARY, VARBINARY | byte[] | String (base64) | ByteString |
| DATE | Date |
int | int |
| TIME | Time |
int | int |
| DATE | Timestamp |
long | long |
| CHAR, VARCHAR | String | String | String |
| TINYINT | byte | Number | byte |
| SMALLINT | short | Number | short |
| INTEGER | int | Number | int |
| BIGINT | long | Number | long |
| REAL | float | Number | float |
| FLOAT, DOUBLE | double | Number | double |
| DECIMAL | BigDecimal | Number | BigDecimal |
| ARRAY | Array | List<Object> | List<Object> |
Note:
- The various numeric types (TINYINT, SMALLINT, INTEGER, BIGINT, REAL,
FLOAT, DOUBLE) are represented by
Numberin serial format because JSON numbers are not strongly typed. Afloatvalue3.0is transmitted as3, and is therefore decoded as anint. - The date-time types (DATE, TIME, TIMESTAMP) are represented in JDBC as
Date,Time,Timestamp, all sub-classes ofDate. When they are passed to and from the server, they are interpreted in terms of a time zone, by default the current connection's time zone. Their serial and local representations asint(days since 1970-01-01 for DATE, milliseconds since 00:00:00.000 for TIME), and long (milliseconds since 1970-01-01 00:00:00.000 for TIMESTAMP) are easier to work with, because it is clear that time zone is not involved. - BINARY and VARBINARY values are represented as base64-encoded strings for serialization over JSON.
-
Field Summary
FieldsModifier and TypeFieldDescriptionfinal ColumnMetaData.RepNon-null for ARRAYs, the type of the values stored in the ARRAY.static final TypedValuestatic final org.apache.calcite.avatica.proto.Common.TypedValuefinal ColumnMetaData.RepType of the value.final ObjectValue. -
Method Summary
Modifier and TypeMethodDescriptionstatic TypedValuebooleanstatic TypedValuefromProto(org.apache.calcite.avatica.proto.Common.TypedValue proto) Constructs aTypedValuefrom the protocol buffer representation.static ObjectgetSerialFromProto(org.apache.calcite.avatica.proto.Common.TypedValue protoValue) Converts the serialized value into the appropriate primitive/object.inthashCode()static TypedValueCreates a TypedValue from a value in JDBC representation, deducing its type.static TypedValueofJdbc(ColumnMetaData.Rep rep, Object value, Calendar calendar) Creates a TypedValue from a value in JDBC representation.static TypedValueofLocal(ColumnMetaData.Rep rep, Object value) Creates a TypedValue from a value in local representation.static TypedValueofSerial(ColumnMetaData.Rep rep, Object value) Creates a TypedValue from a value in serial representation.static ObjectprotoToJdbc(org.apache.calcite.avatica.proto.Common.TypedValue protoValue, Calendar calendar) Extracts the JDBC value from protobuf-TypedValue representation.Converts the value into the JDBC representation.toLocal()Converts the value into the local representation.org.apache.calcite.avatica.proto.Common.TypedValuetoProto()Creates a protocol buffer equivalent object forthis.static org.apache.calcite.avatica.proto.Common.RepWrites the given object into the Protobuf representation of a TypedValue.values(List<TypedValue> typedValues) Converts a list ofTypedValueto a list of values.
-
Field Details
-
EXPLICIT_NULL
-
PROTO_IMPLICIT_NULL
public static final org.apache.calcite.avatica.proto.Common.TypedValue PROTO_IMPLICIT_NULL -
type
Type of the value. -
value
Value.Always in a form that can be serialized to JSON by Jackson. For example, byte arrays are represented as String.
-
componentType
Non-null for ARRAYs, the type of the values stored in the ARRAY. Null for all other cases.
-
-
Method Details
-
create
-
ofLocal
Creates a TypedValue from a value in local representation. -
ofSerial
Creates a TypedValue from a value in serial representation. -
ofJdbc
Creates a TypedValue from a value in JDBC representation. -
ofJdbc
Creates a TypedValue from a value in JDBC representation, deducing its type. -
toLocal
Converts the value into the local representation.For example, a byte string is represented as a
ByteString; a long is represented as aLong(not just someNumber). -
toJdbc
Converts the value into the JDBC representation.For example, a byte string is represented as a
ByteString; a long is represented as aLong(not just someNumber). -
values
Converts a list ofTypedValueto a list of values. -
toProto
public org.apache.calcite.avatica.proto.Common.TypedValue toProto()Creates a protocol buffer equivalent object forthis.- Returns:
- A protobuf TypedValue equivalent for
this
-
fromProto
Constructs aTypedValuefrom the protocol buffer representation.- Parameters:
proto- The protobuf Typedvalue- Returns:
- A
TypedValueinstance
-
getSerialFromProto
public static Object getSerialFromProto(org.apache.calcite.avatica.proto.Common.TypedValue protoValue) Converts the serialized value into the appropriate primitive/object.- Parameters:
protoValue- The serialized TypedValue.- Returns:
- The appropriate concrete type for the parameter value (as an Object).
-
toProto
public static org.apache.calcite.avatica.proto.Common.Rep toProto(org.apache.calcite.avatica.proto.Common.TypedValue.Builder builder, Object o) Writes the given object into the Protobuf representation of a TypedValue. The object is serialized given the type of that object, mapping it to the appropriate representation.- Parameters:
builder- The TypedValue protobuf buildero- The object (value)
-
protoToJdbc
public static Object protoToJdbc(org.apache.calcite.avatica.proto.Common.TypedValue protoValue, Calendar calendar) Extracts the JDBC value from protobuf-TypedValue representation.- Parameters:
protoValue- Protobuf TypedValuecalendar- Instance of a calendar- Returns:
- The JDBC representation of this TypedValue
-
hashCode
public int hashCode() -
equals
-