Search in sources :

Example 1 with Partition

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

the class PTFOperator method processInputPartition.

protected void processInputPartition() throws HiveException {
    try {
        Partition outPart = Executor.executeChain(qDef, inputPart);
        Executor.executeSelectList(qDef, outPart, new ForwardPTF());
    } 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)

Example 2 with Partition

use of com.google.spanner.v1.Partition in project beam by apache.

the class SpannerChangeStreamErrorTest method mockGetParentPartition.

private ResultSet mockGetParentPartition(Timestamp now, 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(now.toString())).addValues(Value.newBuilder().setStringValue(after3Seconds.toString())).addValues(Value.newBuilder().setStringValue("500")).addValues(Value.newBuilder().setStringValue(State.CREATED.name())).addValues(Value.newBuilder().setStringValue(now.toString())).addValues(Value.newBuilder().setStringValue(now.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)

Example 3 with Partition

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

the class MockSpannerServiceImpl method partition.

private void partition(String sessionName, TransactionSelector transactionSelector, StreamObserver<PartitionResponse> responseObserver) {
    Session session = sessions.get(sessionName);
    if (session == null) {
        setSessionNotFound(sessionName, responseObserver);
        return;
    }
    sessionLastUsed.put(session.getName(), Instant.now());
    try {
        ByteString transactionId = getTransactionId(session, transactionSelector);
        responseObserver.onNext(PartitionResponse.newBuilder().addPartitions(Partition.newBuilder().setPartitionToken(generatePartitionToken(session.getName(), transactionId)).build()).build());
        responseObserver.onCompleted();
    } 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) Session(com.google.spanner.v1.Session)

Example 4 with Partition

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

the class MockSpannerServiceImpl method executeStreamingSql.

@Override
public void executeStreamingSql(ExecuteSqlRequest request, StreamObserver<PartialResultSet> responseObserver) {
    if (includeDetermineDialectStatementInRequests || !request.getSql().equals(SessionPool.DETERMINE_DIALECT_STATEMENT.getSql())) {
        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 {
        Statement statement = buildStatement(request.getSql(), request.getParamTypesMap(), request.getParams());
        ByteString transactionId = getTransactionId(session, request.getTransaction());
        boolean isPartitioned = isPartitionedDmlTransaction(transactionId);
        if (isPartitioned) {
            StatementResult firstRes = getResult(statement);
            switch(firstRes.getType()) {
                case EXCEPTION:
                    throw firstRes.getException();
                case UPDATE_COUNT:
                    returnPartialResultSet(session, 0L, !isPartitioned, responseObserver, request.getTransaction(), false);
                    break;
                case RESULT_SET:
                default:
                    break;
            }
        }
        executeStreamingSqlExecutionTime.simulateExecutionTime(exceptions, stickyGlobalExceptions, freezeLock);
        // Get or start transaction
        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);
        StatementResult res = getResult(statement);
        switch(res.getType()) {
            case EXCEPTION:
                throw res.getException();
            case RESULT_SET:
                returnPartialResultSet(res.getResultSet(), transactionId, request.getTransaction(), responseObserver, getExecuteStreamingSqlExecutionTime());
                break;
            case UPDATE_COUNT:
                if (isPartitioned) {
                    commitTransaction(transactionId);
                }
                returnPartialResultSet(session, res.getUpdateCount(), !isPartitioned, responseObserver, request.getTransaction());
                break;
            default:
                throw new IllegalStateException("Unknown result type: " + res.getType());
        }
    } catch (StatusRuntimeException e) {
        responseObserver.onError(e);
    } catch (Throwable t) {
        responseObserver.onError(Status.INTERNAL.withCause(t).asRuntimeException());
    }
}
Also used : ByteString(com.google.protobuf.ByteString) StatusRuntimeException(io.grpc.StatusRuntimeException) Session(com.google.spanner.v1.Session)

Example 5 with Partition

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

the class SpannerClientTest method partitionReadTest.

@Test
public void partitionReadTest() throws Exception {
    PartitionResponse expectedResponse = PartitionResponse.newBuilder().addAllPartitions(new ArrayList<Partition>()).setTransaction(Transaction.newBuilder().build()).build();
    mockSpanner.addResponse(expectedResponse);
    PartitionReadRequest request = PartitionReadRequest.newBuilder().setSession(SessionName.of("[PROJECT]", "[INSTANCE]", "[DATABASE]", "[SESSION]").toString()).setTransaction(TransactionSelector.newBuilder().build()).setTable("table110115790").setIndex("index100346066").addAllColumns(new ArrayList<String>()).setKeySet(KeySet.newBuilder().build()).setPartitionOptions(PartitionOptions.newBuilder().build()).build();
    PartitionResponse actualResponse = client.partitionRead(request);
    Assert.assertEquals(expectedResponse, actualResponse);
    List<AbstractMessage> actualRequests = mockSpanner.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    PartitionReadRequest actualRequest = ((PartitionReadRequest) actualRequests.get(0));
    Assert.assertEquals(request.getSession(), actualRequest.getSession());
    Assert.assertEquals(request.getTransaction(), actualRequest.getTransaction());
    Assert.assertEquals(request.getTable(), actualRequest.getTable());
    Assert.assertEquals(request.getIndex(), actualRequest.getIndex());
    Assert.assertEquals(request.getColumnsList(), actualRequest.getColumnsList());
    Assert.assertEquals(request.getKeySet(), actualRequest.getKeySet());
    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) AbstractMessage(com.google.protobuf.AbstractMessage) ArrayList(java.util.ArrayList) PartitionReadRequest(com.google.spanner.v1.PartitionReadRequest) Test(org.junit.Test)

Aggregations

Partition (com.sap.hadoop.windowing.runtime2.Partition)5 ByteString (com.google.protobuf.ByteString)4 WindowingException (com.sap.hadoop.windowing.WindowingException)4 AbstractMessage (com.google.protobuf.AbstractMessage)3 Session (com.google.spanner.v1.Session)3 StatusRuntimeException (io.grpc.StatusRuntimeException)3 HiveException (org.apache.hadoop.hive.ql.metadata.HiveException)3 Test (org.junit.Test)3 Partition (com.google.spanner.v1.Partition)2 PartitionResponse (com.google.spanner.v1.PartitionResponse)2 ArrayList (java.util.ArrayList)2 SerDeException (org.apache.hadoop.hive.serde2.SerDeException)2 StructObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.StructObjectInspector)2 Statement (com.google.cloud.spanner.Statement)1 ExecuteSqlRequest (com.google.spanner.v1.ExecuteSqlRequest)1 PartitionQueryRequest (com.google.spanner.v1.PartitionQueryRequest)1 PartitionReadRequest (com.google.spanner.v1.PartitionReadRequest)1 ResultSet (com.google.spanner.v1.ResultSet)1 Type (com.google.spanner.v1.Type)1 SameList (com.sap.hadoop.ds.SameList)1