Package org.apache.calcite.avatica.remote

# Class TypedValue

java.lang.Object
org.apache.calcite.avatica.remote.TypedValue

public class TypedValue extends Object
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.

SQL types and their representations
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 `Number` in serial format because JSON numbers are not strongly typed. A `float` value `3.0` is transmitted as `3`, and is therefore decoded as an `int`.
- The date-time types (DATE, TIME, TIMESTAMP) are represented in JDBC as `Date`, `Time`, `Timestamp`, all sub-classes of `Date`. 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 as `int` (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
`final ColumnMetaData.Rep`
`componentType`
Non-null for ARRAYs, the type of the values stored in the ARRAY.
`static final TypedValue`
`EXPLICIT_NULL`
`static final org.apache.calcite.avatica.proto.Common.TypedValue`
`PROTO_IMPLICIT_NULL`
`final ColumnMetaData.Rep`
`type`
Type of the value.
`final Object`
`value`
Value.

## Method Summary

Modifier and Type
Method
Description
`static TypedValue`
`create(String type, Object value)`
`boolean`
`equals(Object o)`
`static TypedValue`
`fromProto(org.apache.calcite.avatica.proto.Common.TypedValue proto)`
Constructs a `TypedValue` from the protocol buffer representation.
`static Object`
`getSerialFromProto(org.apache.calcite.avatica.proto.Common.TypedValue protoValue)`
Converts the serialized value into the appropriate primitive/object.
`int`
`hashCode()`
`static TypedValue`
`ofJdbc(Object value, Calendar calendar)`
Creates a TypedValue from a value in JDBC representation, deducing its type.
`static TypedValue`
`ofJdbc(ColumnMetaData.Rep rep, Object value, Calendar calendar)`
Creates a TypedValue from a value in JDBC representation.
`static TypedValue`
`ofLocal(ColumnMetaData.Rep rep, Object value)`
Creates a TypedValue from a value in local representation.
`static TypedValue`
`ofSerial(ColumnMetaData.Rep rep, Object value)`
Creates a TypedValue from a value in serial representation.
`static Object`
`protoToJdbc(org.apache.calcite.avatica.proto.Common.TypedValue protoValue, Calendar calendar)`
Extracts the JDBC value from protobuf-TypedValue representation.
`Object`
`toJdbc(Calendar calendar)`
Converts the value into the JDBC representation.
`Object`
`toLocal()`
Converts the value into the local representation.
`org.apache.calcite.avatica.proto.Common.TypedValue`
`toProto()`
Creates a protocol buffer equivalent object for `this`.
`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.
`static List<Object>`
`values(List<TypedValue> typedValues)`
Converts a list of `TypedValue` to a list of values.

### Methods inherited from class java.lang.Object

`clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait`

## Field Details

### EXPLICIT_NULL

public static final TypedValue EXPLICIT_NULL

### PROTO_IMPLICIT_NULL

public static final org.apache.calcite.avatica.proto.Common.TypedValue PROTO_IMPLICIT_NULL

### type

public final ColumnMetaData.Rep type
Type of the value.

### value

public final 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.

## Method Details

### create

public static TypedValue create(String type, Object value)

### ofLocal

public static TypedValue ofLocal(ColumnMetaData.Rep rep, Object value)
Creates a TypedValue from a value in local representation.

### ofSerial

public static TypedValue ofSerial(ColumnMetaData.Rep rep, Object value)
Creates a TypedValue from a value in serial representation.

### ofJdbc

public static TypedValue ofJdbc(ColumnMetaData.Rep rep, Object value, Calendar calendar)
Creates a TypedValue from a value in JDBC representation.

### ofJdbc

public static TypedValue ofJdbc(Object value, Calendar calendar)
Creates a TypedValue from a value in JDBC representation, deducing its type.

### toLocal

public Object toLocal()
Converts the value into the local representation.

For example, a byte string is represented as a `ByteString`; a long is represented as a `Long` (not just some `Number`).

### toJdbc

public Object toJdbc(Calendar calendar)
Converts the value into the JDBC representation.

For example, a byte string is represented as a `ByteString`; a long is represented as a `Long` (not just some `Number`).

### values

public static List<Object> values(List<TypedValue> typedValues)
Converts a list of `TypedValue` to a list of values.

### toProto

public org.apache.calcite.avatica.proto.Common.TypedValue toProto()
Creates a protocol buffer equivalent object for `this`.

Returns:
  A protobuf TypedValue equivalent for `this`

### fromProto

public static TypedValue fromProto(org.apache.calcite.avatica.proto.Common.TypedValue proto)
Constructs a `TypedValue` from the protocol buffer representation.

Parameters:
  `proto` - The protobuf Typedvalue
Returns:
  A `TypedValue` instance

### 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 builder
  `o` - 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 TypedValue
  `calendar` - Instance of a calendar
Returns:
  The JDBC representation of this TypedValue

### hashCode

public int hashCode()

Overrides:
  `hashCode` in class `Object`

### equals

public boolean equals(Object o)

Overrides:
  `equals` in class `Object`