use of com.thinkbiganalytics.spark.rest.model.PreviewDataSetRequest in project kylo by Teradata.
the class KyloCatalogReaderUtil method toKyloCatalogRequest.
public static KyloCatalogReadRequest toKyloCatalogRequest(PreviewDataSetRequest previewRequest) {
DataSource dataSource = previewRequest.getDataSource();
Connector connector = dataSource.getConnector();
// merge template
DataSetTemplate dataSetTemplate = DataSourceUtil.mergeTemplates(dataSource);
// get data out of the dataset template
List<String> jars = dataSetTemplate.getJars();
List<String> paths = dataSetTemplate.getPaths();
List<String> files = dataSetTemplate.getFiles();
String format = dataSetTemplate.getFormat();
Map<String, String> options = dataSetTemplate.getOptions();
if (options == null) {
options = new HashMap<>();
}
// parse the SchemaParser if it exists and add options and update the format
if (previewRequest.getSchemaParser() != null) {
SchemaParserDescriptor schemaParser = previewRequest.getSchemaParser();
Map<String, String> sparkOptions = schemaParser.getProperties().stream().collect(Collectors.toMap(p -> p.getAdditionalProperties().stream().filter(labelValue -> "spark.option".equalsIgnoreCase(labelValue.getLabel())).map(labelValue -> labelValue.getValue()).findFirst().orElse(""), p -> p.getValue()));
// remove any options that produced an empty key
sparkOptions.remove("");
// supplied options by the schema parse take precedence over the template options
options.putAll(sparkOptions);
format = schemaParser.getSparkFormat();
}
// add in additional preview options
if (previewRequest.getProperties() != null && !previewRequest.getProperties().isEmpty()) {
options.putAll(previewRequest.getProperties());
}
KyloCatalogReadRequest request = new KyloCatalogReadRequest();
request.setFiles(files);
request.setJars(jars);
request.setFormat(format);
request.setOptions(options);
if (previewRequest.getPreviewItem() != null && previewRequest.isAddPreviewItemToPath()) {
request.addPath(previewRequest.getPreviewItem());
}
PageSpec pageSpec = previewRequest.getPageSpec();
if (pageSpec == null) {
pageSpec = new PageSpec();
}
request.setPageSpec(pageSpec);
return request;
}
Aggregations