use of com.datastax.oss.driver.api.core.data.TupleValue in project java-driver by datastax.
the class DateRangeIT method should_allow_date_range_in_udt_and_tuple.
/**
* Validates that {@link DateRange} can be used in UDT and Tuple types.
*/
@Test
public void should_allow_date_range_in_udt_and_tuple() throws Exception {
CqlSession session = sessionRule.session();
String tableName = testName.getMethodName();
session.execute("CREATE TYPE IF NOT EXISTS test_udt (i int, range 'DateRangeType')");
session.execute(String.format("CREATE TABLE %s (k int PRIMARY KEY, u test_udt, uf frozen<test_udt>, " + "t tuple<'DateRangeType', int>, tf frozen<tuple<'DateRangeType', int>>)", tableName));
session.execute(String.format("INSERT INTO %s (k, u, uf, t, tf) VALUES (" + "1, " + "{i: 10, range: '[2000-01-01T10:15:30.003Z TO 2020-01-01T10:15:30.001Z]'}, " + "{i: 20, range: '[2000-01-01T10:15:30.003Z TO 2020-01-01T10:15:30.001Z]'}, " + "('[2000-01-01T10:15:30.003Z TO 2020-01-01T10:15:30.001Z]', 30), " + "('[2000-01-01T10:15:30.003Z TO 2020-01-01T10:15:30.001Z]', 40))", tableName));
DateRange expected = DateRange.parse("[2000-01-01T10:15:30.003Z TO 2020-01-01T10:15:30.001Z]");
List<Row> rows = session.execute("SELECT * FROM " + tableName).all();
assertThat(rows).hasSize(1);
UdtValue u = rows.get(0).get("u", UdtValue.class);
DateRange dateRange = u.get("range", DateRange.class);
assertThat(dateRange).isEqualTo(expected);
assertThat(u.getInt("i")).isEqualTo(10);
u = rows.get(0).get("uf", UdtValue.class);
dateRange = u.get("range", DateRange.class);
assertThat(dateRange).isEqualTo(expected);
assertThat(u.getInt("i")).isEqualTo(20);
TupleValue t = rows.get(0).get("t", TupleValue.class);
dateRange = t.get(0, DateRange.class);
assertThat(dateRange).isEqualTo(expected);
assertThat(t.getInt(1)).isEqualTo(30);
t = rows.get(0).get("tf", TupleValue.class);
dateRange = t.get(0, DateRange.class);
assertThat(dateRange).isEqualTo(expected);
assertThat(t.getInt(1)).isEqualTo(40);
}
use of com.datastax.oss.driver.api.core.data.TupleValue in project java-driver by datastax.
the class GeometryIT method should_insert_as_tuple.
/**
* Validates that geometry values can be inserted as a tuple and verifies that the tuple is stored
* correctly by retrieving it and ensuring it matches.
*/
@Test
@Ignore
public void should_insert_as_tuple() {
UUID key = Uuids.random();
PreparedStatement prepared = sessionRule.session().prepare("INSERT INTO tbl (k, t) values (?, ?)");
TupleType tupleType = (TupleType) prepared.getVariableDefinitions().get(1).getType();
TupleValue tuple = tupleType.newValue();
tuple = tuple.set(0, sampleData.get(0), genericType);
tuple = tuple.set(1, sampleData.get(1), genericType);
tuple = tuple.set(2, sampleData.get(2), genericType);
BoundStatement bs = prepared.boundStatementBuilder().setUuid(0, key).setTupleValue(1, tuple).build();
sessionRule.session().execute(bs);
ResultSet rs = sessionRule.session().execute(SimpleStatement.builder("SELECT k,t FROM tbl where k=?").addPositionalValues(key).build());
Row row = rs.iterator().next();
assertThat(row.getUuid("k")).isEqualTo(key);
assertThat(row.getTupleValue("t")).isEqualTo(tuple);
assertThat(row.getTupleValue(1)).isEqualTo(tuple);
}
use of com.datastax.oss.driver.api.core.data.TupleValue in project java-driver by datastax.
the class DefaultTupleValueTest method should_equate_instances_with_same_values_but_different_binary_representations.
@Test
public void should_equate_instances_with_same_values_but_different_binary_representations() {
TupleType tupleType = DataTypes.tupleOf(DataTypes.VARINT);
TupleValue tuple1 = tupleType.newValue().setBytesUnsafe(0, Bytes.fromHexString("0x01"));
TupleValue tuple2 = tupleType.newValue().setBytesUnsafe(0, Bytes.fromHexString("0x0001"));
assertThat(tuple1).isEqualTo(tuple2);
assertThat(tuple1.hashCode()).isEqualTo(tuple2.hashCode());
}
use of com.datastax.oss.driver.api.core.data.TupleValue in project java-driver by datastax.
the class DefaultTupleValueTest method should_equate_instances_with_different_protocol_versions.
@Test
public void should_equate_instances_with_different_protocol_versions() {
TupleType tupleType1 = DataTypes.tupleOf(DataTypes.TEXT);
tupleType1.attach(attachmentPoint);
// use the V3 attachmentPoint for type2
TupleType tupleType2 = DataTypes.tupleOf(DataTypes.TEXT);
tupleType2.attach(v3AttachmentPoint);
TupleValue tuple1 = tupleType1.newValue().setBytesUnsafe(0, Bytes.fromHexString("0x01"));
TupleValue tuple2 = tupleType2.newValue().setBytesUnsafe(0, Bytes.fromHexString("0x01"));
assertThat(tuple1).isEqualTo(tuple2);
}
use of com.datastax.oss.driver.api.core.data.TupleValue in project java-driver by datastax.
the class DefaultTupleValueTest method should_support_null_items_when_setting_in_bulk.
@Test
public void should_support_null_items_when_setting_in_bulk() {
DefaultTupleType type = new DefaultTupleType(ImmutableList.of(DataTypes.INT, DataTypes.TEXT), attachmentPoint);
when(codecRegistry.<Integer>codecFor(DataTypes.INT)).thenReturn(TypeCodecs.INT);
when(codecRegistry.codecFor(DataTypes.TEXT, "foo")).thenReturn(TypeCodecs.TEXT);
TupleValue value = type.newValue(null, "foo");
assertThat(value.isNull(0)).isTrue();
assertThat(value.getString(1)).isEqualTo("foo");
}
Aggregations