@Override public boolean isNull(int i) { return currentRow.isNull(i); } }
return row.isNull(col) ? null : row.getInt(col); if (row.isNull(col)) { throw new IllegalArgumentException("Can't cast null value from Cassandra table column '" + col + "' to " + "int value used in domain object model"); return row.isNull(col) ? null : row.getShort(col); if (row.isNull(col)) { throw new IllegalArgumentException("Can't cast null value from Cassandra table column '" + col + "' to " + "short value used in domain object model"); return row.isNull(col) ? null : row.getLong(col); if (row.isNull(col)) { throw new IllegalArgumentException("Can't cast null value from Cassandra table column '" + col + "' to " + "long value used in domain object model"); return row.isNull(col) ? null : row.getDouble(col); if (row.isNull(col)) { throw new IllegalArgumentException("Can't cast null value from Cassandra table column '" + col + "' to " + "double value used in domain object model"); return row.isNull(col) ? null : row.getBool(col); if (row.isNull(col)) { throw new IllegalArgumentException("Can't cast null value from Cassandra table column '" + col + "' to " + "boolean value used in domain object model");
public static String getColumnValueForCql(Row row, int i, CassandraType cassandraType) if (row.isNull(i)) { return null;
outStream.write(",".getBytes(charset)); if (row.isNull(i)) { outStream.write(("\"" + colName + "\"" + ":null").getBytes(charset)); } else {
public static NullableValue getColumnValueForPartitionKey(Row row, int i, CassandraType cassandraType, List<CassandraType> typeArguments) { Type nativeType = cassandraType.getNativeType(); if (row.isNull(i)) { return NullableValue.asNull(nativeType); } switch (cassandraType) { case ASCII: case TEXT: case VARCHAR: return NullableValue.of(nativeType, utf8Slice(row.getString(i))); case UUID: case TIMEUUID: return NullableValue.of(nativeType, utf8Slice(row.getUUID(i).toString())); default: return getColumnValue(row, i, cassandraType, typeArguments); } }
final DataType dataType = columnDefinitions.getType(i); if (row.isNull(i)) { rec.put(i, null); } else {
if (row.isNull(i)) { return NullableValue.asNull(nativeType);
private static void formatMissingOrNullColumn(Row peerRow, String columnName, StringBuilder sb) { if (!peerRow.getColumnDefinitions().contains(columnName)) sb.append(", missing ").append(columnName); else if (peerRow.isNull(columnName)) sb.append(", ").append(columnName).append("=null"); }
private static boolean isNullOrAbsent(Row row, String name) { return row.getColumnDefinitions().getIndexOf(name) < 0 || row.isNull(name); }
private boolean isValidPeer(Row peerRow, boolean logIfInvalid) { boolean isValid = isPeersV2 ? peerRow.getColumnDefinitions().contains("native_address") && peerRow.getColumnDefinitions().contains("native_port") && !peerRow.isNull("native_address") && !peerRow.isNull("native_port") : peerRow.getColumnDefinitions().contains("rpc_address") && !peerRow.isNull("rpc_address"); if (EXTENDED_PEER_CHECK) { isValid &= peerRow.getColumnDefinitions().contains("host_id") && !peerRow.isNull("host_id") && peerRow.getColumnDefinitions().contains("data_center") && !peerRow.isNull("data_center") && peerRow.getColumnDefinitions().contains("rack") && !peerRow.isNull("rack") && peerRow.getColumnDefinitions().contains("tokens") && !peerRow.isNull("tokens"); } if (!isValid && logIfInvalid) logger.warn( "Found invalid row in system.peers: {}. " + "This is likely a gossip or snitch issue, this host will be ignored.", formatInvalidPeer(peerRow)); return isValid; }
private static boolean checkSchemaAgreement(Connection connection, Cluster.Manager cluster) throws InterruptedException, ExecutionException { DefaultResultSetFuture peersFuture = new DefaultResultSetFuture( null, cluster.protocolVersion(), new Requests.Query(SELECT_SCHEMA_PEERS)); DefaultResultSetFuture localFuture = new DefaultResultSetFuture( null, cluster.protocolVersion(), new Requests.Query(SELECT_SCHEMA_LOCAL)); connection.write(peersFuture); connection.write(localFuture); Set<UUID> versions = new HashSet<UUID>(); Row localRow = localFuture.get().one(); if (localRow != null && !localRow.isNull("schema_version")) versions.add(localRow.getUUID("schema_version")); for (Row row : peersFuture.get()) { InetSocketAddress addr = nativeAddressForPeerHost(row, connection.address, cluster); if (addr == null || row.isNull("schema_version")) continue; Host peer = cluster.metadata.getHost(addr); if (peer != null && peer.isUp()) versions.add(row.getUUID("schema_version")); } logger.debug("Checking for schema agreement: versions are {}", versions); return versions.size() <= 1; }
kind = Kind.REGULAR; } else if (version.getMajor() < 3) { kind = row.isNull(KIND_V2) ? Kind.REGULAR : Kind.fromStringV2(row.getString(KIND_V2)); } else { kind = row.isNull(KIND_V3) ? Kind.REGULAR : Kind.fromStringV3(row.getString(KIND_V3)); position = row.isNull(COMPONENT_INDEX) ? 0 : row.getInt(COMPONENT_INDEX); if (row.getColumnDefinitions().contains(str) && !row.isNull(str)) c.indexColumns.put(str, row.getString(str));
@Test(groups = "short") public void executeTest() throws Exception { session() .execute( insertInto(TABLE1) .value("k", "k1") .value("t", "This is a test") .value("i", 3) .value("f", 0.42)); session().execute(update(TABLE1).with(set("t", "Another test")).where(eq("k", "k2"))); List<Row> rows = session().execute(select().from(TABLE1).where(in("k", "k1", "k2"))).all(); assertEquals(2, rows.size()); Row r1 = rows.get(0); assertEquals("k1", r1.getString("k")); assertEquals("This is a test", r1.getString("t")); assertEquals(3, r1.getInt("i")); assertFalse(r1.isNull("f")); Row r2 = rows.get(1); assertEquals("k2", r2.getString("k")); assertEquals("Another test", r2.getString("t")); assertTrue(r2.isNull("i")); assertTrue(r2.isNull("f")); }
@Test(groups = "short") @CassandraVersion( value = "2.0.9", description = "This will only work with C* 2.0.9 (CASSANDRA-7337)") public void casBatchTest() { PreparedStatement st = session().prepare("INSERT INTO test (k, v) VALUES (?, ?) IF NOT EXISTS"); BatchStatement batch = new BatchStatement(); batch.add(new SimpleStatement("INSERT INTO test (k, v) VALUES (?, ?)", "key1", 0)); batch.add(st.bind("key1", 1)); batch.add(st.bind("key1", 2)); assertEquals(3, batch.size()); ResultSet rs = session().execute(batch); Row r = rs.one(); assertTrue(!r.isNull("[applied]")); assertEquals(r.getBool("[applied]"), true); rs = session().execute(batch); r = rs.one(); assertTrue(!r.isNull("[applied]")); assertEquals(r.getBool("[applied]"), false); } }
/** * Tests that a tombstone is created when binding a null value to a column in a prepared * statement. * * @test_category prepared_statements:binding * @jira_ticket JAVA-777 * @since 2.2.0 */ @Test(groups = "long") public void should_create_tombstone_when_null_value_on_bound_statement() { PreparedStatement prepared = session().prepare("INSERT INTO " + SIMPLE_TABLE + " (k, i) VALUES (?, ?)"); BoundStatement st1 = prepared.bind(); st1.setString(0, "foo"); st1.setToNull(1); session().execute(st1); Statement st2 = new SimpleStatement("SELECT i from " + SIMPLE_TABLE + " where k = 'foo'"); st2.enableTracing(); ResultSet rows = session().execute(st2); assertThat(rows.one().isNull(0)).isTrue(); // sleep 10 seconds to make sure the trace will be complete Uninterruptibles.sleepUninterruptibly(10, TimeUnit.SECONDS); QueryTrace queryTrace = rows.getExecutionInfo().getQueryTrace(); assertEventsContain(queryTrace, "1 tombstone"); }
/** * Tests that a value that was previously set on a bound statement can be unset by name. This only * works from protocol V4 onwards. * * @test_category prepared_statements:binding * @jira_ticket JAVA-930 * @since 2.2.0 */ @Test(groups = "short") @CassandraVersion("2.2.0") public void should_unset_value_by_name() { PreparedStatement prepared = session().prepare("INSERT INTO " + SIMPLE_TABLE + " (k, i) VALUES (:k, :i)"); BoundStatement bound = prepared.bind(); bound.setString("k", "foo"); bound.setInt("i", 1234); bound.unset("i"); assertThat(bound.isSet("i")).isFalse(); session().execute(bound); ResultSet rows = session() .execute( new SimpleStatement("SELECT i from " + SIMPLE_TABLE + " where k = 'foo'") .enableTracing()); assertThat(rows.one().isNull("i")); // sleep 10 seconds to make sure the trace will be complete Uninterruptibles.sleepUninterruptibly(10, TimeUnit.SECONDS); QueryTrace queryTrace = rows.getExecutionInfo().getQueryTrace(); assertEventsContain(queryTrace, "0 tombstone"); }
/** * Tests that a value that was previously set on a bound statement can be unset by index. This * only works from protocol V4 onwards. * * @test_category prepared_statements:binding * @jira_ticket JAVA-930 * @since 2.2.0 */ @Test(groups = "short") @CassandraVersion("2.2.0") public void should_unset_value_by_index() { PreparedStatement prepared = session().prepare("INSERT INTO " + SIMPLE_TABLE + " (k, i) VALUES (?, ?)"); BoundStatement bound = prepared.bind(); bound.setString(0, "foo"); bound.setInt(1, 1234); bound.unset(1); assertThat(bound.isSet(1)).isFalse(); session().execute(bound); ResultSet rows = session() .execute( new SimpleStatement("SELECT i from " + SIMPLE_TABLE + " where k = 'foo'") .enableTracing()); assertThat(rows.one().isNull("i")); // sleep 10 seconds to make sure the trace will be complete Uninterruptibles.sleepUninterruptibly(10, TimeUnit.SECONDS); QueryTrace queryTrace = rows.getExecutionInfo().getQueryTrace(); assertEventsContain(queryTrace, "0 tombstone"); }
/** * Tests that a tombstone is created when binding a null value to a column in a batch statement. * * @test_category prepared_statements:binding * @jira_ticket JAVA-777 * @since 2.2.0 */ @Test(groups = "short") @CassandraVersion("2.0.0") public void should_create_tombstone_when_null_value_on_batch_statement() { PreparedStatement prepared = session().prepare("INSERT INTO " + SIMPLE_TABLE + " (k, i) VALUES (?, ?)"); BoundStatement st1 = prepared.bind(); st1.setString(0, "foo"); st1.setToNull(1); session().execute(new BatchStatement().add(st1)); Statement st2 = new SimpleStatement("SELECT i from " + SIMPLE_TABLE + " where k = 'foo'"); st2.enableTracing(); ResultSet rows = session().execute(st2); assertThat(rows.one().isNull(0)).isTrue(); // sleep 10 seconds to make sure the trace will be complete Uninterruptibles.sleepUninterruptibly(10, TimeUnit.SECONDS); QueryTrace queryTrace = rows.getExecutionInfo().getQueryTrace(); assertEventsContain(queryTrace, "1 tombstone"); }
assertThat(row.isNull("d")).isTrue();