Search in sources :

Example 6 with Row

use of com.google.api.ads.admanager.axis.v202111.Row in project simple-bigtable by spotify.

the class RowReadImplTest method testToDataType.

@Test
public void testToDataType() throws Exception {
    assertFalse(rowRead.toDataType().apply(ImmutableList.of()).isPresent());
    final Row row = Row.getDefaultInstance();
    assertEquals(row, rowRead.toDataType().apply(ImmutableList.of(row)).get());
}
Also used : Row(com.google.bigtable.v2.Row) Test(org.junit.Test)

Example 7 with Row

use of com.google.api.ads.admanager.axis.v202111.Row in project simple-bigtable by spotify.

the class FamilyReadImplTest method testParentDataTypeToDataType.

@Test
public void testParentDataTypeToDataType() throws Exception {
    assertEquals(Optional.empty(), familyRead.parentTypeToCurrentType().apply(Optional.empty()));
    assertEquals(Optional.empty(), familyRead.parentTypeToCurrentType().apply(Optional.of(Row.getDefaultInstance())));
    final Family family = Family.getDefaultInstance();
    final Row row = Row.newBuilder().addFamilies(family).build();
    assertEquals(Optional.of(family), familyRead.parentTypeToCurrentType().apply(Optional.of(row)));
}
Also used : Family(com.google.bigtable.v2.Family) Row(com.google.bigtable.v2.Row) Test(org.junit.Test)

Example 8 with Row

use of com.google.api.ads.admanager.axis.v202111.Row 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 9 with Row

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

the class Pql method resultSetToStringArrayList.

/**
 * Gets the result set as list of string arrays, which can be transformed to a CSV using {@code
 * CsvFiles} such as
 *
 * <pre>
 * <code>
 * ResultSet combinedResultSet = Pql.combineResultSet(resultSet1, resultSet2);
 * //...
 * combinedResultSet = Pql.combineResultSet(combinedResultSet, resultSet3);
 * CsvFiles.writeCsv(Pql.resultSetToStringArrayList(combinedResultSet), filePath);
 * </code>
 * </pre>
 *
 * @param resultSet the result set to convert to a CSV compatible format
 * @return a list of string arrays representing the result set
 */
public static List<String[]> resultSetToStringArrayList(ResultSet resultSet) {
    List<String[]> stringArrayList = Lists.newArrayList();
    stringArrayList.add(getColumnLabels(resultSet).toArray(new String[] {}));
    if (resultSet.getRows() != null) {
        for (Row row : resultSet.getRows()) {
            try {
                stringArrayList.add(getRowStringValues(row).toArray(new String[] {}));
            } catch (IllegalArgumentException e) {
                throw new IllegalStateException("Cannot convert result set to string array list", e);
            }
        }
    }
    return stringArrayList;
}
Also used : Row(com.google.api.ads.admanager.jaxws.v202108.Row)

Example 10 with Row

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

Aggregations

Test (org.junit.Test)36 Row (com.google.bigtable.v2.Row)16 ByteString (com.google.protobuf.ByteString)11 Function (com.google.common.base.Function)8 Row (com.google.api.ads.admanager.axis.v202108.Row)6 Row (com.google.api.ads.admanager.axis.v202111.Row)6 Row (com.google.api.ads.admanager.axis.v202202.Row)6 Family (com.google.bigtable.v2.Family)6 ByteKey (org.apache.beam.sdk.io.range.ByteKey)6 Row (com.google.api.ads.admanager.axis.v202105.Row)5 Row (com.google.api.ads.admanager.jaxws.v202105.Row)5 Row (com.google.api.ads.admanager.jaxws.v202108.Row)5 Row (com.google.api.ads.admanager.jaxws.v202111.Row)5 Row (com.google.api.ads.admanager.jaxws.v202202.Row)5 ResultSet (com.google.api.ads.admanager.axis.v202108.ResultSet)4 ResultSet (com.google.api.ads.admanager.axis.v202111.ResultSet)4 ResultSet (com.google.api.ads.admanager.axis.v202202.ResultSet)4 Column (com.google.bigtable.v2.Column)4 ReadRowsRequest (com.google.bigtable.v2.ReadRowsRequest)4 ResultSet (com.google.api.ads.admanager.jaxws.v202105.ResultSet)3