if (dataType.equals(DataType.set(firstArg))) { return row.getSet(i, firstCodec.getJavaType()); } else if (dataType.equals(DataType.list(firstArg))) { return row.getList(i, firstCodec.getJavaType()); } else {
return; } else if (DataType.Name.LIST.toString().equalsIgnoreCase(mainTypeString)) { DataType listType = DataType.list(firstParamType); statement.setList(paramIndex, (List) codecRegistry.codecFor(listType).parse(paramValue)); return;
/** * Returns the type of "not frozen" lists of {@code elementType} elements. * * <p>This is a shorthand for {@code list(elementType, false);}. * * @param elementType the type of the list elements. * @return the type of "not frozen" lists of {@code elementType} elements. */ public static CollectionType list(DataType elementType) { return list(elementType, false); }
/** * Returns the type of frozen lists of {@code elementType} elements. * * <p>This is a shorthand for {@code list(elementType, true);}. * * @param elementType the type of the list elements. * @return the type of frozen lists of {@code elementType} elements. */ public static CollectionType frozenList(DataType elementType) { return list(elementType, true); }
|| dataType.equals(DataType.list(firstArg))) { builder.name(columnDefinitions.getName(i)).type().unionOf().nullBuilder().endNull().and().array() .items(getUnionFieldType(getPrimitiveAvroTypeFromCassandraType(firstArg))).endUnion().noDefault();
private ListCodec(TypeCodec<T> eltCodec) { super( DataType.list(eltCodec.getCqlType()), TypeTokens.listOf(eltCodec.getJavaType()), eltCodec); }
@Test( groups = "unit", expectedExceptions = {IllegalArgumentException.class}) public void collectionElementTooLargeTest() throws Exception { DataType cqlType = DataType.list(DataType.text()); List<String> list = newArrayList(Strings.repeat("a", 65536)); TypeCodec<List<?>> codec = codecRegistry.codecFor(cqlType); codec.serialize(list, ProtocolVersion.V2); }
@Test( groups = "unit", expectedExceptions = {IllegalArgumentException.class}) public void collectionTooLargeTest() throws Exception { DataType cqlType = DataType.list(DataType.cint()); List<Integer> list = Collections.nCopies(65536, 1); TypeCodec<List<?>> codec = codecRegistry.codecFor(cqlType); codec.serialize(list, ProtocolVersion.V2); }
@Test(groups = "unit") public void parseFormatListTest() { String toParse = "['Foo','Bar','Foo''bar']"; List<String> toFormat = Arrays.asList("Foo", "Bar", "Foo'bar"); DataType dt = DataType.list(DataType.text()); assertEquals(codecRegistry.codecFor(dt).parse(toParse), toFormat); assertEquals(codecRegistry.codecFor(dt).format(toFormat), toParse); }
public void serializeDeserializeCollectionsTest(ProtocolVersion version) { List<String> l = Arrays.asList("foo", "bar"); DataType dt = DataType.list(DataType.text()); TypeCodec<List<String>> codec = codecRegistry.codecFor(dt); assertEquals(codec.deserialize(codec.serialize(l, version), version), l); try { DataType listOfBigint = DataType.list(DataType.bigint()); codec = codecRegistry.codecFor(listOfBigint); codec.serialize(l, version); fail("This should not have worked"); } catch (InvalidTypeException e) { /* That's what we want */ } } }
@Test(groups = "unit") public void testCustomList() throws Exception { DataType cqlType = list(CUSTOM_FOO); TypeCodec<List<?>> codec = codecRegistry.codecFor(cqlType); assertThat(codec).isNotNull().accepts(cqlType); }
protected ListVarcharToListListInteger() { super(DataType.list(DataType.varchar()), TypeTokens.listOf(TypeTokens.listOf(Integer.class))); }
@Test(groups = "unit") public void should_create_simple_table_with_list() throws Exception { // When SchemaStatement statement = createTable("test") .addPartitionKey("id", DataType.bigint()) .addColumn("friends", DataType.list(DataType.text())); // Then assertThat(statement.getQueryString()) .isEqualTo( "\n\tCREATE TABLE test(\n\t\t" + "id bigint,\n\t\t" + "friends list<text>,\n\t\t" + "PRIMARY KEY(id))"); }
@Test(groups = "unit") public void should_find_newly_registered_codec_by_cql_type() { // given CodecRegistry registry = new CodecRegistry(); TypeCodec<?> expected = mockCodec(list(text()), listOf(String.class)); registry.register(expected); // when TypeCodec<?> actual = registry.codecFor(list(text())); // then assertThat(actual).isNotNull().isSameAs(expected); }
@Test(groups = "unit") public void should_ignore_codec_colliding_with_already_generated_codec() { MemoryAppender logs = startCapturingLogs(); CodecRegistry registry = new CodecRegistry(); // Force generation of a list token from the default token registry.codecFor(list(cint()), listOf(Integer.class)); TypeCodec<?> newCodec = mockCodec(list(cint()), listOf(Integer.class)); registry.register(newCodec); assertThat(logs.getNext()).contains("Ignoring codec MockCodec"); assertThat(registry.codecFor(list(cint()), listOf(Integer.class))).isNotSameAs(newCodec); stopCapturingLogs(logs); }
@Test(groups = "unit") public void should_find_newly_registered_codec_by_cql_type_and_java_type() { // given CodecRegistry registry = new CodecRegistry(); TypeCodec<?> expected = mockCodec(list(text()), listOf(String.class)); registry.register(expected); // when TypeCodec<?> actual = registry.codecFor(list(text()), listOf(String.class)); // then assertThat(actual).isNotNull().isSameAs(expected); }
@Test(groups = "unit") public void should_create_derived_codecs_for_java_type_handled_by_custom_codec() { TypeCodec<?> newCodec = mockCodec(varchar(), of(StringBuilder.class)); CodecRegistry registry = new CodecRegistry().register(newCodec); // lookup by CQL type only returns default codec assertThat(registry.codecFor(list(varchar()))).doesNotAccept(listOf(StringBuilder.class)); assertThat(registry.codecFor(list(varchar()), listOf(StringBuilder.class))).isNotNull(); }
@Test(groups = "short") public void should_parse_tuple_types() { assertThat(parse("tuple<int,list<text>>", cluster(), null, null, null, false, false)) .isEqualTo(cluster().getMetadata().newTupleType(cint(), list(text()))); }
@Test(groups = "short") public void should_parse_frozen_collection_types() { assertThat(parse("frozen<list<int>>", cluster(), null, null, null, false, false)) .isEqualTo(list(cint(), true)); assertThat(parse("frozen<set<bigint>>", cluster(), null, null, null, false, false)) .isEqualTo(set(bigint(), true)); assertThat(parse("frozen<map<date,timeuuid>>", cluster(), null, null, null, false, false)) .isEqualTo(map(date(), timeuuid(), true)); }
@Test(groups = "short") public void should_parse_collection_types() { assertThat(parse("list<int>", cluster(), null, null, null, false, false)) .isEqualTo(list(cint())); assertThat(parse("set<bigint>", cluster(), null, null, null, false, false)) .isEqualTo(set(bigint())); assertThat(parse("map<date,timeuuid>", cluster(), null, null, null, false, false)) .isEqualTo(map(date(), timeuuid())); }