use of com.thinkbiganalytics.discovery.parser.FileSchemaParser in project kylo by Teradata.
the class FileParserFactory method listSchemaParsers.
/**
* Returns a list of available schema parsers. Parsers are guaranteed to be annotated with @SchemaParser and implement FileSchemaParser interface
*
* @return a list of file schema parsers
*/
public List<FileSchemaParser> listSchemaParsers() {
List<FileSchemaParser> supportedParsers = new ArrayList<>();
List<Class<SchemaParser>> supportedParsersClazzes = listSchemaParsersClasses();
for (Class<SchemaParser> clazz : supportedParsersClazzes) {
try {
FileSchemaParser newInstance = (FileSchemaParser) clazz.newInstance();
newInstance = (FileSchemaParser) SpringApplicationContext.autowire(newInstance);
supportedParsers.add(newInstance);
} catch (InstantiationException | IllegalAccessException e) {
log.warn("Failed to instantiate registered schema parser [?]. Missing default constructor?", clazz.getAnnotation(SchemaParser.class).name(), e);
}
}
return supportedParsers;
}
use of com.thinkbiganalytics.discovery.parser.FileSchemaParser in project kylo by Teradata.
the class SchemaDiscoveryRestController method getFileParsers.
@GET
@Path("/file-parsers")
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation("Gets the available file parsers.")
@ApiResponses(@ApiResponse(code = 200, message = "Returns the file parsers.", response = SchemaParserDescriptor.class, responseContainer = "List"))
public Response getFileParsers() {
List<FileSchemaParser> parsers = FileParserFactory.instance().listSchemaParsers();
List<SchemaParserDescriptor> descriptors = new ArrayList<>();
SchemaParserAnnotationTransformer transformer = new SchemaParserAnnotationTransformer();
for (FileSchemaParser parser : parsers) {
SchemaParserDescriptor descriptor = transformer.toUIModel(parser);
descriptors.add(descriptor);
}
return Response.ok(descriptors).build();
}
use of com.thinkbiganalytics.discovery.parser.FileSchemaParser in project kylo by Teradata.
the class SchemaDiscoveryRestController method uploadFile.
@POST
@Path("/hive/sample-file")
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation("Determines the schema of the provided file.")
@ApiResponses({ @ApiResponse(code = 200, message = "Returns the schema.", response = Schema.class), @ApiResponse(code = 500, message = "The schema could not be determined.", response = RestResponseStatus.class) })
public Response uploadFile(@FormDataParam("parser") String parserDescriptor, @FormDataParam("file") InputStream fileInputStream, @FormDataParam("file") FormDataContentDisposition fileMetaData) throws Exception {
Schema schema;
SchemaParserAnnotationTransformer transformer = new SchemaParserAnnotationTransformer();
try {
SchemaParserDescriptor descriptor = ObjectMapperSerializer.deserialize(parserDescriptor, SchemaParserDescriptor.class);
FileSchemaParser p = transformer.fromUiModel(descriptor);
// TODO: Detect charset
schema = p.parse(fileInputStream, Charset.defaultCharset(), TableSchemaType.HIVE);
} catch (IOException e) {
throw new WebApplicationException(e.getMessage());
} catch (PolicyTransformException e) {
log.warn("Failed to convert parser", e);
throw new InternalServerErrorException(STRINGS.getString("discovery.transformError"), e);
}
return Response.ok(schema).build();
}
Aggregations