use of com.datastax.oss.driver.api.core.type.UserDefinedType in project java-driver by datastax.
the class DataTypeClassNameParserTest method should_parse_user_type_when_definition_not_already_available.
@Test
@UseDataProvider(location = TestDataProviders.class, value = "locales")
public void should_parse_user_type_when_definition_not_already_available(Locale locale) {
Locale def = Locale.getDefault();
try {
Locale.setDefault(locale);
UserDefinedType addressType = (UserDefinedType) parse("org.apache.cassandra.db.marshal.UserType(" + "foo,61646472657373," + ("737472656574:org.apache.cassandra.db.marshal.UTF8Type," + "7a6970636f6465:org.apache.cassandra.db.marshal.Int32Type," + ("70686f6e6573:org.apache.cassandra.db.marshal.SetType(" + "org.apache.cassandra.db.marshal.UserType(foo,70686f6e65," + "6e616d65:org.apache.cassandra.db.marshal.UTF8Type," + "6e756d626572:org.apache.cassandra.db.marshal.UTF8Type)") + "))"));
assertThat(addressType.getKeyspace().asInternal()).isEqualTo("foo");
assertThat(addressType.getName().asInternal()).isEqualTo("address");
assertThat(addressType.isFrozen()).isTrue();
assertThat(addressType.getFieldNames().size()).isEqualTo(3);
assertThat(addressType.getFieldNames().get(0).asInternal()).isEqualTo("street");
assertThat(addressType.getFieldTypes().get(0)).isEqualTo(DataTypes.TEXT);
assertThat(addressType.getFieldNames().get(1).asInternal()).isEqualTo("zipcode");
assertThat(addressType.getFieldTypes().get(1)).isEqualTo(DataTypes.INT);
assertThat(addressType.getFieldNames().get(2).asInternal()).isEqualTo("phones");
DataType phonesType = addressType.getFieldTypes().get(2);
assertThat(phonesType).isInstanceOf(SetType.class);
UserDefinedType phoneType = ((UserDefinedType) ((SetType) phonesType).getElementType());
assertThat(phoneType.getKeyspace().asInternal()).isEqualTo("foo");
assertThat(phoneType.getName().asInternal()).isEqualTo("phone");
assertThat(phoneType.isFrozen()).isTrue();
assertThat(phoneType.getFieldNames().size()).isEqualTo(2);
assertThat(phoneType.getFieldNames().get(0).asInternal()).isEqualTo("name");
assertThat(phoneType.getFieldTypes().get(0)).isEqualTo(DataTypes.TEXT);
assertThat(phoneType.getFieldNames().get(1).asInternal()).isEqualTo("number");
assertThat(phoneType.getFieldTypes().get(1)).isEqualTo(DataTypes.TEXT);
} 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_nested_dependency.
@Test
public void should_resolve_nested_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<tuple<int, 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"));
TupleType tupleType = (TupleType) aType.getFieldTypes().get(0);
ListType listType = (ListType) tupleType.getComponentTypes().get(1);
assertThat(listType.getElementType()).isEqualTo(bType);
}
use of com.datastax.oss.driver.api.core.type.UserDefinedType in project java-driver by datastax.
the class UserDefinedTypeListParserTest method should_parse_singleton_list.
@Test
public void should_parse_singleton_list() {
UserDefinedTypeParser parser = new UserDefinedTypeParser(new DataTypeCqlNameParser(), context);
Map<CqlIdentifier, UserDefinedType> types = parser.parse(KEYSPACE_ID, mockTypeRow("ks", "t", ImmutableList.of("i"), ImmutableList.of("int")));
assertThat(types).hasSize(1);
UserDefinedType type = types.get(CqlIdentifier.fromInternal("t"));
assertThat(type.getKeyspace().asInternal()).isEqualTo("ks");
assertThat(type.getName().asInternal()).isEqualTo("t");
assertThat(type.getFieldNames()).containsExactly(CqlIdentifier.fromInternal("i"));
assertThat(type.getFieldTypes()).containsExactly(DataTypes.INT);
}
use of com.datastax.oss.driver.api.core.type.UserDefinedType in project java-driver by datastax.
the class UserDefinedTypeListParserTest method should_resolve_set_dependency.
@Test
public void should_resolve_set_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<set<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(((SetType) aType.getFieldTypes().get(0)).getElementType()).isEqualTo(bType);
}
use of com.datastax.oss.driver.api.core.type.UserDefinedType in project java-driver by datastax.
the class UserDefinedTypeListParserTest method should_parse_modern_table.
@Test
public void should_parse_modern_table() {
UserDefinedTypeParser parser = new UserDefinedTypeParser(new DataTypeCqlNameParser(), context);
Map<CqlIdentifier, UserDefinedType> types = parser.parse(KEYSPACE_ID, PERSON_ROW_3_0, ADDRESS_ROW_3_0);
assertThat(types).hasSize(2);
UserDefinedType personType = types.get(CqlIdentifier.fromInternal("person"));
UserDefinedType addressType = types.get(CqlIdentifier.fromInternal("address"));
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);
assertThat(personType.getFieldTypes().get(2)).isSameAs(addressType);
}
Aggregations