Class TypedValue
- java.lang.Object
-
- org.apache.calcite.avatica.remote.TypedValue
-
public class TypedValue extends java.lang.ObjectValue 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.
SQL types and their representations Type JDBC Serial Local BOOLEAN boolean boolean boolean BINARY, VARBINARY byte[] String (base64) ByteStringDATE Dateint int TIME Timeint int DATE Timestamplong 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
Fields Modifier and Type Field Description private static com.google.protobuf.Descriptors.FieldDescriptorBYTES_DESCRIPTORColumnMetaData.RepcomponentTypeNon-null for ARRAYs, the type of the values stored in the ARRAY.static TypedValueEXPLICIT_NULLprivate static com.google.protobuf.Descriptors.FieldDescriptorNUMBER_DESCRIPTORstatic Common.TypedValuePROTO_IMPLICIT_NULLprivate static com.google.protobuf.Descriptors.FieldDescriptorSTRING_DESCRIPTORColumnMetaData.ReptypeType of the value.java.lang.ObjectvalueValue.
-
Constructor Summary
Constructors Modifier Constructor Description privateTypedValue(ColumnMetaData.Rep rep, java.lang.Object value)privateTypedValue(ColumnMetaData.Rep rep, ColumnMetaData.Rep componentType, java.lang.Object value)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private static longadjust(java.lang.Number number, java.util.Calendar calendar)static TypedValuecreate(java.lang.String type, java.lang.Object value)booleanequals(java.lang.Object o)static TypedValuefromProto(Common.TypedValue proto)Constructs aTypedValuefrom the protocol buffer representation.static java.lang.ObjectgetSerialFromProto(Common.TypedValue protoValue)Converts the serialized value into the appropriate primitive/object.inthashCode()private booleanisSerial(ColumnMetaData.Rep rep, java.lang.Object value)private static java.lang.ObjectjdbcToSerial(ColumnMetaData.Rep rep, java.lang.Object value, java.util.Calendar calendar)private static java.lang.ObjectjdbcToSerial(ColumnMetaData.Rep rep, java.lang.Object value, java.util.Calendar calendar, SqlType componentType)Converts a value from JDBC format to a type that can be serialized as JSON.private static java.lang.ObjectlocalToSerial(ColumnMetaData.Rep rep, java.lang.Object value)Converts a value from internal format to a type that can be serialized as JSON.static TypedValueofJdbc(java.lang.Object value, java.util.Calendar calendar)Creates a TypedValue from a value in JDBC representation, deducing its type.static TypedValueofJdbc(ColumnMetaData.Rep rep, java.lang.Object value, java.util.Calendar calendar)Creates a TypedValue from a value in JDBC representation.static TypedValueofLocal(ColumnMetaData.Rep rep, java.lang.Object value)Creates a TypedValue from a value in local representation.static TypedValueofSerial(ColumnMetaData.Rep rep, java.lang.Object value)Creates a TypedValue from a value in serial representation.static java.lang.ObjectprotoToJdbc(Common.TypedValue protoValue, java.util.Calendar calendar)Extracts the JDBC value from protobuf-TypedValue representation.(package private) Common.TypedValueserializeArray(java.util.List<java.lang.Object> list, Common.TypedValue.Builder builder, Common.Rep protoArrayComponentRep)private static java.lang.ObjectserialToJdbc(ColumnMetaData.Rep type, ColumnMetaData.Rep componentRep, java.lang.Object value, java.util.Calendar calendar)Converts the given value from serial form to JDBC form.private static java.lang.ObjectserialToLocal(ColumnMetaData.Rep rep, java.lang.Object value)Converts a value to the exact type required for the given representation.java.lang.ObjecttoJdbc(java.util.Calendar calendar)Converts the value into the JDBC representation.java.lang.ObjecttoLocal()Converts the value into the local representation.Common.TypedValuetoProto()Creates a protocol buffer equivalent object forthis.static Common.ReptoProto(Common.TypedValue.Builder builder, java.lang.Object o)Writes the given object into the Protobuf representation of a TypedValue.static java.util.List<java.lang.Object>values(java.util.List<TypedValue> typedValues)Converts a list ofTypedValueto a list of values.private static voidwriteToProtoWithType(Common.TypedValue.Builder builder, java.lang.Object o, Common.Rep type)
-
-
-
Field Detail
-
NUMBER_DESCRIPTOR
private static final com.google.protobuf.Descriptors.FieldDescriptor NUMBER_DESCRIPTOR
-
STRING_DESCRIPTOR
private static final com.google.protobuf.Descriptors.FieldDescriptor STRING_DESCRIPTOR
-
BYTES_DESCRIPTOR
private static final com.google.protobuf.Descriptors.FieldDescriptor BYTES_DESCRIPTOR
-
EXPLICIT_NULL
public static final TypedValue EXPLICIT_NULL
-
PROTO_IMPLICIT_NULL
public static final Common.TypedValue PROTO_IMPLICIT_NULL
-
type
public final ColumnMetaData.Rep type
Type of the value.
-
value
public final java.lang.Object value
Value.Always in a form that can be serialized to JSON by Jackson. For example, byte arrays are represented as String.
-
componentType
public final ColumnMetaData.Rep componentType
Non-null for ARRAYs, the type of the values stored in the ARRAY. Null for all other cases.
-
-
Constructor Detail
-
TypedValue
private TypedValue(ColumnMetaData.Rep rep, java.lang.Object value)
-
TypedValue
private TypedValue(ColumnMetaData.Rep rep, ColumnMetaData.Rep componentType, java.lang.Object value)
-
-
Method Detail
-
isSerial
private boolean isSerial(ColumnMetaData.Rep rep, java.lang.Object value)
-
create
public static TypedValue create(java.lang.String type, java.lang.Object value)
-
ofLocal
public static TypedValue ofLocal(ColumnMetaData.Rep rep, java.lang.Object value)
Creates a TypedValue from a value in local representation.
-
ofSerial
public static TypedValue ofSerial(ColumnMetaData.Rep rep, java.lang.Object value)
Creates a TypedValue from a value in serial representation.
-
ofJdbc
public static TypedValue ofJdbc(ColumnMetaData.Rep rep, java.lang.Object value, java.util.Calendar calendar)
Creates a TypedValue from a value in JDBC representation.
-
ofJdbc
public static TypedValue ofJdbc(java.lang.Object value, java.util.Calendar calendar)
Creates a TypedValue from a value in JDBC representation, deducing its type.
-
toLocal
public java.lang.Object 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).
-
serialToLocal
private static java.lang.Object serialToLocal(ColumnMetaData.Rep rep, java.lang.Object value)
Converts a value to the exact type required for the given representation.
-
toJdbc
public java.lang.Object toJdbc(java.util.Calendar calendar)
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).
-
serialToJdbc
private static java.lang.Object serialToJdbc(ColumnMetaData.Rep type, ColumnMetaData.Rep componentRep, java.lang.Object value, java.util.Calendar calendar)
Converts the given value from serial form to JDBC form.- Parameters:
type- The type of the valuevalue- The valuecalendar- A calendar instance- Returns:
- The JDBC representation of the value.
-
adjust
private static long adjust(java.lang.Number number, java.util.Calendar calendar)
-
jdbcToSerial
private static java.lang.Object jdbcToSerial(ColumnMetaData.Rep rep, java.lang.Object value, java.util.Calendar calendar)
-
jdbcToSerial
private static java.lang.Object jdbcToSerial(ColumnMetaData.Rep rep, java.lang.Object value, java.util.Calendar calendar, SqlType componentType)
Converts a value from JDBC format to a type that can be serialized as JSON.
-
localToSerial
private static java.lang.Object localToSerial(ColumnMetaData.Rep rep, java.lang.Object value)
Converts a value from internal format to a type that can be serialized as JSON.
-
values
public static java.util.List<java.lang.Object> values(java.util.List<TypedValue> typedValues)
Converts a list ofTypedValueto a list of values.
-
toProto
public Common.TypedValue toProto()
Creates a protocol buffer equivalent object forthis.- Returns:
- A protobuf TypedValue equivalent for
this
-
serializeArray
Common.TypedValue serializeArray(java.util.List<java.lang.Object> list, Common.TypedValue.Builder builder, Common.Rep protoArrayComponentRep)
-
writeToProtoWithType
private static void writeToProtoWithType(Common.TypedValue.Builder builder, java.lang.Object o, Common.Rep type)
-
fromProto
public static TypedValue fromProto(Common.TypedValue proto)
Constructs aTypedValuefrom the protocol buffer representation.- Parameters:
proto- The protobuf Typedvalue- Returns:
- A
TypedValueinstance
-
getSerialFromProto
public static java.lang.Object getSerialFromProto(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 Common.Rep toProto(Common.TypedValue.Builder builder, java.lang.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 java.lang.Object protoToJdbc(Common.TypedValue protoValue, java.util.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()
- Overrides:
hashCodein classjava.lang.Object
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equalsin classjava.lang.Object
-
-