@Override public boolean advanceNextPosition() { if (!rs.isExhausted()) { currentRow = rs.one(); count++; return true; } return false; }
@Override public boolean isNull(int i) { return currentRow.isNull(i); } }
@Override public VersionNumber getCassandraVersion() { ResultSet result = executeWithSession(session -> session.execute("select release_version from system.local")); Row versionRow = result.one(); if (versionRow == null) { throw new PrestoException(CASSANDRA_VERSION_ERROR, "The cluster version is not available. " + "Please make sure that the Cassandra cluster is up and running, " + "and that the contact points are specified correctly."); } return VersionNumber.parse(versionRow.getString("release_version")); }
@Override protected Cluster buildCluster(Cluster.Builder builder) { return builder.addContactPoint(host).withPort(port).build(); } };
public TestHost(InetSocketAddress address) { super(address, new ConvictionPolicy.DefaultConvictionPolicy.Factory(), Cluster.builder().addContactPoints("localhost").build().manager); } }
private void checkSizeEstimatesTableExist() { KeyspaceMetadata keyspaceMetadata = executeWithSession(session -> session.getCluster().getMetadata().getKeyspace(SYSTEM)); checkState(keyspaceMetadata != null, "system keyspace metadata must not be null"); TableMetadata table = keyspaceMetadata.getTable(SIZE_ESTIMATES); if (table == null) { throw new PrestoException(NOT_SUPPORTED, "Cassandra versions prior to 2.1.5 are not supported"); } }
@Override public List<String> getCaseSensitiveSchemaNames() { ImmutableList.Builder<String> builder = ImmutableList.builder(); List<KeyspaceMetadata> keyspaces = executeWithSession(session -> session.getCluster().getMetadata().getKeyspaces()); for (KeyspaceMetadata meta : keyspaces) { builder.add(meta.getName()); } return builder.build(); }
@Override public Set<Host> getReplicas(String caseSensitiveSchemaName, TokenRange tokenRange) { requireNonNull(caseSensitiveSchemaName, "keyspace is null"); requireNonNull(tokenRange, "tokenRange is null"); return executeWithSession(session -> session.getCluster().getMetadata().getReplicas(validSchemaName(caseSensitiveSchemaName), tokenRange)); }
@Override public Set<TokenRange> getTokenRanges() { return executeWithSession(session -> session.getCluster().getMetadata().getTokenRanges()); }
@Override public String getPartitioner() { return executeWithSession(session -> session.getCluster().getMetadata().getPartitioner()); }
@Override protected Session createSession() { return cluster.connect(keyspace); }
@Override public ListenableFuture<ResultSet> send(IN value) { Object[] fields = extract(value); return session.executeAsync(ps.bind(fields)); }
@Override public synchronized void close() { closed = true; if (delegate != null) { delegate.close(); delegate = null; } }
@Override public boolean getBoolean(int i) { return currentRow.getBool(i); }
public static Row createSingleStringRow(String value, int protocolVersion) { ColumnDefinitions definitions = new ColumnDefinitions(new Definition[] {new Definition("keyspace", "table", "column", DataType.ascii())}, CodecRegistry.DEFAULT_INSTANCE); ByteBuffer data = ByteBuffer.wrap(value.getBytes(UTF_8)); return ArrayBackedRow.fromData(definitions, null, ProtocolVersion.fromInt(protocolVersion), ImmutableList.of(data)); } }
@Override public boolean reachedEnd() throws IOException { return resultSet.isExhausted(); }
// based on the above keyspace, we would change the cluster and session as follows: Cluster cluster = Cluster.builder() .addContactPoints(serverIP) .build(); Session session = cluster.connect("myfirstcassandradb"); String cqlStatement = "CREATE TABLE users (" + " user_name varchar PRIMARY KEY," + " password varchar " + ");"; session.execute(cqlStatement);
@Override public Set<Host> getReplicas(String caseSensitiveSchemaName, ByteBuffer partitionKey) { requireNonNull(caseSensitiveSchemaName, "keyspace is null"); requireNonNull(partitionKey, "partitionKey is null"); return executeWithSession(session -> session.getCluster().getMetadata().getReplicas(validSchemaName(caseSensitiveSchemaName), partitionKey)); }