use of com.datastax.oss.driver.api.core.type.DataType in project java-driver by datastax.
the class GettableByIndex method get.
/**
* Returns the {@code i}th value, converting it to the given Java type.
*
* <p>The {@link #codecRegistry()} will be used to look up a codec to handle the conversion.
*
* <p>If the target type is generic, use {@link #get(int, GenericType)} instead.
*
* @throws IndexOutOfBoundsException if the index is invalid.
* @throws CodecNotFoundException if no codec can perform the conversion.
*/
@Nullable
default <ValueT> ValueT get(int i, Class<ValueT> targetClass) {
// This is duplicated from the GenericType variant, because we want to give the codec registry
// a chance to process the unwrapped class directly, if it can do so in a more efficient way.
DataType cqlType = getType(i);
TypeCodec<ValueT> codec = codecRegistry().codecFor(cqlType, targetClass);
return get(i, codec);
}
use of com.datastax.oss.driver.api.core.type.DataType in project java-driver by datastax.
the class GettableByIndex method getFloat.
/**
* Returns the {@code i}th value as a Java primitive float.
*
* <p>By default, this works with CQL type {@code float}.
*
* <p>Note that, due to its signature, this method cannot return {@code null}. If the CQL value is
* {@code NULL}, it will return {@code 0.0}. If this doesn't work for you, either call {@link
* #isNull(int)} before calling this method, or use {@code get(i, Float.class)} instead.
*
* @throws IndexOutOfBoundsException if the index is invalid.
*/
default float getFloat(int i) {
DataType cqlType = getType(i);
TypeCodec<Float> codec = codecRegistry().codecFor(cqlType, Float.class);
if (codec instanceof PrimitiveFloatCodec) {
return ((PrimitiveFloatCodec) codec).decodePrimitive(getBytesUnsafe(i), protocolVersion());
} else {
Float value = get(i, codec);
return value == null ? 0 : value;
}
}
use of com.datastax.oss.driver.api.core.type.DataType in project java-driver by datastax.
the class GettableByIndex method getByte.
/**
* Returns the {@code i}th value as a Java primitive byte.
*
* <p>By default, this works with CQL type {@code tinyint}.
*
* <p>Note that, due to its signature, this method cannot return {@code null}. If the CQL value is
* {@code NULL}, it will return {@code 0}. If this doesn't work for you, either call {@link
* #isNull(int)} before calling this method, or use {@code get(i, Byte.class)} instead.
*
* @throws IndexOutOfBoundsException if the index is invalid.
*/
default byte getByte(int i) {
DataType cqlType = getType(i);
TypeCodec<Byte> codec = codecRegistry().codecFor(cqlType, Byte.class);
if (codec instanceof PrimitiveByteCodec) {
return ((PrimitiveByteCodec) codec).decodePrimitive(getBytesUnsafe(i), protocolVersion());
} else {
Byte value = get(i, codec);
return value == null ? 0 : value;
}
}
use of com.datastax.oss.driver.api.core.type.DataType in project java-driver by datastax.
the class FunctionSignature method toString.
@Override
public String toString() {
StringBuilder builder = new StringBuilder(name.asInternal()).append('(');
boolean first = true;
for (DataType type : parameterTypes) {
if (first) {
first = false;
} else {
builder.append(", ");
}
builder.append(type.asCql(true, true));
}
return builder.append(')').toString();
}
use of com.datastax.oss.driver.api.core.type.DataType in project java-driver by datastax.
the class TableParser method parseVirtualTable.
TableMetadata parseVirtualTable(AdminRow tableRow, CqlIdentifier keyspaceId, Map<CqlIdentifier, UserDefinedType> userTypes) {
CqlIdentifier tableId = CqlIdentifier.fromInternal(tableRow.getString("table_name"));
List<RawColumn> rawColumns = RawColumn.toRawColumns(rows.virtualColumns().getOrDefault(keyspaceId, ImmutableMultimap.of()).get(tableId));
if (rawColumns.isEmpty()) {
LOG.warn("[{}] Processing TABLE refresh for {}.{} but found no matching rows, skipping", logPrefix, keyspaceId, tableId);
return null;
}
Collections.sort(rawColumns);
ImmutableMap.Builder<CqlIdentifier, ColumnMetadata> allColumnsBuilder = ImmutableMap.builder();
ImmutableList.Builder<ColumnMetadata> partitionKeyBuilder = ImmutableList.builder();
ImmutableMap.Builder<ColumnMetadata, ClusteringOrder> clusteringColumnsBuilder = ImmutableMap.builder();
for (RawColumn raw : rawColumns) {
DataType dataType = rows.dataTypeParser().parse(keyspaceId, raw.dataType, userTypes, context);
ColumnMetadata column = new DefaultColumnMetadata(keyspaceId, tableId, raw.name, dataType, raw.kind.equals(RawColumn.KIND_STATIC));
switch(raw.kind) {
case RawColumn.KIND_PARTITION_KEY:
partitionKeyBuilder.add(column);
break;
case RawColumn.KIND_CLUSTERING_COLUMN:
clusteringColumnsBuilder.put(column, raw.reversed ? ClusteringOrder.DESC : ClusteringOrder.ASC);
break;
default:
}
allColumnsBuilder.put(column.getName(), column);
}
return new DefaultTableMetadata(keyspaceId, tableId, null, false, true, partitionKeyBuilder.build(), clusteringColumnsBuilder.build(), allColumnsBuilder.build(), Collections.emptyMap(), Collections.emptyMap());
}
Aggregations