Search in sources :

Example 21 with Row

use of org.molgenis.emx2.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.axis.v202111.Row)

Example 22 with Row

use of org.molgenis.emx2.Row in project googleads-java-lib by googleads.

the class PqlTest method testCombineResultSet_badColumns.

@Test
public void testCombineResultSet_badColumns() {
    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));
    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));
    resultSet2.getRows().addAll(Lists.newArrayList(row3));
    thrown.expect(IllegalArgumentException.class);
    Pql.combineResultSets(resultSet1, resultSet2);
}
Also used : ResultSet(com.google.api.ads.admanager.jaxws.v202105.ResultSet) Row(com.google.api.ads.admanager.jaxws.v202105.Row) Test(org.junit.Test)

Example 23 with Row

use of org.molgenis.emx2.Row in project googleads-java-lib by googleads.

the class PqlTest method testGetRowStringValues.

@Test
public void testGetRowStringValues() {
    Row row = new Row();
    row.getValues().addAll(Lists.newArrayList(textValue1, booleanValue1, numberValue2, numberSetValue));
    assertEquals(Lists.newArrayList("value1", "false", "1.02", "1,-1"), Pql.getRowStringValues(row));
}
Also used : Row(com.google.api.ads.admanager.jaxws.v202108.Row) Test(org.junit.Test)

Example 24 with Row

use of org.molgenis.emx2.Row 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());
}
Also used : ResultSet(com.google.api.ads.admanager.jaxws.v202111.ResultSet) Row(com.google.api.ads.admanager.jaxws.v202111.Row) Test(org.junit.Test)

Example 25 with Row

use of org.molgenis.emx2.Row in project googleads-java-lib by googleads.

the class PqlTest method testGetRowStringValues.

@Test
public void testGetRowStringValues() {
    Row row = new Row();
    row.getValues().addAll(Lists.newArrayList(textValue1, booleanValue1, numberValue2, numberSetValue));
    assertEquals(Lists.newArrayList("value1", "false", "1.02", "1,-1"), Pql.getRowStringValues(row));
}
Also used : Row(com.google.api.ads.admanager.jaxws.v202111.Row) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)61 Row (org.molgenis.emx2.Row)39 Row (com.google.bigtable.v2.Row)16 Table (org.molgenis.emx2.Table)13 ByteString (com.google.protobuf.ByteString)11 ArrayList (java.util.ArrayList)9 Function (com.google.common.base.Function)8 MolgenisException (org.molgenis.emx2.MolgenisException)8 Schema (org.molgenis.emx2.Schema)8 Row (com.google.api.ads.admanager.axis.v202108.Row)6 Family (com.google.bigtable.v2.Family)6 IOException (java.io.IOException)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.axis.v202111.Row)5 Row (com.google.api.ads.admanager.axis.v202202.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.v202202.Row)5 Path (java.nio.file.Path)5