Search in sources :

Example 76 with Row

use of com.google.api.ads.admanager.jaxws.v202205.Row in project DataflowTemplates by GoogleCloudPlatform.

the class BigtableToParquetTest method applyBigtableToParquetFn.

@Test
public void applyBigtableToParquetFn() throws Exception {
    Row row = createBigtableRow("row1");
    row = upsertBigtableCell(row, "family1", "column1", 1, "value1");
    GenericRecord parquetRecord = new GenericData.Record(BigtableRow.getClassSchema());
    byte[] rowKey = "row1".getBytes();
    ByteBuffer key = ByteBuffer.wrap(rowKey);
    List<BigtableCell> cells = new ArrayList<>();
    String family = "family1";
    byte[] cellQualifier = "column1".getBytes();
    ByteBuffer qualifier = ByteBuffer.wrap(cellQualifier);
    Long timestamp = 1L;
    byte[] cellValue = "value1".getBytes();
    ByteBuffer value = ByteBuffer.wrap(cellValue);
    cells.add(new BigtableCell(family, qualifier, timestamp, value));
    parquetRecord.put("key", key);
    parquetRecord.put("cells", cells);
    PCollection<GenericRecord> parquetRows = pipeline.apply("Create", Create.of(row)).apply("Transform to Parquet", MapElements.via(new BigtableToParquetFn())).setCoder(AvroCoder.of(GenericRecord.class, BigtableRow.getClassSchema()));
    // Assert on the parquetRows.
    PAssert.that(parquetRows).containsInAnyOrder(parquetRecord);
    pipeline.run();
}
Also used : TestUtils.upsertBigtableCell(com.google.cloud.teleport.bigtable.TestUtils.upsertBigtableCell) ArrayList(java.util.ArrayList) GenericRecord(org.apache.avro.generic.GenericRecord) Row(com.google.bigtable.v2.Row) TestUtils.createBigtableRow(com.google.cloud.teleport.bigtable.TestUtils.createBigtableRow) GenericRecord(org.apache.avro.generic.GenericRecord) ByteBuffer(java.nio.ByteBuffer) BigtableToParquetFn(com.google.cloud.teleport.bigtable.BigtableToParquet.BigtableToParquetFn) Test(org.junit.Test)

Example 77 with Row

use of com.google.api.ads.admanager.jaxws.v202205.Row in project beam by apache.

the class BigtableIOTest method makeTableData.

/**
 * Helper function to create a table and return the rows that it created.
 */
private static List<Row> makeTableData(String tableId, int numRows) {
    service.createTable(tableId);
    Map<ByteString, ByteString> testData = service.getTable(tableId);
    List<Row> testRows = new ArrayList<>(numRows);
    for (int i = 0; i < numRows; ++i) {
        ByteString key = ByteString.copyFromUtf8(String.format("key%09d", i));
        ByteString value = ByteString.copyFromUtf8(String.format("value%09d", i));
        testData.put(key, value);
        testRows.add(makeRow(key, value));
    }
    return testRows;
}
Also used : ByteString(com.google.protobuf.ByteString) ArrayList(java.util.ArrayList) Row(com.google.bigtable.v2.Row)

Example 78 with Row

use of com.google.api.ads.admanager.jaxws.v202205.Row in project YCSB by brianfrankcooper.

the class GoogleBigtableClient method read.

@Override
public Status read(String table, String key, Set<String> fields, Map<String, ByteIterator> result) {
    if (debug) {
        System.out.println("Doing read from Bigtable columnfamily " + new String(columnFamilyBytes));
        System.out.println("Doing read for key: " + key);
    }
    setTable(table);
    RowFilter filter = RowFilter.newBuilder().setFamilyNameRegexFilterBytes(ByteStringer.wrap(columnFamilyBytes)).build();
    if (fields != null && fields.size() > 0) {
        Builder filterChain = RowFilter.Chain.newBuilder();
        filterChain.addFilters(filter);
        filterChain.addFilters(RowFilter.newBuilder().setCellsPerColumnLimitFilter(1).build());
        int count = 0;
        // usually "field#" so pre-alloc
        final StringBuilder regex = new StringBuilder(fields.size() * 6);
        for (final String field : fields) {
            if (count++ > 0) {
                regex.append("|");
            }
            regex.append(field);
        }
        filterChain.addFilters(RowFilter.newBuilder().setColumnQualifierRegexFilter(ByteStringer.wrap(regex.toString().getBytes()))).build();
        filter = RowFilter.newBuilder().setChain(filterChain.build()).build();
    }
    final ReadRowsRequest.Builder rrr = ReadRowsRequest.newBuilder().setTableNameBytes(ByteStringer.wrap(lastTableBytes)).setFilter(filter).setRows(RowSet.newBuilder().addRowKeys(ByteStringer.wrap(key.getBytes())));
    List<Row> rows;
    try {
        rows = client.readRowsAsync(rrr.build()).get();
        if (rows == null || rows.isEmpty()) {
            return Status.NOT_FOUND;
        }
        for (final Row row : rows) {
            for (final Family family : row.getFamiliesList()) {
                if (Arrays.equals(family.getNameBytes().toByteArray(), columnFamilyBytes)) {
                    for (final Column column : family.getColumnsList()) {
                        // we should only have a single cell per column
                        result.put(column.getQualifier().toString(UTF8_CHARSET), new ByteArrayByteIterator(column.getCells(0).getValue().toByteArray()));
                        if (debug) {
                            System.out.println("Result for field: " + column.getQualifier().toString(UTF8_CHARSET) + " is: " + column.getCells(0).getValue().toString(UTF8_CHARSET));
                        }
                    }
                }
            }
        }
        return Status.OK;
    } catch (InterruptedException e) {
        System.err.println("Interrupted during get: " + e);
        Thread.currentThread().interrupt();
        return Status.ERROR;
    } catch (ExecutionException e) {
        System.err.println("Exception during get: " + e);
        return Status.ERROR;
    }
}
Also used : Builder(com.google.bigtable.v2.RowFilter.Chain.Builder) ReadRowsRequest(com.google.bigtable.v2.ReadRowsRequest) ByteString(com.google.protobuf.ByteString) ByteArrayByteIterator(site.ycsb.ByteArrayByteIterator) RowFilter(com.google.bigtable.v2.RowFilter) Column(com.google.bigtable.v2.Column) Family(com.google.bigtable.v2.Family) Row(com.google.bigtable.v2.Row) DeleteFromRow(com.google.bigtable.v2.Mutation.DeleteFromRow) ExecutionException(java.util.concurrent.ExecutionException)

Example 79 with Row

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

the class RowReadImplTest method testBinaryToDataType.

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

Example 80 with Row

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

the class PqlTest method testCombineResultSet.

@Test
public void testCombineResultSet() {
    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, numberValue3 });
    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, column3 });
    resultSet2.setRows(new Row[] { row3 });
    ResultSet combinedResultSet = Pql.combineResultSets(resultSet1, resultSet2);
    assertEquals(3, combinedResultSet.getRows().length);
    assertArrayEquals(new ColumnType[] { column1, column2, column3 }, combinedResultSet.getColumnTypes());
    assertArrayEquals(new Value[] { textValue1, booleanValue1, numberValue1 }, combinedResultSet.getRows()[0].getValues());
    assertArrayEquals(new Value[] { textValue2, booleanValue2, numberValue2 }, combinedResultSet.getRows()[1].getValues());
    assertArrayEquals(new Value[] { textValue3, booleanValue3, numberValue3 }, combinedResultSet.getRows()[2].getValues());
}
Also used : ResultSet(com.google.api.ads.admanager.axis.v202105.ResultSet) Row(com.google.api.ads.admanager.axis.v202105.Row) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)68 Row (org.molgenis.emx2.Row)43 Row (com.google.bigtable.v2.Row)22 ArrayList (java.util.ArrayList)17 ByteString (com.google.protobuf.ByteString)14 Table (org.molgenis.emx2.Table)11 Function (com.google.common.base.Function)10 Row (org.hypertrace.entity.query.service.v1.Row)10 Map (java.util.Map)9 ResultSetChunk (org.hypertrace.entity.query.service.v1.ResultSetChunk)8 Schema (org.molgenis.emx2.Schema)8 Row (com.google.api.ads.admanager.axis.v202108.Row)6 Family (com.google.bigtable.v2.Family)6 List (java.util.List)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.axis.v202205.Row)5 Row (com.google.api.ads.admanager.jaxws.v202105.Row)5