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);
}
}
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;
}
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());
}
}
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());
}
}
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()));
}
Aggregations