@Override public FieldValueList apply(TableRow rowPb) { return FieldValueList.fromPb(rowPb.getF(), null); } }));
@SuppressWarnings("unchecked") static FieldValue fromPb(Object cellPb, Field recordSchema) { if (Data.isNull(cellPb)) { return FieldValue.of(Attribute.PRIMITIVE, null); } if (cellPb instanceof String) { return FieldValue.of(Attribute.PRIMITIVE, cellPb); } if (cellPb instanceof List) { return FieldValue.of(Attribute.REPEATED, FieldValueList.fromPb((List<Object>) cellPb, null)); } if (cellPb instanceof Map) { Map<String, Object> cellMapPb = (Map<String, Object>) cellPb; if (cellMapPb.containsKey("f")) { FieldList subFieldsSchema = recordSchema != null ? recordSchema.getSubFields() : null; return FieldValue.of( Attribute.RECORD, FieldValueList.fromPb((List<Object>) cellMapPb.get("f"), subFieldsSchema)); } // This should never be the case when we are processing a first level table field (i.e. a // row's field, not a record sub-field) if (cellMapPb.containsKey("v")) { return FieldValue.fromPb(cellMapPb.get("v"), recordSchema); } } throw new IllegalArgumentException("Unexpected table cell format"); } }
@Override public FieldValueList apply(TableRow rowPb) { return FieldValueList.fromPb(rowPb.getF(), null); } }));
@SuppressWarnings("unchecked") static FieldValue fromPb(Object cellPb, Field recordSchema) { if (Data.isNull(cellPb)) { return FieldValue.of(Attribute.PRIMITIVE, null); } if (cellPb instanceof String) { return FieldValue.of(Attribute.PRIMITIVE, cellPb); } if (cellPb instanceof List) { return FieldValue.of(Attribute.REPEATED, FieldValueList.fromPb((List<Object>) cellPb, null)); } if (cellPb instanceof Map) { Map<String, Object> cellMapPb = (Map<String, Object>) cellPb; if (cellMapPb.containsKey("f")) { FieldList subFieldsSchema = recordSchema != null ? recordSchema.getSubFields() : null; return FieldValue.of( Attribute.RECORD, FieldValueList.fromPb((List<Object>) cellMapPb.get("f"), subFieldsSchema)); } // This should never be the case when we are processing a first level table field (i.e. a // row's field, not a record sub-field) if (cellMapPb.containsKey("v")) { return FieldValue.fromPb(cellMapPb.get("v"), recordSchema); } } throw new IllegalArgumentException("Unexpected table cell format"); } }