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