/** * Creates a tuple type given a list of types. * * @param types the types for the tuple type. * @return the newly created tuple type. */ public TupleType newTupleType(DataType... types) { return newTupleType(Arrays.asList(types)); }
shallowUserTypes)); return cluster.getMetadata().newTupleType(types);
@SuppressWarnings("deprecation") @Test(groups = "short") public void should_handle_collections_of_tuples() { String query; BuiltStatement statement; query = "UPDATE foo SET l=[(1,2)] WHERE k=1;"; TupleType tupleType = cluster().getMetadata().newTupleType(cint(), cint()); List<TupleValue> list = ImmutableList.of(tupleType.newValue(1, 2)); statement = update("foo").with(set("l", list)).where(eq("k", 1)); assertThat(statement.toString()).isEqualTo(query); } }
@Test(groups = "short") public void should_handle_tuple() throws Exception { String query = "INSERT INTO foo (k,x) VALUES (0,(1));"; TupleType tupleType = cluster().getMetadata().newTupleType(cint()); BuiltStatement insert = insertInto("foo").value("k", 0).value("x", tupleType.newValue(1)); assertEquals(insert.toString(), query); }
/** Helper method for creating nested tuples */ private TupleValue nestedTuplesCreatorHelper(int depth) { if (depth == 1) { TupleType baseTuple = cluster().getMetadata().newTupleType(DataType.cint()); return baseTuple.newValue(303); } else { TupleValue innerTuple = nestedTuplesCreatorHelper(depth - 1); TupleType t = cluster().getMetadata().newTupleType(innerTuple.getType()); return t.newValue(innerTuple); } }
@Test(groups = "short") public void simpleValueTest() throws Exception { TupleType t = cluster().getMetadata().newTupleType(DataType.cint(), DataType.text(), DataType.cfloat()); TupleValue v = t.newValue(); v.setInt(0, 1); v.setString(1, "a"); v.setFloat(2, 1.0f); assertEquals(v.getType().getComponentTypes().size(), 3); assertEquals(v.getType().getComponentTypes().get(0), DataType.cint()); assertEquals(v.getType().getComponentTypes().get(1), DataType.text()); assertEquals(v.getType().getComponentTypes().get(2), DataType.cfloat()); assertEquals(v.getInt(0), 1); assertEquals(v.getString(1), "a"); assertEquals(v.getFloat(2), 1.0f); assertEquals(TypeCodec.tuple(t).format(v), "(1,'a',1.0)"); }
case TUPLE: allcollectiontypes.setTupleValue( index, cluster().getMetadata().newTupleType(dataType).newValue(sampleElement));
/** * Creates a tuple type given a list of types. * * @param types the types for the tuple type. * @return the newly created tuple type. */ public TupleType newTupleType(DataType... types) { return newTupleType(Arrays.asList(types)); }
@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()))); }
private void setUpTupleTypes(Cluster cluster) { locationType = cluster.getMetadata().newTupleType(cfloat(), cfloat()); locationValue = locationType.newValue().setFloat(0, 37.387224f).setFloat(1, -121.9733837f); // insert a tuple of a different dimension partialLocationValueInserted = cluster.getMetadata().newTupleType(cfloat()).newValue().setFloat(0, 37.387224f); // retrieve the partial tuple with null missing values partialLocationValueRetrieved = locationType.newValue(37.387224f, null); location = new Location(37.387224f, -121.9733837f); partialLocation = new Location(37.387224f, 0.0f); }
@Test(groups = "short") public void simpleWriteReadTest() throws Exception { session().execute("USE " + keyspace); PreparedStatement ins = session().prepare("INSERT INTO t(k, v) VALUES (?, ?)"); PreparedStatement sel = session().prepare("SELECT * FROM t WHERE k=?"); TupleType t = cluster().getMetadata().newTupleType(DataType.cint(), DataType.text(), DataType.cfloat()); int k = 1; TupleValue v = t.newValue(1, "a", 1.0f); session().execute(ins.bind(k, v)); TupleValue v2 = session().execute(sel.bind(k)).one().getTupleValue("v"); assertEquals(v2, v); // Test simple statement interpolation k = 2; v = t.newValue(2, "b", 2.0f); session().execute("INSERT INTO t(k, v) VALUES (?, ?)", k, v); v2 = session().execute(sel.bind(k)).one().getTupleValue("v"); assertEquals(v2, v); }
/** * Validates that tuple values generated from an attached type (cluster-provided TupleType) and a * detached type (using TupleType.of) are the same. * * @since 2.2.0 */ @Test(groups = "short") public void detachedTupleTypeTest() { TupleType detachedType = TupleType.of( protocolVersion, CodecRegistry.DEFAULT_INSTANCE, DataType.cint(), DataType.text(), DataType.cfloat()); TupleValue detachedValue = detachedType.newValue(1, "hello", 2.0f); TupleType attachedType = cluster().getMetadata().newTupleType(DataType.cint(), DataType.text(), DataType.cfloat()); TupleValue attachedValue = attachedType.newValue(1, "hello", 2.0f); assertThat(detachedValue).isEqualTo(attachedValue); }
cluster() .getMetadata() .newTupleType(DataType.text(), DataType.cint(), DataType.uuid(), DataType.blob()); TupleValue v = t.newValue(null, null, null, null); userType.setTupleValue("b", v);
cluster() .getMetadata() .newTupleType(DataType.ascii(), DataType.cint(), DataType.cboolean()); TupleType t1 = cluster().getMetadata().newTupleType(DataType.ascii(), DataType.cint()); TupleValue partial = t1.newValue("bar", 456); TupleValue partionResult = t.newValue("bar", 456, null); TupleType t2 = cluster().getMetadata().newTupleType(DataType.ascii()); TupleValue subpartial = t2.newValue("zoo"); TupleValue subpartialResult = t.newValue("zoo", null, null);
cluster() .getMetadata() .newTupleType(cluster().getMetadata().newTupleType(cint()), map(cint(), cint())); FunctionMetadata function = keyspace.getFunction("complex", argumentType); assertThat(function).isNotNull();
@Test(groups = "short") public void should_ignore_case() { assertThat(parse("INT", cluster(), null, null, null, false, false)).isEqualTo(cint()); assertThat(parse("SET<BIGint>", cluster(), null, null, null, false, false)) .isEqualTo(set(bigint())); assertThat( parse("FROZEN<mAp<Date,Tuple<timeUUID>>>", cluster(), null, null, null, false, false)) .isEqualTo(map(date(), cluster().getMetadata().newTupleType(timeuuid()), true)); }
assertThat(b).hasField("f1", set(d)); assertThat(c).hasField("f1", map(e, d)); assertThat(d).hasField("f1", metadata.newTupleType(f, g, h)); assertThat(e).hasField("f1", list(g)); assertThat(f).hasField("f1", h);
@SuppressWarnings("deprecation") @Test(groups = "short") public void should_handle_collections_of_tuples() { String query; BuiltStatement statement; query = "UPDATE foo SET l=[(1,2)] WHERE k=1;"; TupleType tupleType = cluster().getMetadata().newTupleType(cint(), cint()); List<TupleValue> list = ImmutableList.of(tupleType.newValue(1, 2)); statement = update("foo").with(set("l", list)).where(eq("k", 1)); assertThat(statement.toString()).isEqualTo(query); } }
@Test(groups = "short") public void should_handle_tuple() throws Exception { String query = "INSERT INTO foo (k,x) VALUES (0,(1));"; TupleType tupleType = cluster().getMetadata().newTupleType(cint()); BuiltStatement insert = insertInto("foo").value("k", 0).value("x", tupleType.newValue(1)); assertEquals(insert.toString(), query); }
private void setUpTupleTypes(Cluster cluster) { locationType = cluster.getMetadata().newTupleType(cfloat(), cfloat()); locationValue = locationType.newValue().setFloat(0, 37.387224f).setFloat(1, -121.9733837f); // insert a tuple of a different dimension partialLocationValueInserted = cluster.getMetadata().newTupleType(cfloat()).newValue().setFloat(0, 37.387224f); // retrieve the partial tuple with null missing values partialLocationValueRetrieved = locationType.newValue(37.387224f, null); location = new Location(37.387224f, -121.9733837f); partialLocation = new Location(37.387224f, 0.0f); }