private TableSchema tableSchema(Config params)
{
try {
return params.get("schema", TableSchema.class);
}
catch (ConfigException ignore) {
}
String fileName = params.get("schema", String.class);
try {
String schemaString = workspace.templateFile(templateEngine, fileName, UTF_8, params);
if (FilenameUtils.getExtension(fileName).equals("json")) {
return objectMapper.readValue(schemaString, TableSchema.class);
}
else {
ObjectNode schemaJson = new YamlLoader().loadString(schemaString);
return objectMapper.readValue(schemaJson.traverse(), TableSchema.class);
}
}
catch (IOException ex) {
throw workspace.propagateIoException(ex, fileName, ConfigException::new);
}
catch (TemplateException ex) {
throw new ConfigException(
String.format(ENGLISH, "%s in %s", ex.getMessage(), fileName),
ex);
}
}
}