Search in sources :

Example 11 with ResultSet

use of com.google.api.ads.admanager.jaxws.v202202.ResultSet in project googleads-java-lib by googleads.

the class Pql method combineResultSets.

/**
 * Combines the first and second result sets, if and only if, the columns of both result sets
 * match.
 *
 * @throws IllegalArgumentException if the columns of the first result set don't match the second
 */
public static ResultSet combineResultSets(ResultSet first, ResultSet second) {
    Function<ColumnType, String> columnTypeToString = new Function<ColumnType, String>() {

        public String apply(ColumnType input) {
            return input.getLabelName();
        }
    };
    List<String> firstColumns = Lists.transform(Lists.newArrayList(first.getColumnTypes()), columnTypeToString);
    List<String> secondColumns = Lists.transform(Lists.newArrayList(second.getColumnTypes()), columnTypeToString);
    if (!firstColumns.equals(secondColumns)) {
        throw new IllegalArgumentException(String.format("First result set columns [%s] do not match second columns [%s]", Joiner.on(",").join(firstColumns), Joiner.on(",").join(secondColumns)));
    }
    List<Row> combinedRows = Lists.newArrayList(first.getRows());
    if (second.getRows() != null) {
        combinedRows.addAll(Lists.newArrayList(second.getRows()));
    }
    ResultSet combinedResultSet = new ResultSet();
    combinedResultSet.getColumnTypes().addAll(first.getColumnTypes());
    combinedResultSet.getRows().addAll(combinedRows);
    return combinedResultSet;
}
Also used : Function(com.google.common.base.Function) ColumnType(com.google.api.ads.admanager.jaxws.v202111.ColumnType) ResultSet(com.google.api.ads.admanager.jaxws.v202111.ResultSet) Row(com.google.api.ads.admanager.jaxws.v202111.Row)

Example 12 with ResultSet

use of com.google.api.ads.admanager.jaxws.v202202.ResultSet in project googleads-java-lib by googleads.

the class Pql method combineResultSets.

/**
 * Combines the first and second result sets, if and only if, the columns of both result sets
 * match.
 *
 * @throws IllegalArgumentException if the columns of the first result set don't match the second
 */
public static ResultSet combineResultSets(ResultSet first, ResultSet second) {
    Function<ColumnType, String> columnTypeToString = new Function<ColumnType, String>() {

        @Override
        public String apply(ColumnType input) {
            return input.getLabelName();
        }
    };
    List<String> firstColumns = Lists.transform(Lists.newArrayList(first.getColumnTypes()), columnTypeToString);
    List<String> secondColumns = Lists.transform(Lists.newArrayList(second.getColumnTypes()), columnTypeToString);
    if (!firstColumns.equals(secondColumns)) {
        throw new IllegalArgumentException(String.format("First result set columns [%s] do not match second columns [%s]", Joiner.on(",").join(firstColumns), Joiner.on(",").join(secondColumns)));
    }
    List<Row> combinedRows = Lists.newArrayList(first.getRows());
    if (second.getRows() != null) {
        Collections.addAll(combinedRows, second.getRows());
    }
    ResultSet combinedResultSet = new ResultSet();
    combinedResultSet.setColumnTypes(first.getColumnTypes());
    combinedResultSet.setRows(combinedRows.toArray(new Row[] {}));
    return combinedResultSet;
}
Also used : Function(com.google.common.base.Function) ColumnType(com.google.api.ads.admanager.axis.v202105.ColumnType) ResultSet(com.google.api.ads.admanager.axis.v202105.ResultSet) Row(com.google.api.ads.admanager.axis.v202105.Row)

Example 13 with ResultSet

use of com.google.api.ads.admanager.jaxws.v202202.ResultSet in project googleads-java-lib by googleads.

the class Pql method combineResultSets.

/**
 * Combines the first and second result sets, if and only if, the columns of both result sets
 * match.
 *
 * @throws IllegalArgumentException if the columns of the first result set don't match the second
 */
public static ResultSet combineResultSets(ResultSet first, ResultSet second) {
    Function<ColumnType, String> columnTypeToString = new Function<ColumnType, String>() {

        @Override
        public String apply(ColumnType input) {
            return input.getLabelName();
        }
    };
    List<String> firstColumns = Lists.transform(Lists.newArrayList(first.getColumnTypes()), columnTypeToString);
    List<String> secondColumns = Lists.transform(Lists.newArrayList(second.getColumnTypes()), columnTypeToString);
    if (!firstColumns.equals(secondColumns)) {
        throw new IllegalArgumentException(String.format("First result set columns [%s] do not match second columns [%s]", Joiner.on(",").join(firstColumns), Joiner.on(",").join(secondColumns)));
    }
    List<Row> combinedRows = Lists.newArrayList(first.getRows());
    if (second.getRows() != null) {
        Collections.addAll(combinedRows, second.getRows());
    }
    ResultSet combinedResultSet = new ResultSet();
    combinedResultSet.setColumnTypes(first.getColumnTypes());
    combinedResultSet.setRows(combinedRows.toArray(new Row[] {}));
    return combinedResultSet;
}
Also used : Function(com.google.common.base.Function) ColumnType(com.google.api.ads.admanager.axis.v202111.ColumnType) ResultSet(com.google.api.ads.admanager.axis.v202111.ResultSet) Row(com.google.api.ads.admanager.axis.v202111.Row)

Example 14 with ResultSet

use of com.google.api.ads.admanager.jaxws.v202202.ResultSet in project googleads-java-lib by googleads.

the class Pql method combineResultSets.

/**
 * Combines the first and second result sets, if and only if, the columns of both result sets
 * match.
 *
 * @throws IllegalArgumentException if the columns of the first result set don't match the second
 */
public static ResultSet combineResultSets(ResultSet first, ResultSet second) {
    Function<ColumnType, String> columnTypeToString = new Function<ColumnType, String>() {

        public String apply(ColumnType input) {
            return input.getLabelName();
        }
    };
    List<String> firstColumns = Lists.transform(Lists.newArrayList(first.getColumnTypes()), columnTypeToString);
    List<String> secondColumns = Lists.transform(Lists.newArrayList(second.getColumnTypes()), columnTypeToString);
    if (!firstColumns.equals(secondColumns)) {
        throw new IllegalArgumentException(String.format("First result set columns [%s] do not match second columns [%s]", Joiner.on(",").join(firstColumns), Joiner.on(",").join(secondColumns)));
    }
    List<Row> combinedRows = Lists.newArrayList(first.getRows());
    if (second.getRows() != null) {
        combinedRows.addAll(Lists.newArrayList(second.getRows()));
    }
    ResultSet combinedResultSet = new ResultSet();
    combinedResultSet.getColumnTypes().addAll(first.getColumnTypes());
    combinedResultSet.getRows().addAll(combinedRows);
    return combinedResultSet;
}
Also used : Function(com.google.common.base.Function) ColumnType(com.google.api.ads.admanager.jaxws.v202202.ColumnType) ResultSet(com.google.api.ads.admanager.jaxws.v202202.ResultSet) Row(com.google.api.ads.admanager.jaxws.v202202.Row)

Example 15 with ResultSet

use of com.google.api.ads.admanager.jaxws.v202202.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);
}
Also used : PublisherQueryLanguageServiceInterface(com.google.api.ads.admanager.axis.v202108.PublisherQueryLanguageServiceInterface) StatementBuilder(com.google.api.ads.admanager.axis.utils.v202108.StatementBuilder) ResultSet(com.google.api.ads.admanager.axis.v202108.ResultSet) Row(com.google.api.ads.admanager.axis.v202108.Row) DateTime(org.joda.time.DateTime)

Aggregations

Test (org.junit.Test)25 ResultSet (com.google.api.ads.admanager.axis.v202108.ResultSet)12 ResultSet (com.google.api.ads.admanager.axis.v202111.ResultSet)12 ResultSet (com.google.api.ads.admanager.axis.v202202.ResultSet)12 StatementBuilder (com.google.api.ads.admanager.axis.utils.v202108.StatementBuilder)8 StatementBuilder (com.google.api.ads.admanager.axis.utils.v202111.StatementBuilder)8 StatementBuilder (com.google.api.ads.admanager.axis.utils.v202202.StatementBuilder)8 PublisherQueryLanguageServiceInterface (com.google.api.ads.admanager.axis.v202108.PublisherQueryLanguageServiceInterface)8 PublisherQueryLanguageServiceInterface (com.google.api.ads.admanager.axis.v202111.PublisherQueryLanguageServiceInterface)8 PublisherQueryLanguageServiceInterface (com.google.api.ads.admanager.axis.v202202.PublisherQueryLanguageServiceInterface)8 Function (com.google.common.base.Function)8 DateTime (org.joda.time.DateTime)6 ResultSet (com.google.spanner.v1.ResultSet)5 ResultSet (com.google.api.ads.admanager.axis.v202105.ResultSet)4 Row (com.google.api.ads.admanager.axis.v202108.Row)4 Row (com.google.api.ads.admanager.axis.v202111.Row)4 Row (com.google.api.ads.admanager.axis.v202202.Row)4 ResultSet (com.google.api.ads.admanager.jaxws.v202105.ResultSet)4 ResultSet (com.google.api.ads.admanager.jaxws.v202108.ResultSet)4 ResultSet (com.google.api.ads.admanager.jaxws.v202111.ResultSet)4