use of com.hortonworks.registries.common.Schema in project streamline by hortonworks.
the class SchemaTest method testSchemaFromJson.
@Test
public void testSchemaFromJson() throws Exception {
String json = "{\"fields\":[{\"name\":\"field1\", \"type\":\"STRING\"},{\"name\":\"field2\", \"type\":\"STRING\"}]}";
System.out.println(json);
ObjectMapper mapper = new ObjectMapper();
Schema schema = mapper.readValue(json, Schema.class);
System.out.println(schema);
}
use of com.hortonworks.registries.common.Schema in project streamline by hortonworks.
the class UDFCatalogResource method getArgTypes.
private List<String> getArgTypes(Class<?> clazz, String methodname, int argStartIndex) {
Method addMethod = findMethod(clazz, methodname);
if (addMethod == null) {
return Collections.emptyList();
}
final Class<?>[] params = addMethod.getParameterTypes();
List<String> argTypes = new ArrayList<>();
for (int i = argStartIndex; i < params.length; i++) {
final Class<?> arg = params[i];
try {
argTypes.add(Schema.fromJavaType(arg).toString());
} catch (ParserException ex) {
Collection<Schema.Type> types = Collections2.filter(Arrays.asList(Schema.Type.values()), new Predicate<Schema.Type>() {
public boolean apply(Schema.Type input) {
return arg.isAssignableFrom(input.getJavaType());
}
});
if (types.isEmpty()) {
LOG.error("Could not find a compatible type in schema for {} argument types", addMethod);
return Collections.emptyList();
} else {
argTypes.add(Joiner.on("|").join(types));
}
}
}
return argTypes;
}
Aggregations