/** * Creates an instance of {@code FieldValueList}, useful for testing. * * <p>This method is unstable. See <a * href="https://github.com/googleapis/google-cloud-java/pull/2891">this discussion</a> for more * context. */ @BetaApi public static FieldValueList of(List<FieldValue> row, Field... schema) { return of(row, schema.length > 0 ? FieldList.of(schema) : null); }
static FieldValueList fromPb(List<?> rowPb, FieldList schema) { List<FieldValue> row = new ArrayList<>(rowPb.size()); if (schema != null) { if (schema.size() != rowPb.size()) { throw new IllegalArgumentException("Row size and fields schema sizes should match"); } Iterator<Field> schemaIter = schema.iterator(); Iterator<?> rowPbIter = rowPb.iterator(); while (rowPbIter.hasNext() && schemaIter.hasNext()) { row.add(FieldValue.fromPb(rowPbIter.next(), schemaIter.next())); } } else { for (Object cellPb : rowPb) { row.add(FieldValue.fromPb(cellPb, null)); } } return FieldValueList.of(row, schema); } }
private static FieldValueList newFieldValueList(String s) { return FieldValueList.of(ImmutableList.of(FieldValue.of(PRIMITIVE, s))); }
@Test public void testNullSchema() { FieldValueList fieldValuesNoSchema = FieldValueList.of( ImmutableList.of( booleanFv, integerFv, floatFv, stringFv, timestampFv, bytesFv, nullFv, repeatedFv, recordFv, numericFv)); assertEquals(fieldValues, fieldValuesNoSchema); UnsupportedOperationException exception = null; try { fieldValuesNoSchema.get("first"); } catch (UnsupportedOperationException e) { exception = e; } assertNotNull(exception); }
/** * Creates an instance of {@code FieldValueList}, useful for testing. * * <p>This method is unstable. See <a * href="https://github.com/googleapis/google-cloud-java/pull/2891">this discussion</a> for more * context. */ @BetaApi public static FieldValueList of(List<FieldValue> row, Field... schema) { return of(row, schema.length > 0 ? FieldList.of(schema) : null); }
static FieldValueList fromPb(List<?> rowPb, FieldList schema) { List<FieldValue> row = new ArrayList<>(rowPb.size()); if (schema != null) { if (schema.size() != rowPb.size()) { throw new IllegalArgumentException("Row size and fields schema sizes should match"); } Iterator<Field> schemaIter = schema.iterator(); Iterator<?> rowPbIter = rowPb.iterator(); while (rowPbIter.hasNext() && schemaIter.hasNext()) { row.add(FieldValue.fromPb(rowPbIter.next(), schemaIter.next())); } } else { for (Object cellPb : rowPb) { row.add(FieldValue.fromPb(cellPb, null)); } } return FieldValueList.of(row, schema); } }