Search in sources :

Example 1 with ColumnType

use of com.google.api.ads.admanager.axis.v202202.ColumnType 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 2 with ColumnType

use of com.google.api.ads.admanager.axis.v202202.ColumnType 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 3 with ColumnType

use of com.google.api.ads.admanager.axis.v202202.ColumnType 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.v202105.ColumnType) ResultSet(com.google.api.ads.admanager.jaxws.v202105.ResultSet) Row(com.google.api.ads.admanager.jaxws.v202105.Row)

Example 4 with ColumnType

use of com.google.api.ads.admanager.axis.v202202.ColumnType 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.v202108.ColumnType) ResultSet(com.google.api.ads.admanager.jaxws.v202108.ResultSet) Row(com.google.api.ads.admanager.jaxws.v202108.Row)

Example 5 with ColumnType

use of com.google.api.ads.admanager.axis.v202202.ColumnType 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)

Aggregations

Function (com.google.common.base.Function)8 Before (org.junit.Before)8 ResultSet (com.google.api.ads.admanager.axis.v202202.ResultSet)4 Row (com.google.api.ads.admanager.axis.v202202.Row)3 Test (org.junit.Test)3 ColumnType (com.google.api.ads.admanager.axis.v202105.ColumnType)2 ColumnType (com.google.api.ads.admanager.axis.v202108.ColumnType)2 ColumnType (com.google.api.ads.admanager.axis.v202111.ColumnType)2 ColumnType (com.google.api.ads.admanager.axis.v202202.ColumnType)2 ColumnType (com.google.api.ads.admanager.jaxws.v202105.ColumnType)2 ColumnType (com.google.api.ads.admanager.jaxws.v202108.ColumnType)2 ColumnType (com.google.api.ads.admanager.jaxws.v202202.ColumnType)2 AdUnitTargeting (com.google.api.ads.admanager.axis.v202105.AdUnitTargeting)1 BooleanValue (com.google.api.ads.admanager.axis.v202105.BooleanValue)1 Date (com.google.api.ads.admanager.axis.v202105.Date)1 DateTime (com.google.api.ads.admanager.axis.v202105.DateTime)1 DateTimeValue (com.google.api.ads.admanager.axis.v202105.DateTimeValue)1 DateValue (com.google.api.ads.admanager.axis.v202105.DateValue)1 InventoryTargeting (com.google.api.ads.admanager.axis.v202105.InventoryTargeting)1 NumberValue (com.google.api.ads.admanager.axis.v202105.NumberValue)1