Search in sources :

Example 31 with TupleType

use of com.datastax.oss.driver.api.core.type.TupleType in project java-driver by datastax.

the class CachingCodecRegistryTestDataProviders method tuplesWithCqlTypes.

@DataProvider
public static Object[][] tuplesWithCqlTypes() {
    TupleType tupleType1 = DataTypes.tupleOf(DataTypes.INT, DataTypes.TEXT);
    TupleType tupleType2 = DataTypes.tupleOf(DataTypes.INT, DataTypes.listOf(DataTypes.TEXT));
    TupleType tupleType3 = DataTypes.tupleOf(DataTypes.mapOf(tupleType1, tupleType2));
    TupleValue tupleValue1 = tupleType1.newValue(42, "foo");
    TupleValue tupleValue2 = tupleType2.newValue(42, ImmutableList.of("foo", "bar"));
    return new Object[][] { { tupleType1, tupleType1.newValue() }, { tupleType1, tupleValue1 }, { tupleType2, tupleType2.newValue() }, { tupleType2, tupleValue2 }, { tupleType3, tupleType3.newValue() }, { tupleType3, tupleType3.newValue(ImmutableMap.of(tupleValue1, tupleValue2)) } };
}
Also used : TupleType(com.datastax.oss.driver.api.core.type.TupleType) DefaultTupleValue(com.datastax.oss.driver.internal.core.data.DefaultTupleValue) TupleValue(com.datastax.oss.driver.api.core.data.TupleValue) DataProvider(com.tngtech.java.junit.dataprovider.DataProvider)

Example 32 with TupleType

use of com.datastax.oss.driver.api.core.type.TupleType in project java-driver by datastax.

the class TermTest method should_generate_literal_terms.

@Test
public void should_generate_literal_terms() {
    assertThat(literal(1)).hasCql("1");
    assertThat(literal("foo")).hasCql("'foo'");
    assertThat(literal(ImmutableList.of(1, 2, 3))).hasCql("[1,2,3]");
    TupleType tupleType = DataTypes.tupleOf(DataTypes.INT, DataTypes.TEXT);
    TupleValue tupleValue = tupleType.newValue().setInt(0, 1).setString(1, "foo");
    assertThat(literal(tupleValue)).hasCql("(1,'foo')");
    UserDefinedType udtType = new UserDefinedTypeBuilder(CqlIdentifier.fromCql("ks"), CqlIdentifier.fromCql("user")).withField(CqlIdentifier.fromCql("first_name"), DataTypes.TEXT).withField(CqlIdentifier.fromCql("last_name"), DataTypes.TEXT).build();
    UdtValue udtValue = udtType.newValue().setString("first_name", "Jane").setString("last_name", "Doe");
    assertThat(literal(udtValue)).hasCql("{first_name:'Jane',last_name:'Doe'}");
    assertThat(literal(null)).hasCql("NULL");
    assertThat(literal(Charsets.UTF_8, new CharsetCodec())).hasCql("'UTF-8'");
    assertThat(literal(Charsets.UTF_8, CharsetCodec.TEST_REGISTRY)).hasCql("'UTF-8'");
}
Also used : UdtValue(com.datastax.oss.driver.api.core.data.UdtValue) TupleType(com.datastax.oss.driver.api.core.type.TupleType) UserDefinedType(com.datastax.oss.driver.api.core.type.UserDefinedType) UserDefinedTypeBuilder(com.datastax.oss.driver.internal.core.type.UserDefinedTypeBuilder) CharsetCodec(com.datastax.oss.driver.api.querybuilder.CharsetCodec) TupleValue(com.datastax.oss.driver.api.core.data.TupleValue) Test(org.junit.Test)

Aggregations

TupleType (com.datastax.oss.driver.api.core.type.TupleType)32 Test (org.junit.Test)22 UserDefinedType (com.datastax.oss.driver.api.core.type.UserDefinedType)13 TupleValue (com.datastax.oss.driver.api.core.data.TupleValue)12 ListType (com.datastax.oss.driver.api.core.type.ListType)7 MapType (com.datastax.oss.driver.api.core.type.MapType)6 SetType (com.datastax.oss.driver.api.core.type.SetType)6 UdtValue (com.datastax.oss.driver.api.core.data.UdtValue)5 UserDefinedTypeBuilder (com.datastax.oss.driver.internal.core.type.UserDefinedTypeBuilder)5 ByteBuffer (java.nio.ByteBuffer)5 DataType (com.datastax.oss.driver.api.core.type.DataType)4 BigInteger (java.math.BigInteger)4 CustomType (com.datastax.oss.driver.api.core.type.CustomType)3 DefaultTupleValue (com.datastax.oss.driver.internal.core.data.DefaultTupleValue)3 LineString (com.datastax.dse.driver.api.core.data.geometry.LineString)2 Point (com.datastax.dse.driver.api.core.data.geometry.Point)2 Polygon (com.datastax.dse.driver.api.core.data.geometry.Polygon)2 Geo (com.datastax.dse.driver.api.core.graph.predicates.Geo)2 DseDataTypes (com.datastax.dse.driver.api.core.type.DseDataTypes)2 CqlIdentifier (com.datastax.oss.driver.api.core.CqlIdentifier)2