@Test public void testNestedFieldSchemaWrongType() throws DataException { Schema schema = createSchemaWithTimestampField(); Field f = DataUtils.getNestedField(schema, "string"); Exception e = assertThrows(DataException.class, () -> { DataUtils.getNestedField(f.schema(), "foo"); }); assertThat(e.getMessage(), startsWith("Unable to get field")); }
public static Field getNestedField(Schema schema, String fieldName) { validate(schema, fieldName); final String[] fieldNames = fieldName.split("\\."); try { Field innermost = schema.field(fieldNames[0]); for (int i = 1; i < fieldNames.length; ++i) { innermost = innermost.schema().field(fieldNames[i]); } return innermost; } catch (DataException e) { throw new DataException( String.format("Unable to get field '%s' from schema %s.", fieldName, schema), e ); } }
DataUtils { public static Field getNestedField(Schema schema, String fieldName) { validate(schema, fieldName); final String[] fieldNames = fieldName.split("\\."); try { Field innermost = schema.field(fieldNames[0]); for (int i = 1; i < fieldNames.length; ++i) { innermost = innermost.schema().field(fieldNames[i]); } return innermost; } catch (DataException e) { throw new DataException( String.format("Unable to get field '%s' from schema %s.", fieldName, schema), e ); } } }
DataUtils { public static Field getNestedField(Schema schema, String fieldName) { validate(schema, fieldName); final String[] fieldNames = fieldName.split("\\."); try { Field innermost = schema.field(fieldNames[0]); for (int i = 1; i < fieldNames.length; ++i) { innermost = innermost.schema().field(fieldNames[i]); } return innermost; } catch (DataException e) { throw new DataException( String.format("Unable to get field '%s' from schema %s.", fieldName, schema), e ); } }  }
DataUtils { public static Field getNestedField(Schema schema, String fieldName) { validate(schema, fieldName); final String[] fieldNames = fieldName.split("\\."); try { Field innermost = schema.field(fieldNames[0]); for (int i = 1; i < fieldNames.length; ++i) { innermost = innermost.schema().field(fieldNames[i]); } return innermost; } catch (DataException e) { throw new DataException( String.format("Unable to get field '%s' from schema %s.", fieldName, schema), e ); } }  static Object getField(Object structOrMap, String fieldName); static Object getNestedFieldValue(Object structOrMap, String fieldName); static Field getNestedField(Schema schema, String fieldName); }
DataUtils { public static Field getNestedField(Schema schema, String fieldName) { validate(schema, fieldName); final String[] fieldNames = fieldName.split("\\."); try { Field innermost = schema.field(fieldNames[0]); for (int i = 1; i < fieldNames.length; ++i) { innermost = innermost.schema().field(fieldNames[i]); } return innermost; } catch (DataException e) { throw new DataException( String.format("Unable to get field '%s' from schema %s.", fieldName, schema), e ); } }  static Object getField(Object structOrMap, String fieldName); static Object getNestedFieldValue(Object structOrMap, String fieldName); static Field getNestedField(Schema schema, String fieldName);  }