@Test(expected = DataException.class) public void testValidateValueMismatchDate() { ConnectSchema.validateValue(Date.SCHEMA, 1000L); }
public static void validateValue(Schema schema, Object value) { if (value == null) { if (!schema.isOptional()) throw new DataException("Invalid value: null used for required field"); else return; } List<Class> expectedClasses = LOGICAL_TYPE_CLASSES.get(schema.name()); if (expectedClasses == null) expectedClasses = SCHEMA_TYPE_CLASSES.get(schema.type()); if (expectedClasses == null) throw new DataException("Invalid Java object for schema type " + schema.type() + ": " + value.getClass()); boolean foundMatch = false; for (Class<?> expectedClass : expectedClasses) { if (expectedClass.isInstance(value)) { foundMatch = true; break; } } if (!foundMatch) throw new DataException("Invalid Java object for schema type " + schema.type() + ": " + value.getClass()); switch (schema.type()) { case STRUCT: Struct struct = (Struct) value; if (!struct.schema().equals(schema)) throw new DataException("Struct schemas do not match."); struct.validate(); break; case ARRAY: List<?> array = (List<?>) value; for (Object entry : array) validateValue(schema.valueSchema(), entry); break; case MAP: Map<?, ?> map = (Map<?, ?>) value; for (Map.Entry<?, ?> entry : map.entrySet()) { validateValue(schema.keySchema(), entry.getKey()); validateValue(schema.valueSchema(), entry.getValue()); } break; } }
ConnectSchema implements Schema { public static void validateValue(Schema schema, Object value) { if (value == null) { if (!schema.isOptional()) throw new DataException("Invalid value: null used for required field"); else return; } List<Class> expectedClasses = LOGICAL_TYPE_CLASSES.get(schema.name()); if (expectedClasses == null) expectedClasses = SCHEMA_TYPE_CLASSES.get(schema.type()); if (expectedClasses == null) throw new DataException("Invalid Java object for schema type " + schema.type() + ": " + value.getClass()); boolean foundMatch = false; for (Class<?> expectedClass : expectedClasses) { if (expectedClass.isInstance(value)) { foundMatch = true; break; } } if (!foundMatch) throw new DataException("Invalid Java object for schema type " + schema.type() + ": " + value.getClass()); switch (schema.type()) { case STRUCT: Struct struct = (Struct) value; if (!struct.schema().equals(schema)) throw new DataException("Struct schemas do not match."); struct.validate(); break; case ARRAY: List<?> array = (List<?>) value; for (Object entry : array) validateValue(schema.valueSchema(), entry); break; case MAP: Map<?, ?> map = (Map<?, ?>) value; for (Map.Entry<?, ?> entry : map.entrySet()) { validateValue(schema.keySchema(), entry.getKey()); validateValue(schema.valueSchema(), entry.getValue()); } break; } } }
ConnectSchema implements Schema { public static void validateValue(Schema schema, Object value) { if (value == null) { if (!schema.isOptional()) throw new DataException("Invalid value: null used for required field"); else return; } List<Class> expectedClasses = LOGICAL_TYPE_CLASSES.get(schema.name()); if (expectedClasses == null) expectedClasses = SCHEMA_TYPE_CLASSES.get(schema.type()); if (expectedClasses == null) throw new DataException("Invalid Java object for schema type " + schema.type() + ": " + value.getClass()); boolean foundMatch = false; for (Class<?> expectedClass : expectedClasses) { if (expectedClass.isInstance(value)) { foundMatch = true; break; } } if (!foundMatch) throw new DataException("Invalid Java object for schema type " + schema.type() + ": " + value.getClass()); switch (schema.type()) { case STRUCT: Struct struct = (Struct) value; if (!struct.schema().equals(schema)) throw new DataException("Struct schemas do not match."); struct.validate(); break; case ARRAY: List<?> array = (List<?>) value; for (Object entry : array) validateValue(schema.valueSchema(), entry); break; case MAP: Map<?, ?> map = (Map<?, ?>) value; for (Map.Entry<?, ?> entry : map.entrySet()) { validateValue(schema.keySchema(), entry.getKey()); validateValue(schema.valueSchema(), entry.getValue()); } break; } } ConnectSchema(Type type, boolean optional, Object defaultValue, String name, Integer version, String doc, Map<String, String> parameters, List<Field> fields, Schema keySchema, Schema valueSchema);  ConnectSchema(Type type, boolean optional, Object defaultValue, String name, Integer version, String doc);  ConnectSchema(Type type); }
ConnectSchema implements Schema { public static void validateValue(Schema schema, Object value) { if (value == null) { if (!schema.isOptional()) throw new DataException("Invalid value: null used for required field"); else return; } List<Class> expectedClasses = LOGICAL_TYPE_CLASSES.get(schema.name()); if (expectedClasses == null) expectedClasses = SCHEMA_TYPE_CLASSES.get(schema.type()); if (expectedClasses == null) throw new DataException("Invalid Java object for schema type " + schema.type() + ": " + value.getClass()); boolean foundMatch = false; for (Class<?> expectedClass : expectedClasses) { if (expectedClass.isInstance(value)) { foundMatch = true; break; } } if (!foundMatch) throw new DataException("Invalid Java object for schema type " + schema.type() + ": " + value.getClass()); switch (schema.type()) { case STRUCT: Struct struct = (Struct) value; if (!struct.schema().equals(schema)) throw new DataException("Struct schemas do not match."); struct.validate(); break; case ARRAY: List<?> array = (List<?>) value; for (Object entry : array) validateValue(schema.valueSchema(), entry); break; case MAP: Map<?, ?> map = (Map<?, ?>) value; for (Map.Entry<?, ?> entry : map.entrySet()) { validateValue(schema.keySchema(), entry.getKey()); validateValue(schema.valueSchema(), entry.getValue()); } break; } } ConnectSchema(Type type, boolean optional, Object defaultValue, String name, Integer version, String doc, Map<String, String> parameters, List<Field> fields, Schema keySchema, Schema valueSchema);  ConnectSchema(Type type, boolean optional, Object defaultValue, String name, Integer version, String doc);  ConnectSchema(Type type); @Override Type type(); @Override boolean isOptional(); @Override Object defaultValue(); @Override String name(); @Override Integer version(); @Override String doc(); @Override Map<String, String> parameters(); @Override List<Field> fields(); Field field(String fieldName); @Override Schema keySchema(); @Override Schema valueSchema(); static void validateValue(Schema schema, Object value); void validateValue(Object value); @Override ConnectSchema schema(); @Override boolean equals(Object o); @Override int hashCode(); @Override String toString(); static Type schemaType(Class<?> klass); }
ConnectSchema implements Schema { public static void validateValue(Schema schema, Object value) { if (value == null) { if (!schema.isOptional()) throw new DataException("Invalid value: null used for required field"); else return; } List<Class> expectedClasses = LOGICAL_TYPE_CLASSES.get(schema.name()); if (expectedClasses == null) expectedClasses = SCHEMA_TYPE_CLASSES.get(schema.type()); if (expectedClasses == null) throw new DataException("Invalid Java object for schema type " + schema.type() + ": " + value.getClass()); boolean foundMatch = false; for (Class<?> expectedClass : expectedClasses) { if (expectedClass.isInstance(value)) { foundMatch = true; break; } } if (!foundMatch) throw new DataException("Invalid Java object for schema type " + schema.type() + ": " + value.getClass()); switch (schema.type()) { case STRUCT: Struct struct = (Struct) value; if (!struct.schema().equals(schema)) throw new DataException("Struct schemas do not match."); struct.validate(); break; case ARRAY: List<?> array = (List<?>) value; for (Object entry : array) validateValue(schema.valueSchema(), entry); break; case MAP: Map<?, ?> map = (Map<?, ?>) value; for (Map.Entry<?, ?> entry : map.entrySet()) { validateValue(schema.keySchema(), entry.getKey()); validateValue(schema.valueSchema(), entry.getValue()); } break; } } ConnectSchema(Type type, boolean optional, Object defaultValue, String name, Integer version, String doc, Map<String, String> parameters, List<Field> fields, Schema keySchema, Schema valueSchema);  ConnectSchema(Type type, boolean optional, Object defaultValue, String name, Integer version, String doc);  ConnectSchema(Type type); @Override Type type(); @Override boolean isOptional(); @Override Object defaultValue(); @Override String name(); @Override Integer version(); @Override String doc(); @Override Map<String, String> parameters(); @Override List<Field> fields(); Field field(String fieldName); @Override Schema keySchema(); @Override Schema valueSchema(); static void validateValue(Schema schema, Object value); void validateValue(Object value); @Override ConnectSchema schema(); @Override boolean equals(Object o); @Override int hashCode(); @Override String toString(); static Type schemaType(Class<?> klass);  }