use of com.datastax.oss.driver.api.core.type.UserDefinedType in project java-driver by datastax.
the class DataTypeCqlNameParserTest method should_parse_top_level_user_type_as_shallow.
@Test
public void should_parse_top_level_user_type_as_shallow() {
UserDefinedType addressType = (UserDefinedType) parse("address");
assertThat(addressType).isInstanceOf(ShallowUserDefinedType.class);
assertThat(addressType.getKeyspace()).isEqualTo(KEYSPACE_ID);
assertThat(addressType.getName().asInternal()).isEqualTo("address");
assertThat(addressType.isFrozen()).isFalse();
UserDefinedType frozenAddressType = (UserDefinedType) parse("frozen<address>");
assertThat(frozenAddressType).isInstanceOf(ShallowUserDefinedType.class);
assertThat(frozenAddressType.getKeyspace()).isEqualTo(KEYSPACE_ID);
assertThat(frozenAddressType.getName().asInternal()).isEqualTo("address");
assertThat(frozenAddressType.isFrozen()).isTrue();
}
use of com.datastax.oss.driver.api.core.type.UserDefinedType in project java-driver by datastax.
the class DataTypeClassNameParserTest method should_make_a_frozen_copy_user_type_when_definition_already_available.
@Test
@UseDataProvider(location = TestDataProviders.class, value = "locales")
public void should_make_a_frozen_copy_user_type_when_definition_already_available(Locale locale) {
Locale def = Locale.getDefault();
try {
Locale.setDefault(locale);
UserDefinedType existing = mock(UserDefinedType.class);
parse("org.apache.cassandra.db.marshal.UserType(foo,70686f6e65," + "6e616d65:org.apache.cassandra.db.marshal.UTF8Type," + "6e756d626572:org.apache.cassandra.db.marshal.UTF8Type)", ImmutableMap.of(CqlIdentifier.fromInternal("phone"), existing));
verify(existing).copy(true);
} finally {
Locale.setDefault(def);
}
}
use of com.datastax.oss.driver.api.core.type.UserDefinedType in project java-driver by datastax.
the class UserDefinedTypeListParserTest method should_resolve_map_dependency.
@Test
public void should_resolve_map_dependency() {
UserDefinedTypeParser parser = new UserDefinedTypeParser(new DataTypeCqlNameParser(), context);
Map<CqlIdentifier, UserDefinedType> types = parser.parse(KEYSPACE_ID, mockTypeRow("ks", "a1", ImmutableList.of("bs"), ImmutableList.of("frozen<map<int, frozen<b>>>")), mockTypeRow("ks", "a2", ImmutableList.of("bs"), ImmutableList.of("frozen<map<frozen<b>, int>>")), mockTypeRow("ks", "b", ImmutableList.of("i"), ImmutableList.of("int")));
assertThat(types).hasSize(3);
UserDefinedType a1Type = types.get(CqlIdentifier.fromInternal("a1"));
UserDefinedType a2Type = types.get(CqlIdentifier.fromInternal("a2"));
UserDefinedType bType = types.get(CqlIdentifier.fromInternal("b"));
assertThat(((MapType) a1Type.getFieldTypes().get(0)).getValueType()).isEqualTo(bType);
assertThat(((MapType) a2Type.getFieldTypes().get(0)).getKeyType()).isEqualTo(bType);
}
use of com.datastax.oss.driver.api.core.type.UserDefinedType in project java-driver by datastax.
the class UserDefinedTypeListParserTest method should_parse_legacy_table.
@Test
public void should_parse_legacy_table() {
UserDefinedTypeParser parser = new UserDefinedTypeParser(new DataTypeClassNameParser(), context);
// no need to add a column for the address type, because in 2.2 UDTs are always fully redefined
// in column and field types (instead of referencing an existing type)
Map<CqlIdentifier, UserDefinedType> types = parser.parse(KEYSPACE_ID, PERSON_ROW_2_2);
assertThat(types).hasSize(1);
UserDefinedType personType = types.get(CqlIdentifier.fromInternal("person"));
assertThat(personType.getKeyspace().asInternal()).isEqualTo("ks");
assertThat(personType.getName().asInternal()).isEqualTo("person");
assertThat(personType.getFieldNames()).containsExactly(CqlIdentifier.fromInternal("first_name"), CqlIdentifier.fromInternal("last_name"), CqlIdentifier.fromInternal("address"));
assertThat(personType.getFieldTypes().get(0)).isEqualTo(DataTypes.TEXT);
assertThat(personType.getFieldTypes().get(1)).isEqualTo(DataTypes.TEXT);
UserDefinedType addressType = ((UserDefinedType) personType.getFieldTypes().get(2));
assertThat(addressType.getKeyspace().asInternal()).isEqualTo("ks");
assertThat(addressType.getName().asInternal()).isEqualTo("address");
assertThat(addressType.getFieldNames()).containsExactly(CqlIdentifier.fromInternal("street"), CqlIdentifier.fromInternal("zipcode"));
}
use of com.datastax.oss.driver.api.core.type.UserDefinedType in project java-driver by datastax.
the class UserDefinedTypeListParserTest method should_resolve_list_dependency.
@Test
public void should_resolve_list_dependency() {
UserDefinedTypeParser parser = new UserDefinedTypeParser(new DataTypeCqlNameParser(), context);
Map<CqlIdentifier, UserDefinedType> types = parser.parse(KEYSPACE_ID, mockTypeRow("ks", "a", ImmutableList.of("bs"), ImmutableList.of("frozen<list<frozen<b>>>")), mockTypeRow("ks", "b", ImmutableList.of("i"), ImmutableList.of("int")));
assertThat(types).hasSize(2);
UserDefinedType aType = types.get(CqlIdentifier.fromInternal("a"));
UserDefinedType bType = types.get(CqlIdentifier.fromInternal("b"));
assertThat(((ListType) aType.getFieldTypes().get(0)).getElementType()).isEqualTo(bType);
}
Aggregations