Search in sources :

Example 1 with ResultSet

use of com.google.api.ads.admanager.jaxws.v202202.ResultSet in project beam by apache.

the class SpannerChangeStreamErrorTest method mockTableExists.

private void mockTableExists() {
    Statement tableExistsStatement = Statement.of("SELECT t.table_name FROM information_schema.tables AS t WHERE t.table_catalog = '' AND t.table_schema = '' AND t.table_name = 'my-metadata-table'");
    ResultSetMetadata tableExistsResultSetMetadata = ResultSetMetadata.newBuilder().setRowType(StructType.newBuilder().addFields(Field.newBuilder().setName("table_name").setType(Type.newBuilder().setCode(TypeCode.STRING).build()).build()).build()).build();
    ResultSet tableExistsResultSet = ResultSet.newBuilder().addRows(ListValue.newBuilder().addValues(Value.newBuilder().setStringValue(TEST_TABLE).build()).build()).setMetadata(tableExistsResultSetMetadata).build();
    mockSpannerService.putStatementResult(StatementResult.query(tableExistsStatement, tableExistsResultSet));
}
Also used : Statement(com.google.cloud.spanner.Statement) ResultSetMetadata(com.google.spanner.v1.ResultSetMetadata) ResultSet(com.google.spanner.v1.ResultSet)

Example 2 with ResultSet

use of com.google.api.ads.admanager.jaxws.v202202.ResultSet 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;
}
Also used : Statement(com.google.cloud.spanner.Statement) ResultSet(com.google.spanner.v1.ResultSet)

Example 3 with ResultSet

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

the class PqlTest method testGetColumnLabels.

@Test
public void testGetColumnLabels() {
    ResultSet resultSet = new ResultSet();
    resultSet.setColumnTypes(new ColumnType[] { column1, column2, column3 });
    assertEquals(Lists.newArrayList(new String[] { "column1", "column2", "column3" }), Pql.getColumnLabels(resultSet));
}
Also used : ResultSet(com.google.api.ads.admanager.axis.v202202.ResultSet) Test(org.junit.Test)

Example 4 with ResultSet

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

the class PqlTest method testCombineResultSet_badColumns.

@Test
public void testCombineResultSet_badColumns() {
    Row row1 = new Row();
    row1.setValues(new Value[] { textValue1, booleanValue1, numberValue1 });
    Row row2 = new Row();
    row2.setValues(new Value[] { textValue2, booleanValue2, numberValue2 });
    Row row3 = new Row();
    row3.setValues(new Value[] { textValue3, booleanValue3 });
    ResultSet resultSet1 = new ResultSet();
    resultSet1.setColumnTypes(new ColumnType[] { column1, column2, column3 });
    resultSet1.setRows(new Row[] { row1, row2 });
    ResultSet resultSet2 = new ResultSet();
    resultSet2.setColumnTypes(new ColumnType[] { column1, column2 });
    resultSet2.setRows(new Row[] { row3 });
    thrown.expect(IllegalArgumentException.class);
    Pql.combineResultSets(resultSet1, resultSet2);
}
Also used : ResultSet(com.google.api.ads.admanager.axis.v202202.ResultSet) Row(com.google.api.ads.admanager.axis.v202202.Row) Test(org.junit.Test)

Example 5 with ResultSet

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

the class GetAllProgrammaticBuyers 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.
 * @throws IOException if unable to write the response to a file.
 */
public static void runExample(AdManagerServices adManagerServices, AdManagerSession session) throws IOException {
    // Get the PublisherQueryLanguageService.
    PublisherQueryLanguageServiceInterface pqlService = adManagerServices.get(session, PublisherQueryLanguageServiceInterface.class);
    // Create statement to select all programmatic buyers.
    StatementBuilder statementBuilder = new StatementBuilder().select("BuyerAccountId, Name").from("Programmatic_Buyer").orderBy("BuyerAccountId ASC").offset(0).limit(StatementBuilder.SUGGESTED_PAGE_LIMIT);
    // Default for result sets.
    ResultSet combinedResultSet = null;
    ResultSet resultSet;
    int i = 0;
    do {
        // Get all programmatic buyers.
        resultSet = pqlService.select(statementBuilder.toStatement());
        // Combine result sets with previous ones.
        combinedResultSet = combinedResultSet == null ? resultSet : Pql.combineResultSets(combinedResultSet, resultSet);
        System.out.printf("%d) %d programmatic buyers 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("Programmatic-Buyers-", ".csv").toString();
    // Write the result set to a CSV.
    CsvFiles.writeCsv(Pql.resultSetToStringArrayList(combinedResultSet), filePath);
    System.out.printf("Programmatic buyers saved to: %s%n", filePath);
}
Also used : PublisherQueryLanguageServiceInterface(com.google.api.ads.admanager.axis.v202111.PublisherQueryLanguageServiceInterface) StatementBuilder(com.google.api.ads.admanager.axis.utils.v202111.StatementBuilder) ResultSet(com.google.api.ads.admanager.axis.v202111.ResultSet)

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