Search in sources :

Example 16 with ColumnType

use of com.google.api.ads.admanager.jaxws.v202105.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>() {

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

Aggregations

Function (com.google.common.base.Function)8 Before (org.junit.Before)8 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 ResultSet (com.google.api.ads.admanager.axis.v202105.ResultSet)1 Row (com.google.api.ads.admanager.axis.v202105.Row)1 SetValue (com.google.api.ads.admanager.axis.v202105.SetValue)1