@Test public void testValidateNullField() throws ConnectException { Schema schema = createSchemaWithTimestampField(); Exception e = assertThrows(ConnectException.class, () -> { DataUtils.getNestedField(schema, null); }); assertEquals("The field to extract cannot be null or empty.", e.getMessage()); }
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);  }