Search in sources :

Example 16 with DataType

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;
}
Also used : SetType(com.datastax.oss.driver.api.core.type.SetType) ListType(com.datastax.oss.driver.api.core.type.ListType) DataType(com.datastax.oss.driver.api.core.type.DataType) MapType(com.datastax.oss.driver.api.core.type.MapType)

Example 17 with DataType

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);
}
Also used : DefaultDseColumnMetadata(com.datastax.dse.driver.internal.core.metadata.schema.DefaultDseColumnMetadata) ColumnMetadata(com.datastax.oss.driver.api.core.metadata.schema.ColumnMetadata) DseColumnMetadata(com.datastax.dse.driver.api.core.metadata.schema.DseColumnMetadata) DefaultDseColumnMetadata(com.datastax.dse.driver.internal.core.metadata.schema.DefaultDseColumnMetadata) DseColumnMetadata(com.datastax.dse.driver.api.core.metadata.schema.DseColumnMetadata) ImmutableList(com.datastax.oss.driver.shaded.guava.common.collect.ImmutableList) DefaultDseTableMetadata(com.datastax.dse.driver.internal.core.metadata.schema.DefaultDseTableMetadata) CqlIdentifier(com.datastax.oss.driver.api.core.CqlIdentifier) ImmutableMap(com.datastax.oss.driver.shaded.guava.common.collect.ImmutableMap) DefaultDseColumnMetadata(com.datastax.dse.driver.internal.core.metadata.schema.DefaultDseColumnMetadata) RawColumn(com.datastax.oss.driver.internal.core.metadata.schema.parsing.RawColumn) DataType(com.datastax.oss.driver.api.core.type.DataType) ClusteringOrder(com.datastax.oss.driver.api.core.metadata.schema.ClusteringOrder)

Example 18 with DataType

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());
}
Also used : TupleType(com.datastax.oss.driver.api.core.type.TupleType) DataType(com.datastax.oss.driver.api.core.type.DataType) TupleValue(com.datastax.oss.driver.api.core.data.TupleValue)

Example 19 with DataType

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());
}
Also used : UdtValue(com.datastax.oss.driver.api.core.data.UdtValue) DataType(com.datastax.oss.driver.api.core.type.DataType) UserDefinedType(com.datastax.oss.driver.api.core.type.UserDefinedType)

Example 20 with DataType

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);
}
Also used : DataType(com.datastax.oss.driver.api.core.type.DataType)

Aggregations

DataType (com.datastax.oss.driver.api.core.type.DataType)73 NonNull (edu.umd.cs.findbugs.annotations.NonNull)21 CqlIdentifier (com.datastax.oss.driver.api.core.CqlIdentifier)19 SetType (com.datastax.oss.driver.api.core.type.SetType)10 ImmutableList (com.datastax.oss.driver.shaded.guava.common.collect.ImmutableList)10 ImmutableMap (com.datastax.oss.driver.shaded.guava.common.collect.ImmutableMap)10 UserDefinedType (com.datastax.oss.driver.api.core.type.UserDefinedType)9 CheckReturnValue (edu.umd.cs.findbugs.annotations.CheckReturnValue)9 ColumnMetadata (com.datastax.oss.driver.api.core.metadata.schema.ColumnMetadata)8 Map (java.util.Map)8 UdtValue (com.datastax.oss.driver.api.core.data.UdtValue)7 ClusteringOrder (com.datastax.oss.driver.api.core.metadata.schema.ClusteringOrder)7 ListType (com.datastax.oss.driver.api.core.type.ListType)7 MapType (com.datastax.oss.driver.api.core.type.MapType)7 TupleValue (com.datastax.oss.driver.api.core.data.TupleValue)6 Nullable (edu.umd.cs.findbugs.annotations.Nullable)6 UUID (java.util.UUID)6 TupleType (com.datastax.oss.driver.api.core.type.TupleType)5 CodecRegistry (com.datastax.oss.driver.api.core.type.codec.registry.CodecRegistry)5 List (java.util.List)5