Search in sources :

Example 6 with ResultSet

use of com.google.api.ads.admanager.jaxws.v202205.ResultSet in project grpc-gcp-java by GoogleCloudPlatform.

the class SpannerTestCases method testRead.

void testRead() throws InterruptedException {
    System.out.println("\nTestRead");
    ManagedChannel channel = getChannel();
    SpannerBlockingStub stub = getBlockingStub(channel);
    Session session = stub.createSession(CreateSessionRequest.newBuilder().setDatabase(database).build());
    ReadRequest request = ReadRequest.newBuilder().setSession(session.getName()).setTable("small_table").setKeySet(KeySet.newBuilder().setAll(true).build()).addColumns("users").addColumns("firstname").addColumns("lastname").build();
    BlockingCall<ReadRequest, ResultSet> blockingCall = (ReadRequest req) -> stub.read(req);
    doTestBlocking(channel, request, blockingCall);
    stub.deleteSession(DeleteSessionRequest.newBuilder().setName(session.getName()).build());
    channel.shutdown().awaitTermination(5, TimeUnit.SECONDS);
}
Also used : SpannerBlockingStub(com.google.spanner.v1.SpannerGrpc.SpannerBlockingStub) PartialResultSet(com.google.spanner.v1.PartialResultSet) ResultSet(com.google.spanner.v1.ResultSet) ManagedChannel(io.grpc.ManagedChannel) GcpManagedChannel(com.google.grpc.gcp.GcpManagedChannel) Session(com.google.spanner.v1.Session) ReadRequest(com.google.spanner.v1.ReadRequest)

Example 7 with ResultSet

use of com.google.api.ads.admanager.jaxws.v202205.ResultSet in project stargate by stargate.

the class DefaultQueryInterceptor method interceptQuery.

@Override
public ResultMessage interceptQuery(CQLStatement statement, QueryState state, QueryOptions options, Map<String, ByteBuffer> customPayload, long queryStartNanoTime) {
    if (!isSystemLocalOrPeers(statement)) {
        return null;
    }
    SelectStatement selectStatement = (SelectStatement) statement;
    TableMetadata tableMetadata = StargateSystemKeyspace.Local;
    if (isSystemPeers(selectStatement))
        tableMetadata = StargateSystemKeyspace.Peers;
    else if (isSystemPeersV2(selectStatement))
        tableMetadata = StargateSystemKeyspace.PeersV2;
    SelectStatement interceptStatement = new SelectStatement(tableMetadata, selectStatement.bindVariables, selectStatement.parameters, selectStatement.getSelection(), selectStatement.getRestrictions(), false, null, null, null, null);
    ResultMessage.Rows rows = interceptStatement.execute(state, options, queryStartNanoTime);
    return new ResultMessage.Rows(new ResultSet(selectStatement.getResultMetadata(), rows.result.rows));
}
Also used : TableMetadata(org.apache.cassandra.schema.TableMetadata) SelectStatement(org.apache.cassandra.cql3.statements.SelectStatement) ResultSet(org.apache.cassandra.cql3.ResultSet) ResultMessage(org.apache.cassandra.transport.messages.ResultMessage)

Example 8 with ResultSet

use of com.google.api.ads.admanager.jaxws.v202205.ResultSet in project stargate by stargate.

the class ProxyProtocolQueryInterceptor method interceptQuery.

@Override
public Single<ResultMessage> interceptQuery(CQLStatement statement, QueryState state, QueryOptions options, Map<String, ByteBuffer> customPayload, long queryStartNanoTime) {
    // see DseConnection
    assert state.getClientState() instanceof StargateClientState;
    StargateClientState clientState = (StargateClientState) state.getClientState();
    if (!isSystemLocalOrPeers(statement) || !clientState.proxyDestinationAddress().isPresent()) {
        return wrapped.map(i -> i.interceptQuery(statement, state, options, customPayload, queryStartNanoTime)).orElse(null);
    }
    InetSocketAddress destinationAddress = clientState.proxyDestinationAddress().get();
    boolean isPrivateDestination = destinationAddress.getAddress().isSiteLocalAddress();
    // If the destination is private, we want to use the "source" address of the PROXY header.
    // We stored that in clientState.getRemoteAddress().
    InetAddress systemLocalAddress = isPrivateDestination ? clientState.getRemoteAddress().getAddress() : destinationAddress.getAddress();
    SelectStatement selectStatement = (SelectStatement) statement;
    List<List<ByteBuffer>> rows;
    String tableName = selectStatement.table();
    boolean isPrivateLocal = systemLocalAddress.isSiteLocalAddress();
    Set<InetAddress> peers = isPrivateLocal ? privatePeers : publicPeers;
    if (tableName.equals(PeersSystemView.NAME)) {
        rows = peers.isEmpty() ? Collections.emptyList() : Lists.newArrayListWithCapacity(peers.size() - 1);
        for (InetAddress peer : peers) {
            if (!peer.equals(systemLocalAddress)) {
                rows.add(buildRow(selectStatement.getResultMetadata(), peer, peers));
            }
        }
    } else {
        assert tableName.equals(LocalNodeSystemView.NAME);
        rows = Collections.singletonList(buildRow(selectStatement.getResultMetadata(), systemLocalAddress, peers));
    }
    ResultSet resultSet = new ResultSet(selectStatement.getResultMetadata(), rows);
    return Single.just(new ResultMessage.Rows(resultSet));
}
Also used : InetAddressType(org.apache.cassandra.db.marshal.InetAddressType) LoadingCache(com.datastax.oss.driver.shaded.guava.common.cache.LoadingCache) Arrays(java.util.Arrays) Strings(com.datastax.oss.driver.shaded.guava.common.base.Strings) LoggerFactory(org.slf4j.LoggerFactory) Security(java.security.Security) CQLStatement(org.apache.cassandra.cql3.CQLStatement) ByteBuffer(java.nio.ByteBuffer) InetAddress(java.net.InetAddress) Lists(com.datastax.oss.driver.shaded.guava.common.collect.Lists) SelectStatement(org.apache.cassandra.cql3.statements.SelectStatement) Map(java.util.Map) VisibleForTesting(com.datastax.oss.driver.shaded.guava.common.annotations.VisibleForTesting) StargateClientState(io.stargate.db.dse.impl.StargateClientState) DatabaseDescriptor(org.apache.cassandra.config.DatabaseDescriptor) StargateSystemKeyspace.isSystemLocalOrPeers(io.stargate.db.dse.impl.StargateSystemKeyspace.isSystemLocalOrPeers) StargateSystemKeyspace(io.stargate.db.dse.impl.StargateSystemKeyspace) BootstrapState(com.datastax.bdp.db.nodes.BootstrapState) QueryState(org.apache.cassandra.service.QueryState) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) UUID(java.util.UUID) InetSocketAddress(java.net.InetSocketAddress) Collectors(java.util.stream.Collectors) Executors(java.util.concurrent.Executors) Objects(java.util.Objects) List(java.util.List) Optional(java.util.Optional) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ServerError(org.apache.cassandra.stargate.transport.ServerError) ProductVersion(com.datastax.bdp.db.util.ProductVersion) PeersSystemView(com.datastax.bdp.db.nodes.virtual.PeersSystemView) SetType(org.apache.cassandra.db.marshal.SetType) ResultSet(org.apache.cassandra.cql3.ResultSet) QueryProcessor(org.apache.cassandra.cql3.QueryProcessor) Single(io.reactivex.Single) Int32Type(org.apache.cassandra.db.marshal.Int32Type) UTF8Type(org.apache.cassandra.db.marshal.UTF8Type) ResultMetadata(org.apache.cassandra.cql3.ResultSet.ResultMetadata) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) ProtocolVersion(org.apache.cassandra.transport.ProtocolVersion) LocalNodeSystemView(com.datastax.bdp.db.nodes.virtual.LocalNodeSystemView) ResultMessage(org.apache.cassandra.transport.messages.ResultMessage) Sets(com.datastax.oss.driver.shaded.guava.common.collect.Sets) Logger(org.slf4j.Logger) UnknownHostException(java.net.UnknownHostException) TimeUnit(java.util.concurrent.TimeUnit) UUIDType(org.apache.cassandra.db.marshal.UUIDType) EventListener(io.stargate.db.EventListener) Collections(java.util.Collections) QueryOptions(org.apache.cassandra.cql3.QueryOptions) InetSocketAddress(java.net.InetSocketAddress) ResultMessage(org.apache.cassandra.transport.messages.ResultMessage) SelectStatement(org.apache.cassandra.cql3.statements.SelectStatement) ResultSet(org.apache.cassandra.cql3.ResultSet) List(java.util.List) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) InetAddress(java.net.InetAddress) StargateClientState(io.stargate.db.dse.impl.StargateClientState)

Example 9 with ResultSet

use of com.google.api.ads.admanager.jaxws.v202205.ResultSet in project beam by apache.

the class SpannerChangeStreamErrorTest method mockTableExists.

private void mockTableExists() {
    Statement tableExistsStatement = Statement.of("SELECT t.table_name FROM information_schema.tables AS t WHERE t.table_catalog = '' AND t.table_schema = '' AND t.table_name = 'my-metadata-table'");
    ResultSetMetadata tableExistsResultSetMetadata = ResultSetMetadata.newBuilder().setRowType(StructType.newBuilder().addFields(Field.newBuilder().setName("table_name").setType(Type.newBuilder().setCode(TypeCode.STRING).build()).build()).build()).build();
    ResultSet tableExistsResultSet = ResultSet.newBuilder().addRows(ListValue.newBuilder().addValues(Value.newBuilder().setStringValue(TEST_TABLE).build()).build()).setMetadata(tableExistsResultSetMetadata).build();
    mockSpannerService.putStatementResult(StatementResult.query(tableExistsStatement, tableExistsResultSet));
}
Also used : Statement(com.google.cloud.spanner.Statement) ResultSetMetadata(com.google.spanner.v1.ResultSetMetadata) ResultSet(com.google.spanner.v1.ResultSet)

Example 10 with ResultSet

use of com.google.api.ads.admanager.jaxws.v202205.ResultSet in project beam by apache.

the class SpannerChangeStreamErrorTest method mockGetParentPartition.

private ResultSet mockGetParentPartition(Timestamp startTimestamp, Timestamp after3Seconds) {
    Statement getPartitionStatement = Statement.newBuilder("SELECT * FROM my-metadata-table WHERE PartitionToken = @partition").bind("partition").to("Parent0").build();
    ResultSet getPartitionResultSet = ResultSet.newBuilder().addRows(ListValue.newBuilder().addValues(Value.newBuilder().setStringValue("Parent0")).addValues(Value.newBuilder().setListValue(ListValue.newBuilder().build())).addValues(Value.newBuilder().setStringValue(startTimestamp.toString())).addValues(Value.newBuilder().setStringValue(after3Seconds.toString())).addValues(Value.newBuilder().setStringValue("500")).addValues(Value.newBuilder().setStringValue(State.CREATED.name())).addValues(Value.newBuilder().setStringValue(startTimestamp.toString())).addValues(Value.newBuilder().setStringValue(startTimestamp.toString())).addValues(Value.newBuilder().setNullValue(NullValue.NULL_VALUE).build()).addValues(Value.newBuilder().setNullValue(NullValue.NULL_VALUE).build()).addValues(Value.newBuilder().setNullValue(NullValue.NULL_VALUE).build()).build()).setMetadata(PARTITION_METADATA_RESULT_SET_METADATA).build();
    mockSpannerService.putStatementResult(StatementResult.query(getPartitionStatement, getPartitionResultSet));
    return getPartitionResultSet;
}
Also used : Statement(com.google.cloud.spanner.Statement) ResultSet(com.google.spanner.v1.ResultSet)

Aggregations

Test (org.junit.Test)37 ResultSet (com.google.spanner.v1.ResultSet)21 PartialResultSet (com.google.spanner.v1.PartialResultSet)14 ResultSet (com.google.api.ads.admanager.axis.v202108.ResultSet)12 ResultSet (com.google.api.ads.admanager.axis.v202111.ResultSet)12 ResultSet (com.google.api.ads.admanager.axis.v202202.ResultSet)12 ResultSet (com.google.api.ads.admanager.axis.v202205.ResultSet)12 Function (com.google.common.base.Function)10 StatementBuilder (com.google.api.ads.admanager.axis.utils.v202108.StatementBuilder)8 StatementBuilder (com.google.api.ads.admanager.axis.utils.v202111.StatementBuilder)8 StatementBuilder (com.google.api.ads.admanager.axis.utils.v202202.StatementBuilder)8 StatementBuilder (com.google.api.ads.admanager.axis.utils.v202205.StatementBuilder)8 PublisherQueryLanguageServiceInterface (com.google.api.ads.admanager.axis.v202108.PublisherQueryLanguageServiceInterface)8 PublisherQueryLanguageServiceInterface (com.google.api.ads.admanager.axis.v202111.PublisherQueryLanguageServiceInterface)8 PublisherQueryLanguageServiceInterface (com.google.api.ads.admanager.axis.v202202.PublisherQueryLanguageServiceInterface)8 PublisherQueryLanguageServiceInterface (com.google.api.ads.admanager.axis.v202205.PublisherQueryLanguageServiceInterface)8 Session (com.google.spanner.v1.Session)8 DateTime (org.joda.time.DateTime)8 ListValue (com.google.protobuf.ListValue)5 ResultSet (org.apache.cassandra.cql3.ResultSet)5