use of org.apache.asterix.external.api.IDataParserFactory in project asterixdb by apache.
the class ExternalDataUtils method createExternalParserFactory.
public static IDataParserFactory createExternalParserFactory(ILibraryManager libraryManager, String dataverse, String parserFactoryName) throws AsterixException {
try {
String library = parserFactoryName.substring(0, parserFactoryName.indexOf(ExternalDataConstants.EXTERNAL_LIBRARY_SEPARATOR));
ClassLoader classLoader = libraryManager.getLibraryClassLoader(dataverse, library);
return (IDataParserFactory) classLoader.loadClass(parserFactoryName.substring(parserFactoryName.indexOf(ExternalDataConstants.EXTERNAL_LIBRARY_SEPARATOR) + 1)).newInstance();
} catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) {
throw new AsterixException("Failed to create an external parser factory", e);
}
}
use of org.apache.asterix.external.api.IDataParserFactory in project asterixdb by apache.
the class ParserFactoryProvider method getDataParserFactory.
public static IDataParserFactory getDataParserFactory(ILibraryManager libraryManager, Map<String, String> configuration) throws AsterixException {
IDataParserFactory parserFactory;
String parserFactoryName = configuration.get(ExternalDataConstants.KEY_DATA_PARSER);
if ((parserFactoryName != null) && ExternalDataUtils.isExternal(parserFactoryName)) {
return ExternalDataUtils.createExternalParserFactory(libraryManager, ExternalDataUtils.getDataverse(configuration), parserFactoryName);
} else {
String parserFactoryKey = ExternalDataUtils.getRecordFormat(configuration);
if (parserFactoryKey == null) {
parserFactoryKey = configuration.get(ExternalDataConstants.KEY_PARSER_FACTORY);
}
parserFactory = ParserFactoryProvider.getDataParserFactory(parserFactoryKey);
}
return parserFactory;
}
use of org.apache.asterix.external.api.IDataParserFactory in project asterixdb by apache.
the class ParserFactoryProvider method initFactories.
protected static Map<String, Class> initFactories() throws AsterixException {
Map<String, Class> factories = new HashMap<>();
ClassLoader cl = ParserFactoryProvider.class.getClassLoader();
try {
Enumeration<URL> urls = cl.getResources(RESOURCE);
for (URL url : Collections.list(urls)) {
List<String> classNames;
try (InputStream is = url.openStream()) {
classNames = IOUtils.readLines(is, StandardCharsets.UTF_8);
}
for (String className : classNames) {
if (className.startsWith("#")) {
continue;
}
final Class<?> clazz = Class.forName(className);
List<String> formats = ((IDataParserFactory) clazz.newInstance()).getParserFormats();
for (String format : formats) {
if (factories.containsKey(format)) {
throw new AsterixException("Duplicate format " + format);
}
factories.put(format, clazz);
}
}
}
} catch (IOException | ClassNotFoundException | InstantiationException | IllegalAccessException e) {
throw new AsterixException(e);
}
return factories;
}
Aggregations