Search in sources :

Example 56 with ResultSet

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

the class GetGeoTargets method runExample.

/**
 * Runs the example.
 *
 * @param adManagerServices the services factory.
 * @param session the session.
 * @param type the geo target type.
 * @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 type) throws IOException {
    // Get the PublisherQueryLanguageService.
    PublisherQueryLanguageServiceInterface pqlService = adManagerServices.get(session, PublisherQueryLanguageServiceInterface.class);
    // Create statement to select all targetable cities.
    StatementBuilder statementBuilder = new StatementBuilder().select("Id, Name, CanonicalParentId, ParentIds, CountryCode").from("Geo_Target").where("Type = :type and Targetable = true").orderBy("CountryCode ASC, Name ASC").offset(0).limit(StatementBuilder.SUGGESTED_PAGE_LIMIT).withBindVariableValue("type", type);
    // Default for result sets.
    ResultSet combinedResultSet = null;
    ResultSet resultSet;
    int i = 0;
    do {
        // Get all cities.
        resultSet = pqlService.select(statementBuilder.toStatement());
        // Combine result sets with previous ones.
        combinedResultSet = combinedResultSet == null ? resultSet : Pql.combineResultSets(combinedResultSet, resultSet);
        System.out.printf("%d) %d geo targets beginning at offset %d were found.%n", i++, resultSet.getRows() == null ? 0 : resultSet.getRows().length, statementBuilder.getOffset());
        statementBuilder.increaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
    } while (resultSet.getRows() != null && resultSet.getRows().length > 0);
    // Change to your file location.
    String filePath = File.createTempFile(type + "-", ".csv").toString();
    // Write the result set to a CSV.
    CsvFiles.writeCsv(Pql.resultSetToStringArrayList(combinedResultSet), filePath);
    System.out.printf("Geo targets 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)

Example 57 with ResultSet

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

the class GetMcmEarnings method runExample.

/**
 * Runs the example.
 *
 * @param adManagerServices the services factory.
 * @param session the session.
 * @throws ApiException if the API request failed with one or more service errors.
 * @throws RemoteException if the API request failed due to other errors.
 */
public static void runExample(AdManagerServices adManagerServices, AdManagerSession session) throws IOException {
    // Get the PublisherQueryLanguageService.
    PublisherQueryLanguageServiceInterface pqlService = adManagerServices.get(session, PublisherQueryLanguageServiceInterface.class);
    DateTime lastMonth = DateTime.now().minusMonths(1).withDayOfMonth(1);
    // Create statement to select earnings data from the prior month.
    StatementBuilder statementBuilder = new StatementBuilder().select("Month, ChildName, ChildNetworkCode, TotalEarningsCurrencyCode," + " TotalEarningsMicros, ParentPaymentCurrencyCode, ParentPaymentMicros," + " ChildPaymentCurrencyCode, ChildPaymentMicros, DeductionsMicros").from("mcm_earnings").where("Month = :month").orderBy("ChildNetworkCode").limit(StatementBuilder.SUGGESTED_PAGE_LIMIT).withBindVariableValue("month", DateTimes.toDateTime(lastMonth).getDate());
    // Default for result sets.
    ResultSet combinedResultSet = null;
    ResultSet resultSet;
    int i = 0;
    do {
        // Get all earnings information.
        resultSet = pqlService.select(statementBuilder.toStatement());
        // Combine result sets with previous ones.
        combinedResultSet = combinedResultSet == null ? resultSet : Pql.combineResultSets(combinedResultSet, resultSet);
        System.out.printf("%d) %d rows beginning at offset %d were found.%n", i++, resultSet.getRows() == null ? 0 : resultSet.getRows().length, statementBuilder.getOffset());
        statementBuilder.increaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
    } while (resultSet.getRows() != null && resultSet.getRows().length > 0);
    // Change to your file location.
    String filePath = File.createTempFile("EarningsReport-", ".csv").toString();
    // Write the result set to a CSV.
    CsvFiles.writeCsv(Pql.resultSetToStringArrayList(combinedResultSet), filePath);
    System.out.printf("Earnings information 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) DateTime(org.joda.time.DateTime)

Example 58 with ResultSet

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

the class PqlTest method testCombineResultSet.

@Test
public void testCombineResultSet() {
    Row row1 = new Row();
    row1.getValues().addAll(Lists.newArrayList(textValue1, booleanValue1, numberValue1));
    Row row2 = new Row();
    row2.getValues().addAll(Lists.newArrayList(textValue2, booleanValue2, numberValue2));
    Row row3 = new Row();
    row3.getValues().addAll(Lists.newArrayList(textValue3, booleanValue3, numberValue3));
    ResultSet resultSet1 = new ResultSet();
    resultSet1.getColumnTypes().addAll(Lists.newArrayList(column1, column2, column3));
    resultSet1.getRows().addAll(Lists.newArrayList(row1, row2));
    ResultSet resultSet2 = new ResultSet();
    resultSet2.getColumnTypes().addAll(Lists.newArrayList(column1, column2, column3));
    resultSet2.getRows().addAll(Lists.newArrayList(row3));
    ResultSet combinedResultSet = Pql.combineResultSets(resultSet1, resultSet2);
    assertEquals(3, combinedResultSet.getRows().size());
    assertEquals(Lists.newArrayList(column1, column2, column3), combinedResultSet.getColumnTypes());
    assertEquals(Lists.newArrayList(textValue1, booleanValue1, numberValue1), combinedResultSet.getRows().get(0).getValues());
    assertEquals(Lists.newArrayList(textValue2, booleanValue2, numberValue2), combinedResultSet.getRows().get(1).getValues());
    assertEquals(Lists.newArrayList(textValue3, booleanValue3, numberValue3), combinedResultSet.getRows().get(2).getValues());
}
Also used : ResultSet(com.google.api.ads.admanager.jaxws.v202108.ResultSet) Row(com.google.api.ads.admanager.jaxws.v202108.Row) Test(org.junit.Test)

Example 59 with ResultSet

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

the class PqlTest method testCombineResultSet_badColumns.

@Test
public void testCombineResultSet_badColumns() {
    Row row1 = new Row();
    row1.getValues().addAll(Lists.newArrayList(textValue1, booleanValue1, numberValue1));
    Row row2 = new Row();
    row2.getValues().addAll(Lists.newArrayList(textValue2, booleanValue2, numberValue2));
    Row row3 = new Row();
    row3.getValues().addAll(Lists.newArrayList(textValue3, booleanValue3));
    ResultSet resultSet1 = new ResultSet();
    resultSet1.getColumnTypes().addAll(Lists.newArrayList(column1, column2, column3));
    resultSet1.getRows().addAll(Lists.newArrayList(row1, row2));
    ResultSet resultSet2 = new ResultSet();
    resultSet2.getColumnTypes().addAll(Lists.newArrayList(column1, column2));
    resultSet2.getRows().addAll(Lists.newArrayList(row3));
    thrown.expect(IllegalArgumentException.class);
    Pql.combineResultSets(resultSet1, resultSet2);
}
Also used : ResultSet(com.google.api.ads.admanager.jaxws.v202108.ResultSet) Row(com.google.api.ads.admanager.jaxws.v202108.Row) Test(org.junit.Test)

Example 60 with ResultSet

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

the class PqlTest method testGetColumnLabels.

@Test
public void testGetColumnLabels() {
    ResultSet resultSet = new ResultSet();
    resultSet.getColumnTypes().addAll(Lists.newArrayList(column1, column2, column3));
    assertEquals(Lists.newArrayList("column1", "column2", "column3"), Pql.getColumnLabels(resultSet));
}
Also used : ResultSet(com.google.api.ads.admanager.jaxws.v202108.ResultSet) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)37 ResultSet (com.google.spanner.v1.ResultSet)21 PartialResultSet (com.google.spanner.v1.PartialResultSet)14 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 ResultSet (com.google.api.ads.admanager.axis.v202205.ResultSet)12 Function (com.google.common.base.Function)10 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 StatementBuilder (com.google.api.ads.admanager.axis.utils.v202205.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 PublisherQueryLanguageServiceInterface (com.google.api.ads.admanager.axis.v202205.PublisherQueryLanguageServiceInterface)8 Session (com.google.spanner.v1.Session)8 DateTime (org.joda.time.DateTime)8 ListValue (com.google.protobuf.ListValue)5 ResultSet (org.apache.cassandra.cql3.ResultSet)5