use of com.datastax.oss.driver.api.core.type.DataType in project java-driver by datastax.
the class DseTableParser method buildLegacyIndexTarget.
private static String buildLegacyIndexTarget(ColumnMetadata column, Map<String, String> options) {
String columnName = column.getName().asCql(true);
DataType columnType = column.getType();
if (options.containsKey("index_keys")) {
return String.format("keys(%s)", columnName);
}
if (options.containsKey("index_keys_and_values")) {
return String.format("entries(%s)", columnName);
}
if ((columnType instanceof ListType && ((ListType) columnType).isFrozen()) || (columnType instanceof SetType && ((SetType) columnType).isFrozen()) || (columnType instanceof MapType && ((MapType) columnType).isFrozen())) {
return String.format("full(%s)", columnName);
}
// Note: the keyword 'values' is not accepted as a valid index target function until 3.0
return columnName;
}
use of com.datastax.oss.driver.api.core.type.DataType in project java-driver by datastax.
the class DseTableParser method parseVirtualTable.
DseTableMetadata parseVirtualTable(AdminRow tableRow, CqlIdentifier keyspaceId) {
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, Collections.emptyMap(), context);
DseColumnMetadata column = new DefaultDseColumnMetadata(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 DefaultDseTableMetadata(keyspaceId, tableId, null, false, true, partitionKeyBuilder.build(), clusteringColumnsBuilder.build(), allColumnsBuilder.build(), Collections.emptyMap(), Collections.emptyMap(), null, null);
}
use of com.datastax.oss.driver.api.core.type.DataType in project java-driver by datastax.
the class TupleValueSerializer method readDynamicCustomValue.
@Override
public TupleValue readDynamicCustomValue(Buffer buffer, GraphBinaryReader context) throws IOException {
// read the type first
DataType type = ComplexTypeSerializerUtil.decodeTypeDefinition(buffer, driverContext);
assert type instanceof TupleType : "GraphBinary TupleValue deserializer was called on a value that is not encoded as a TupleValue.";
TupleType tupleType = (TupleType) type;
TupleValue value = tupleType.newValue();
// then decode the values from the buffer
return ComplexTypeSerializerUtil.decodeValue(buffer, value, tupleType.getComponentTypes().size());
}
use of com.datastax.oss.driver.api.core.type.DataType in project java-driver by datastax.
the class UdtValueSerializer method readDynamicCustomValue.
@Override
public UdtValue readDynamicCustomValue(Buffer buffer, GraphBinaryReader context) throws IOException {
// read type definition first
DataType driverType = ComplexTypeSerializerUtil.decodeTypeDefinition(buffer, driverContext);
assert driverType instanceof UserDefinedType : "GraphBinary UdtValue deserializer was called on a value that is not encoded as a UdtValue.";
UserDefinedType userDefinedType = (UserDefinedType) driverType;
UdtValue value = userDefinedType.newValue();
// then read values
return ComplexTypeSerializerUtil.decodeValue(buffer, value, userDefinedType.getFieldTypes().size());
}
use of com.datastax.oss.driver.api.core.type.DataType in project java-driver by datastax.
the class DataTypeSerializationTest method should_serialize_and_deserialize.
private void should_serialize_and_deserialize(DataType in, boolean expectDetached) {
// When
DataType out = SerializationHelper.serializeAndDeserialize(in);
// Then
assertThat(out).isEqualTo(in);
assertThat(out.isDetached()).isEqualTo(expectDetached);
}
Aggregations