Search in sources :

Example 6 with TupleValue

use of com.datastax.oss.driver.api.core.data.TupleValue in project java-driver by datastax.

the class TupleCodecTest method should_parse_full_tuple.

@Test
public void should_parse_full_tuple() {
    TupleValue tuple = parse("(1,NULL,'a')");
    assertThat(tuple.getInt(0)).isEqualTo(1);
    assertThat(tuple.isNull(1)).isTrue();
    assertThat(tuple.getString(2)).isEqualTo("a");
    verify(intCodec).parse("1");
    verify(doubleCodec).parse("NULL");
    verify(textCodec).parse("'a'");
}
Also used : DefaultTupleValue(com.datastax.oss.driver.internal.core.data.DefaultTupleValue) TupleValue(com.datastax.oss.driver.api.core.data.TupleValue) Test(org.junit.Test)

Example 7 with TupleValue

use of com.datastax.oss.driver.api.core.data.TupleValue in project java-driver by datastax.

the class DefaultTupleValueTest method should_serialize_and_deserialize.

@Test
public void should_serialize_and_deserialize() {
    DefaultTupleType type = new DefaultTupleType(ImmutableList.of(DataTypes.INT, DataTypes.TEXT), attachmentPoint);
    TupleValue in = type.newValue();
    in = in.setBytesUnsafe(0, Bytes.fromHexString("0x00000001"));
    in = in.setBytesUnsafe(1, Bytes.fromHexString("0x61"));
    TupleValue out = SerializationHelper.serializeAndDeserialize(in);
    assertThat(out.getType()).isEqualTo(in.getType());
    assertThat(out.getType().isDetached()).isTrue();
    assertThat(Bytes.toHexString(out.getBytesUnsafe(0))).isEqualTo("0x00000001");
    assertThat(Bytes.toHexString(out.getBytesUnsafe(1))).isEqualTo("0x61");
}
Also used : DefaultTupleType(com.datastax.oss.driver.internal.core.type.DefaultTupleType) TupleValue(com.datastax.oss.driver.api.core.data.TupleValue) Test(org.junit.Test)

Example 8 with TupleValue

use of com.datastax.oss.driver.api.core.data.TupleValue in project java-driver by datastax.

the class DefaultTupleValueTest method should_not_equate_instances_with_same_binary_representation_but_different_types.

@Test
public void should_not_equate_instances_with_same_binary_representation_but_different_types() {
    TupleType tupleType1 = DataTypes.tupleOf(DataTypes.INT);
    TupleType tupleType2 = DataTypes.tupleOf(DataTypes.VARINT);
    TupleValue tuple1 = tupleType1.newValue().setBytesUnsafe(0, Bytes.fromHexString("0x00000001"));
    TupleValue tuple2 = tupleType2.newValue().setBytesUnsafe(0, Bytes.fromHexString("0x00000001"));
    assertThat(tuple1).isNotEqualTo(tuple2);
}
Also used : TupleType(com.datastax.oss.driver.api.core.type.TupleType) DefaultTupleType(com.datastax.oss.driver.internal.core.type.DefaultTupleType) TupleValue(com.datastax.oss.driver.api.core.data.TupleValue) Test(org.junit.Test)

Example 9 with TupleValue

use of com.datastax.oss.driver.api.core.data.TupleValue in project java-driver by datastax.

the class DefaultTupleValue method equals.

@Override
public boolean equals(Object o) {
    if (this == o) {
        return true;
    }
    if (!(o instanceof TupleValue)) {
        return false;
    }
    TupleValue that = (TupleValue) o;
    if (!type.equals(that.getType())) {
        return false;
    }
    for (int i = 0; i < values.length; i++) {
        DataType innerThisType = type.getComponentTypes().get(i);
        DataType innerThatType = that.getType().getComponentTypes().get(i);
        if (!innerThisType.equals(innerThatType)) {
            return false;
        }
        Object thisValue = this.codecRegistry().codecFor(innerThisType).decode(this.getBytesUnsafe(i), this.protocolVersion());
        Object thatValue = that.codecRegistry().codecFor(innerThatType).decode(that.getBytesUnsafe(i), that.protocolVersion());
        if (!Objects.equals(thisValue, thatValue)) {
            return false;
        }
    }
    return true;
}
Also used : DataType(com.datastax.oss.driver.api.core.type.DataType) TupleValue(com.datastax.oss.driver.api.core.data.TupleValue)

Example 10 with TupleValue

use of com.datastax.oss.driver.api.core.data.TupleValue 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)

Aggregations

TupleValue (com.datastax.oss.driver.api.core.data.TupleValue)31 Test (org.junit.Test)18 DefaultTupleValue (com.datastax.oss.driver.internal.core.data.DefaultTupleValue)12 TupleType (com.datastax.oss.driver.api.core.type.TupleType)10 Row (com.datastax.oss.driver.api.core.cql.Row)6 UdtValue (com.datastax.oss.driver.api.core.data.UdtValue)5 DefaultTupleType (com.datastax.oss.driver.internal.core.type.DefaultTupleType)5 DataType (com.datastax.oss.driver.api.core.type.DataType)4 ByteBuffer (java.nio.ByteBuffer)4 ResultSet (com.datastax.oss.driver.api.core.cql.ResultSet)3 Nullable (edu.umd.cs.findbugs.annotations.Nullable)3 InetAddress (java.net.InetAddress)3 List (java.util.List)3 BoundStatement (com.datastax.oss.driver.api.core.cql.BoundStatement)2 PreparedStatement (com.datastax.oss.driver.api.core.cql.PreparedStatement)2 SimpleStatement (com.datastax.oss.driver.api.core.cql.SimpleStatement)2 UserDefinedType (com.datastax.oss.driver.api.core.type.UserDefinedType)2 CodecRegistry (com.datastax.oss.driver.api.core.type.codec.registry.CodecRegistry)2 UserDefinedTypeBuilder (com.datastax.oss.driver.internal.core.type.UserDefinedTypeBuilder)2 DataProvider (com.tngtech.java.junit.dataprovider.DataProvider)2