Search in sources :

Example 31 with FieldValue

use of com.google.cloud.bigquery.FieldValue in project beam by apache.

the class BigQuerySamplesIT method fieldValueListToStrings.

private static List<String> fieldValueListToStrings(FieldValueList row) {
    MyData data = new MyData();
    data.myString = row.get("string_field").getStringValue();
    data.myInt64 = row.get("int64_field").getLongValue();
    data.myFloat64 = row.get("float64_field").getDoubleValue();
    data.myNumeric = new BigDecimal(row.get("numeric_field").getDoubleValue());
    data.myBoolean = row.get("bool_field").getBooleanValue();
    data.myBytes = Base64.getDecoder().decode(row.get("bytes_field").getStringValue());
    data.myDate = LocalDate.parse(row.get("date_field").getStringValue()).toString();
    data.myDateTime = LocalDateTime.parse(row.get("datetime_field").getStringValue()).toString();
    data.myTime = LocalTime.parse(row.get("time_field").getStringValue()).toString();
    data.myTimestamp = Instant.ofEpochMilli((long) (Double.parseDouble(row.get("timestamp_field").getStringValue()) * 1000.0)).toString();
    data.myGeography = row.get("geography_field").getStringValue();
    data.myArray = row.get("array_field").getRepeatedValue().stream().map(FieldValue::getLongValue).collect(Collectors.toList());
    FieldValueList structValues = row.get("struct_field").getRecordValue();
    data.myStruct = new MyStruct();
    data.myStruct.stringValue = structValues.get(0).getStringValue();
    data.myStruct.int64Value = structValues.get(1).getLongValue();
    return myDataToStrings(data);
}
Also used : MyStruct(org.apache.beam.examples.snippets.transforms.io.gcp.bigquery.BigQueryMyData.MyStruct) MyData(org.apache.beam.examples.snippets.transforms.io.gcp.bigquery.BigQueryMyData.MyData) FieldValueList(com.google.cloud.bigquery.FieldValueList) FieldValue(com.google.cloud.bigquery.FieldValue) BigDecimal(java.math.BigDecimal)

Aggregations

FieldValue (com.google.cloud.bigquery.FieldValue)31 QueryResult (com.google.cloud.bigquery.QueryResult)13 Test (org.junit.Test)10 QueryJobConfiguration (com.google.cloud.bigquery.QueryJobConfiguration)9 QueryResponse (com.google.cloud.bigquery.QueryResponse)9 QueryRequest (com.google.cloud.bigquery.QueryRequest)8 List (java.util.List)8 TableId (com.google.cloud.bigquery.TableId)7 BigQuery (com.google.cloud.bigquery.BigQuery)5 ArrayList (java.util.ArrayList)5 ParticipantCriteria (org.pmiops.workbench.cohortbuilder.ParticipantCriteria)5 Job (com.google.cloud.bigquery.Job)4 TableResult (com.google.cloud.bigquery.TableResult)4 ImmutableList (com.google.common.collect.ImmutableList)4 InsertAllResponse (com.google.cloud.bigquery.InsertAllResponse)3 Schema (com.google.cloud.bigquery.Schema)3 TableInfo (com.google.cloud.bigquery.TableInfo)3 SimpleDateFormat (java.text.SimpleDateFormat)3 HashMap (java.util.HashMap)3 PageRequest (org.pmiops.workbench.cohortreview.util.PageRequest)3