use of com.hortonworks.registries.common.exception.ParserException in project registry by hortonworks.
the class AbstractStorable method getSchema.
/**
* Default implementation that will generate schema by reading all the field names in the class and use its
* define type to convert to the Schema type.
*
* @return the schema
*/
@JsonIgnore
public Schema getSchema() {
Map<String, Class> fieldNamesToTypes = ReflectionHelper.getFieldNamesToTypes(this.getClass());
List<Schema.Field> fields = new ArrayList<>();
for (Map.Entry<String, Class> entry : fieldNamesToTypes.entrySet()) {
try {
getField(entry.getKey(), entry.getValue()).ifPresent(field -> {
fields.add(field);
LOG.trace("getSchema: Adding {}", field);
});
} catch (NoSuchFieldException | NoSuchMethodException | InvocationTargetException | IllegalAccessException | ParserException e) {
throw new StorageException(e);
}
}
return Schema.of(fields);
}
use of com.hortonworks.registries.common.exception.ParserException 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