use of com.google.api.ads.admanager.jaxws.v202205.ResultSet in project googleads-java-lib by googleads.
the class GetRecentChanges method runExample.
/**
* Runs the example.
*
* @param adManagerServices the services factory.
* @param session the session.
* @param filePath file path where changes will be saved.
* @throws ApiException if the API request failed with one or more service errors.
* @throws RemoteException if the API request failed due to other errors.
* @throws IOException if unable to write the response to a file.
*/
public static void runExample(AdManagerServices adManagerServices, AdManagerSession session, String filePath) throws IOException {
PublisherQueryLanguageServiceInterface pqlService = adManagerServices.get(session, PublisherQueryLanguageServiceInterface.class);
// Create statement to select recent changes. Change_History only supports ordering by
// descending ChangeDateTime. Offset is not supported. To page, use the change ID of
// the earliest change as a pagination token. A date time range is required
// when querying this table.
DateTime endDateTime = DateTime.now();
DateTime startDateTime = endDateTime.minusDays(1);
StatementBuilder statementBuilder = new StatementBuilder().select("Id, ChangeDateTime, EntityId, EntityType, Operation, UserId").from("Change_History").where("ChangeDateTime < :endDateTime AND ChangeDateTime > :startDateTime").orderBy("ChangeDateTime DESC").withBindVariableValue("startDateTime", DateTimes.toDateTime(startDateTime)).withBindVariableValue("endDateTime", DateTimes.toDateTime(endDateTime)).limit(StatementBuilder.SUGGESTED_PAGE_LIMIT);
// Retrieve a small amount of changes at a time, paging through
// until all changes have been retrieved.
ResultSet combinedResultSet = null;
ResultSet resultSet;
int i = 0;
do {
resultSet = pqlService.select(statementBuilder.toStatement());
// Combine result sets with previous ones.
combinedResultSet = combinedResultSet == null ? resultSet : Pql.combineResultSets(combinedResultSet, resultSet);
if (resultSet.getRows() != null && resultSet.getRows().length > 0) {
// Get the earliest change ID in the result set.
int numRows = resultSet.getRows().length;
Row lastRow = resultSet.getRows(numRows - 1);
String id = (String) Pql.getNativeValue(lastRow.getValues(0));
System.out.printf("%d) %d changes prior to ID %s were found.%n", i++, numRows, id);
// Use the earliest change ID in the result set to page.
statementBuilder.where("Id < :id AND ChangeDateTime < :endDateTime AND ChangeDateTime > :startDateTime").withBindVariableValue("id", id);
}
} while (resultSet.getRows() != null && resultSet.getRows().length > 0);
// Write the result set to a CSV.
CsvFiles.writeCsv(Pql.resultSetToStringArrayList(combinedResultSet), filePath);
System.out.printf("Recent changes saved to: %s%n", filePath);
}
use of com.google.api.ads.admanager.jaxws.v202205.ResultSet in project java-spanner by googleapis.
the class RandomResultSetGenerator method generate.
public ResultSet generate() {
ResultSet.Builder builder = ResultSet.newBuilder();
for (int row = 0; row < rowCount; row++) {
ListValue.Builder rowBuilder = ListValue.newBuilder();
for (Type type : TYPES) {
Value.Builder valueBuilder = Value.newBuilder();
setRandomValue(valueBuilder, type);
rowBuilder.addValues(valueBuilder.build());
}
builder.addRows(rowBuilder.build());
}
builder.setMetadata(METADATA);
return builder.build();
}
use of com.google.api.ads.admanager.jaxws.v202205.ResultSet in project java-spanner by googleapis.
the class RandomResultSetGenerator method generate.
public ResultSet generate() {
ResultSet.Builder builder = ResultSet.newBuilder();
for (int row = 0; row < rowCount; row++) {
ListValue.Builder rowBuilder = ListValue.newBuilder();
for (Type type : TYPES) {
Value.Builder valueBuilder = Value.newBuilder();
setRandomValue(valueBuilder, type);
rowBuilder.addValues(valueBuilder.build());
}
builder.addRows(rowBuilder.build());
}
builder.setMetadata(METADATA);
return builder.build();
}
use of com.google.api.ads.admanager.jaxws.v202205.ResultSet in project java-spanner by googleapis.
the class SpannerClientTest method executeSqlTest.
@Test
public void executeSqlTest() throws Exception {
ResultSet expectedResponse = ResultSet.newBuilder().setMetadata(ResultSetMetadata.newBuilder().build()).addAllRows(new ArrayList<ListValue>()).setStats(ResultSetStats.newBuilder().build()).build();
mockSpanner.addResponse(expectedResponse);
ExecuteSqlRequest request = ExecuteSqlRequest.newBuilder().setSession(SessionName.of("[PROJECT]", "[INSTANCE]", "[DATABASE]", "[SESSION]").toString()).setTransaction(TransactionSelector.newBuilder().build()).setSql("sql114126").setParams(Struct.newBuilder().build()).putAllParamTypes(new HashMap<String, Type>()).setResumeToken(ByteString.EMPTY).setPartitionToken(ByteString.EMPTY).setSeqno(109325920).setQueryOptions(ExecuteSqlRequest.QueryOptions.newBuilder().build()).setRequestOptions(RequestOptions.newBuilder().build()).build();
ResultSet actualResponse = client.executeSql(request);
Assert.assertEquals(expectedResponse, actualResponse);
List<AbstractMessage> actualRequests = mockSpanner.getRequests();
Assert.assertEquals(1, actualRequests.size());
ExecuteSqlRequest actualRequest = ((ExecuteSqlRequest) 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.getResumeToken(), actualRequest.getResumeToken());
Assert.assertEquals(request.getQueryMode(), actualRequest.getQueryMode());
Assert.assertEquals(request.getPartitionToken(), actualRequest.getPartitionToken());
Assert.assertEquals(request.getSeqno(), actualRequest.getSeqno());
Assert.assertEquals(request.getQueryOptions(), actualRequest.getQueryOptions());
Assert.assertEquals(request.getRequestOptions(), actualRequest.getRequestOptions());
Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
use of com.google.api.ads.admanager.jaxws.v202205.ResultSet in project stargate by stargate.
the class DefaultQueryInterceptor method interceptSystemLocalOrPeers.
private static Single<ResultMessage> interceptSystemLocalOrPeers(CQLStatement statement, QueryState state, QueryOptions options, long queryStartNanoTime) {
SelectStatement selectStatement = ((SelectStatement) statement);
// Re-parse so that we can intercept and replace the keyspace.
SelectStatement.Raw rawStatement = (SelectStatement.Raw) QueryProcessor.parseStatement(selectStatement.queryString);
rawStatement.setKeyspace(SYSTEM_KEYSPACE_NAME);
SelectStatement interceptStatement = rawStatement.prepare(state.getClientState());
Single<ResultMessage.Rows> rows = interceptStatement.execute(state, options, queryStartNanoTime);
return rows.map(r -> {
// see DseConnection
assert state.getClientState() instanceof StargateClientState;
StargateClientState clientState = (StargateClientState) state.getClientState();
clientState.boundPort().ifPresent(port -> replaceNativeTransportPort(r.result, port));
return new ResultMessage.Rows(new ResultSet(selectStatement.getResultMetadata(), r.result.rows));
});
}
Aggregations