Search in sources :

Example 11 with Partition

use of com.google.spanner.v1.Partition in project SQLWindowing by hbutani.

the class PTFOperator method processMapFunction.

protected void processMapFunction() throws HiveException {
    try {
        TableFuncDef tDef = RuntimeUtils.getFirstTableFunction(qDef);
        Partition outPart = tDef.getFunction().transformRawInput(inputPart);
        PartitionIterator<Object> pItr = outPart.iterator();
        while (pItr.hasNext()) {
            Object oRow = pItr.next();
            forward(oRow, outputObjInspector);
        }
    } catch (WindowingException we) {
        throw new HiveException("Cannot close PTFOperator.", we);
    }
}
Also used : Partition(com.sap.hadoop.windowing.runtime2.Partition) HiveException(org.apache.hadoop.hive.ql.metadata.HiveException) WindowingException(com.sap.hadoop.windowing.WindowingException) TableFuncDef(com.sap.hadoop.windowing.query2.definition.TableFuncDef)

Example 12 with Partition

use of com.google.spanner.v1.Partition in project java-spanner by googleapis.

the class DatabaseClientImplTest method testBackendPartitionQueryOptions.

@Test
public void testBackendPartitionQueryOptions() {
    // from the session pool interfering with the test case.
    try (Spanner spanner = SpannerOptions.newBuilder().setProjectId("[PROJECT]").setChannelProvider(channelProvider).setCredentials(NoCredentials.getInstance()).setSessionPoolOption(SessionPoolOptions.newBuilder().setMinSessions(0).build()).build().getService()) {
        BatchClient client = spanner.getBatchClient(DatabaseId.of("[PROJECT]", "[INSTANCE]", "[DATABASE"));
        BatchReadOnlyTransaction transaction = client.batchReadOnlyTransaction(TimestampBound.strong());
        List<Partition> partitions = transaction.partitionQuery(PartitionOptions.newBuilder().setMaxPartitions(10L).build(), Statement.newBuilder(SELECT1.getSql()).withQueryOptions(QueryOptions.newBuilder().setOptimizerVersion("1").setOptimizerStatisticsPackage("custom-package").build()).build());
        try (ResultSet rs = transaction.execute(partitions.get(0))) {
            // Just iterate over the results to execute the query.
            while (rs.next()) {
            }
        } finally {
            transaction.cleanup();
        }
        // Check if the last query executed is a DeleteSessionRequest and the second last query
        // executed is a ExecuteSqlRequest and was executed using a custom optimizer version and
        // statistics package.
        List<AbstractMessage> requests = mockSpanner.getRequests();
        assert requests.size() >= 2 : "required to have at least 2 requests";
        assertThat(requests.get(requests.size() - 1)).isInstanceOf(DeleteSessionRequest.class);
        assertThat(requests.get(requests.size() - 2)).isInstanceOf(ExecuteSqlRequest.class);
        ExecuteSqlRequest executeSqlRequest = (ExecuteSqlRequest) requests.get(requests.size() - 2);
        assertThat(executeSqlRequest.getQueryOptions()).isNotNull();
        assertThat(executeSqlRequest.getQueryOptions().getOptimizerVersion()).isEqualTo("1");
        assertThat(executeSqlRequest.getQueryOptions().getOptimizerStatisticsPackage()).isEqualTo("custom-package");
    }
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) ExecuteSqlRequest(com.google.spanner.v1.ExecuteSqlRequest) Test(org.junit.Test)

Example 13 with Partition

use of com.google.spanner.v1.Partition in project java-spanner by googleapis.

the class MockSpannerServiceImpl method streamingRead.

@Override
public void streamingRead(final ReadRequest request, StreamObserver<PartialResultSet> responseObserver) {
    requests.add(request);
    Preconditions.checkNotNull(request.getSession());
    Session session = sessions.get(request.getSession());
    if (session == null) {
        setSessionNotFound(request.getSession(), responseObserver);
        return;
    }
    sessionLastUsed.put(session.getName(), Instant.now());
    try {
        streamingReadExecutionTime.simulateExecutionTime(exceptions, stickyGlobalExceptions, freezeLock);
        // Get or start transaction
        ByteString transactionId = getTransactionId(session, request.getTransaction());
        if (!request.getPartitionToken().isEmpty()) {
            List<ByteString> tokens = partitionTokens.get(partitionKey(session.getName(), transactionId));
            if (tokens == null || !tokens.contains(request.getPartitionToken())) {
                throw Status.INVALID_ARGUMENT.withDescription(String.format("Partition token %s is not a valid token for this transaction", request.getPartitionToken())).asRuntimeException();
            }
        }
        simulateAbort(session, transactionId);
        Iterable<String> cols = () -> request.getColumnsList().iterator();
        Statement statement = StatementResult.createReadStatement(request.getTable(), request.getKeySet().getAll() ? KeySet.all() : KeySet.singleKey(Key.of()), cols);
        StatementResult res = getResult(statement);
        if (res == null) {
            throw Status.NOT_FOUND.withDescription("No result found for " + statement.toString()).asRuntimeException();
        }
        if (res.getType() == StatementResult.StatementResultType.EXCEPTION) {
            throw res.getException();
        }
        returnPartialResultSet(res.getResultSet(), transactionId, request.getTransaction(), responseObserver, getStreamingReadExecutionTime());
    } catch (StatusRuntimeException e) {
        responseObserver.onError(e);
    } catch (Throwable t) {
        responseObserver.onError(Status.INTERNAL.asRuntimeException());
    }
}
Also used : ByteString(com.google.protobuf.ByteString) StatusRuntimeException(io.grpc.StatusRuntimeException) ByteString(com.google.protobuf.ByteString) Session(com.google.spanner.v1.Session)

Example 14 with Partition

use of com.google.spanner.v1.Partition in project java-spanner by googleapis.

the class SpannerClientTest method partitionQueryTest.

@Test
public void partitionQueryTest() throws Exception {
    PartitionResponse expectedResponse = PartitionResponse.newBuilder().addAllPartitions(new ArrayList<Partition>()).setTransaction(Transaction.newBuilder().build()).build();
    mockSpanner.addResponse(expectedResponse);
    PartitionQueryRequest request = PartitionQueryRequest.newBuilder().setSession(SessionName.of("[PROJECT]", "[INSTANCE]", "[DATABASE]", "[SESSION]").toString()).setTransaction(TransactionSelector.newBuilder().build()).setSql("sql114126").setParams(Struct.newBuilder().build()).putAllParamTypes(new HashMap<String, Type>()).setPartitionOptions(PartitionOptions.newBuilder().build()).build();
    PartitionResponse actualResponse = client.partitionQuery(request);
    Assert.assertEquals(expectedResponse, actualResponse);
    List<AbstractMessage> actualRequests = mockSpanner.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    PartitionQueryRequest actualRequest = ((PartitionQueryRequest) actualRequests.get(0));
    Assert.assertEquals(request.getSession(), actualRequest.getSession());
    Assert.assertEquals(request.getTransaction(), actualRequest.getTransaction());
    Assert.assertEquals(request.getSql(), actualRequest.getSql());
    Assert.assertEquals(request.getParams(), actualRequest.getParams());
    Assert.assertEquals(request.getParamTypesMap(), actualRequest.getParamTypesMap());
    Assert.assertEquals(request.getPartitionOptions(), actualRequest.getPartitionOptions());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : PartitionResponse(com.google.spanner.v1.PartitionResponse) Partition(com.google.spanner.v1.Partition) Type(com.google.spanner.v1.Type) AbstractMessage(com.google.protobuf.AbstractMessage) PartitionQueryRequest(com.google.spanner.v1.PartitionQueryRequest) ByteString(com.google.protobuf.ByteString) Test(org.junit.Test)

Example 15 with Partition

use of com.google.spanner.v1.Partition in project grpc-gcp-java by GoogleCloudPlatform.

the class SpannerProbes method partitionProber.

/**
 * Probe to test PartitionQuery and PartitionRead grpc call from Spanner stub.
 */
public static void partitionProber(SpannerGrpc.SpannerBlockingStub stub) {
    Session session = null;
    try {
        session = stub.createSession(CreateSessionRequest.newBuilder().setDatabase(DATABASE).build());
        // Probing partition query call.
        TransactionOptions options = TransactionOptions.newBuilder().setReadOnly(TransactionOptions.ReadOnly.getDefaultInstance()).build();
        TransactionSelector selector = TransactionSelector.newBuilder().setBegin(options).build();
        stub.partitionQuery(PartitionQueryRequest.newBuilder().setSession(session.getName()).setSql("select * FROM " + TABLE).setTransaction(selector).build());
        // Probing partition read call.
        stub.partitionRead(PartitionReadRequest.newBuilder().setSession(session.getName()).setTable(TABLE).setTransaction(selector).setKeySet(KeySet.newBuilder().setAll(true).build()).addColumns("username").addColumns("firstname").addColumns("lastname").build());
    } finally {
        deleteSession(stub, session);
    }
}
Also used : TransactionOptions(com.google.spanner.v1.TransactionOptions) TransactionSelector(com.google.spanner.v1.TransactionSelector) Session(com.google.spanner.v1.Session)

Aggregations

Partition (com.sap.hadoop.windowing.runtime2.Partition)5 ArrayList (java.util.ArrayList)5 Partition (bdv.img.hdf5.Partition)4 ByteString (com.google.protobuf.ByteString)4 Session (com.google.spanner.v1.Session)4 WindowingException (com.sap.hadoop.windowing.WindowingException)4 AbstractMessage (com.google.protobuf.AbstractMessage)3 StatusRuntimeException (io.grpc.StatusRuntimeException)3 File (java.io.File)3 bdv.export (bdv.export)2 PluginHelper (bdv.ij.util.PluginHelper)2 Hdf5ImageLoader (bdv.img.hdf5.Hdf5ImageLoader)2 SequenceDescriptionMinimal (bdv.spimdata.SequenceDescriptionMinimal)2 SpimDataMinimal (bdv.spimdata.SpimDataMinimal)2 XmlIoSpimDataMinimal (bdv.spimdata.XmlIoSpimDataMinimal)2 Partition (com.google.spanner.v1.Partition)2 PartitionResponse (com.google.spanner.v1.PartitionResponse)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 BasicViewSetup (mpicbg.spim.data.generic.sequence.BasicViewSetup)2