Search in sources :

Example 1 with TableCell

use of com.google.api.services.bigquery.model.TableCell in project beam by apache.

the class BigqueryMatcher method formatRows.

private String formatRows(int totalNumRows) {
    StringBuilder samples = new StringBuilder();
    List<TableRow> rows = response.getRows();
    for (int i = 0; i < totalNumRows && i < rows.size(); i++) {
        samples.append(String.format("%n\t\t"));
        for (TableCell field : rows.get(i).getF()) {
            samples.append(String.format("%-10s", field.getV()));
        }
    }
    if (rows.size() > totalNumRows) {
        samples.append(String.format("%n\t\t..."));
    }
    return samples.toString();
}
Also used : TableCell(com.google.api.services.bigquery.model.TableCell) TableRow(com.google.api.services.bigquery.model.TableRow)

Example 2 with TableCell

use of com.google.api.services.bigquery.model.TableCell in project beam by apache.

the class BigqueryMatcher method generateHash.

private String generateHash(@Nonnull List<TableRow> rows) {
    List<HashCode> rowHashes = Lists.newArrayList();
    for (TableRow row : rows) {
        List<String> cellsInOneRow = Lists.newArrayList();
        for (TableCell cell : row.getF()) {
            cellsInOneRow.add(Objects.toString(cell.getV()));
            Collections.sort(cellsInOneRow);
        }
        rowHashes.add(Hashing.sha1().hashString(cellsInOneRow.toString(), StandardCharsets.UTF_8));
    }
    return Hashing.combineUnordered(rowHashes).toString();
}
Also used : HashCode(com.google.common.hash.HashCode) TableCell(com.google.api.services.bigquery.model.TableCell) TableRow(com.google.api.services.bigquery.model.TableRow)

Example 3 with TableCell

use of com.google.api.services.bigquery.model.TableCell in project beam by apache.

the class BigqueryMatcherTest method createResponseContainingTestData.

private QueryResponse createResponseContainingTestData() {
    TableCell field1 = new TableCell();
    field1.setV("abc");
    TableCell field2 = new TableCell();
    field2.setV("2");
    TableCell field3 = new TableCell();
    field3.setV("testing BigQuery matcher.");
    TableRow row = new TableRow();
    row.setF(Lists.newArrayList(field1, field2, field3));
    QueryResponse response = new QueryResponse();
    response.setJobComplete(true);
    response.setRows(Lists.newArrayList(row));
    response.setTotalRows(BigInteger.ONE);
    return response;
}
Also used : TableCell(com.google.api.services.bigquery.model.TableCell) TableRow(com.google.api.services.bigquery.model.TableRow) QueryResponse(com.google.api.services.bigquery.model.QueryResponse)

Example 4 with TableCell

use of com.google.api.services.bigquery.model.TableCell in project zeppelin by apache.

the class BigQueryInterpreter method printRows.

//Function that generates and returns the schema and the rows as string
public static String printRows(final GetQueryResultsResponse response) {
    StringBuilder msg = null;
    msg = new StringBuilder();
    try {
        for (TableFieldSchema schem : response.getSchema().getFields()) {
            msg.append(schem.getName());
            msg.append(TAB);
        }
        msg.append(NEWLINE);
        for (TableRow row : response.getRows()) {
            for (TableCell field : row.getF()) {
                msg.append(field.getV().toString());
                msg.append(TAB);
            }
            msg.append(NEWLINE);
        }
        return msg.toString();
    } catch (NullPointerException ex) {
        throw new NullPointerException("SQL Execution returned an error!");
    }
}
Also used : TableCell(com.google.api.services.bigquery.model.TableCell) TableRow(com.google.api.services.bigquery.model.TableRow) TableFieldSchema(com.google.api.services.bigquery.model.TableFieldSchema)

Aggregations

TableCell (com.google.api.services.bigquery.model.TableCell)4 TableRow (com.google.api.services.bigquery.model.TableRow)4 QueryResponse (com.google.api.services.bigquery.model.QueryResponse)1 TableFieldSchema (com.google.api.services.bigquery.model.TableFieldSchema)1 HashCode (com.google.common.hash.HashCode)1