use of com.google.spanner.v1.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));
}
use of com.google.spanner.v1.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);
}
use of com.google.spanner.v1.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());
}
use of com.google.spanner.v1.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));
}
use of com.google.spanner.v1.ResultSet in project googleads-java-lib by googleads.
the class GetAllBrowsers 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);
// Create statement to select all browsers.
StatementBuilder statementBuilder = new StatementBuilder().select("Id, BrowserName, MajorVersion, MinorVersion").from("Browser").orderBy("BrowserName ASC").offset(0).limit(StatementBuilder.SUGGESTED_PAGE_LIMIT);
// Default for result sets.
ResultSet combinedResultSet = null;
ResultSet resultSet;
int i = 0;
do {
// Get all browsers.
resultSet = pqlService.select(statementBuilder.toStatement());
// Combine result sets with previous ones.
combinedResultSet = combinedResultSet == null ? resultSet : Pql.combineResultSets(combinedResultSet, resultSet);
System.out.printf("%d) %d criteria 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("Browsers-", ".csv").toString();
// Write the result set to a CSV.
CsvFiles.writeCsv(Pql.resultSetToStringArrayList(combinedResultSet), filePath);
System.out.printf("Browsers saved to: %s%n", filePath);
}
Aggregations