use of com.datastax.oss.driver.api.core.type.UserDefinedType in project java-driver by datastax.
the class DataTypeDetachableTest method attaching_udt_should_attach_all_of_its_subtypes.
@Test
public void attaching_udt_should_attach_all_of_its_subtypes() {
TupleType tuple = DataTypes.tupleOf(DataTypes.INT);
UserDefinedType udt = new UserDefinedTypeBuilder(CqlIdentifier.fromInternal("ks"), CqlIdentifier.fromInternal("type")).withField(CqlIdentifier.fromInternal("field1"), DataTypes.INT).withField(CqlIdentifier.fromInternal("field2"), tuple).build();
assertThat(tuple.isDetached()).isTrue();
assertThat(udt.isDetached()).isTrue();
udt.attach(attachmentPoint);
assertThat(tuple.isDetached()).isFalse();
}
use of com.datastax.oss.driver.api.core.type.UserDefinedType in project java-driver by datastax.
the class CassandraSchemaParser method parseVirtualKeyspace.
private KeyspaceMetadata parseVirtualKeyspace(AdminRow keyspaceRow) {
CqlIdentifier keyspaceId = CqlIdentifier.fromInternal(keyspaceRow.getString("keyspace_name"));
boolean durableWrites = MoreObjects.firstNonNull(keyspaceRow.getBoolean("durable_writes"), false);
Map<String, String> replicationOptions = Collections.emptyMap();
;
Map<CqlIdentifier, UserDefinedType> types = parseTypes(keyspaceId);
return new DefaultKeyspaceMetadata(keyspaceId, durableWrites, true, replicationOptions, types, parseVirtualTables(keyspaceId, types), Collections.emptyMap(), Collections.emptyMap(), Collections.emptyMap());
}
use of com.datastax.oss.driver.api.core.type.UserDefinedType in project java-driver by datastax.
the class CoreGraphDataTypeITBase method should_insert_and_retrieve_nested_UDTS_and_tuples.
@Test
public void should_insert_and_retrieve_nested_UDTS_and_tuples() {
CqlSession session = session();
// use CQL to create type for now because DSP-17567 is not in yet, so this is more stable
session.execute(String.format("CREATE TYPE %s.udt1(a int, b text)", graphName()));
session.execute(String.format("CREATE TYPE %s.udt2(" + "a int" + ", b text" + ", c frozen<udt1>" + ", mylist list<bigint>" + ", mytuple_withlist tuple<varchar, tuple<bigint, frozen<list<bigint>>>>" + ")", graphName()));
session.execute(String.format("CREATE TYPE %s.udt3(" + "a list<int>" + ", b set<float>" + ", c map<text, bigint>" + ", d list<frozen<list<double>>>" + ", e set<frozen<set<float>>>" + ", f list<frozen<tuple<int, text>>>" + ")", graphName()));
UserDefinedType udt1 = session.getMetadata().getKeyspace(graphName()).flatMap(keyspace -> keyspace.getUserDefinedType("udt1")).orElseThrow(IllegalStateException::new);
UdtValue udtValue1 = udt1.newValue(1, "2");
UserDefinedType udt2 = session.getMetadata().getKeyspace(graphName()).flatMap(keyspace -> keyspace.getUserDefinedType("udt2")).orElseThrow(IllegalStateException::new);
TupleType secondNested = tupleOf(BIGINT, listOf(BIGINT));
TupleType firstNested = tupleOf(TEXT, secondNested);
UdtValue udtValue2 = udt2.newValue(1, "2", udt1.newValue(3, "4"), ImmutableList.of(5L), firstNested.newValue("6", secondNested.newValue(7L, ImmutableList.of(8L))));
UserDefinedType udt3 = session.getMetadata().getKeyspace(graphName()).flatMap(keyspace -> keyspace.getUserDefinedType("udt3")).orElseThrow(IllegalStateException::new);
UdtValue udtValue3 = udt3.newValue(ImmutableList.of(1), ImmutableSet.of(2.1f), ImmutableMap.of("3", 4L), ImmutableList.of(ImmutableList.of(5.1d, 6.1d), ImmutableList.of(7.1d)), ImmutableSet.of(ImmutableSet.of(8.1f), ImmutableSet.of(9.1f)), ImmutableList.of(tupleOf(INT, TEXT).newValue(10, "11")));
Map<String, Object> properties = ImmutableMap.<String, Object>builder().put("frozen(typeOf('udt1'))", udtValue1).put("frozen(typeOf('udt2'))", udtValue2).put("frozen(typeOf('udt3'))", udtValue3).build();
int vertexID = 1;
String vertexLabel = "graphBinaryNestedTypes";
runTest(properties, vertexLabel, vertexID);
}
use of com.datastax.oss.driver.api.core.type.UserDefinedType in project java-driver by datastax.
the class GeometryIT method should_insert_as_field_in_udt.
/**
* Validates that a geometry value can be inserted as a field in a UDT and verifies that the UDT
* is stored correctly by retrieving it and ensuring it matches.
*/
@Test
@Ignore
public void should_insert_as_field_in_udt() {
UUID key = Uuids.random();
UserDefinedType udtType = sessionRule.session().getMetadata().getKeyspace(sessionRule.session().getKeyspace().orElseThrow(AssertionError::new)).flatMap(ks -> ks.getUserDefinedType(CqlIdentifier.fromInternal("udt1"))).orElseThrow(AssertionError::new);
assertThat(udtType).isNotNull();
UdtValue value = udtType.newValue();
value = value.set("g", sampleData.get(0), genericType);
PreparedStatement prepared = sessionRule.session().prepare("INSERT INTO tbl (k, u) values (?, ?)");
BoundStatement bs = prepared.boundStatementBuilder().setUuid(0, key).setUdtValue(1, value).build();
sessionRule.session().execute(bs);
ResultSet rs = sessionRule.session().execute(SimpleStatement.builder("SELECT k,u FROM tbl where k=?").addPositionalValues(key).build());
Row row = rs.iterator().next();
assertThat(row.getUuid("k")).isEqualTo(key);
assertThat(row.getUdtValue("u")).isEqualTo(value);
assertThat(row.getUdtValue(1)).isEqualTo(value);
}
use of com.datastax.oss.driver.api.core.type.UserDefinedType in project jnosql-diana-driver by eclipse.
the class CassandraConverter method get.
static Object get(ColumnDefinition definition, Row row) {
String name = definition.getName().asInternal();
final DataType type = definition.getType();
if (type instanceof UserDefinedType) {
return getUDT(definition, row.getUdtValue(name));
}
final TypeCodec<Object> codec = row.codecRegistry().codecFor(type);
return row.get(name, codec);
}
Aggregations