use of org.apache.drill.metastore.rdbms.exception.RdbmsMetastoreException in project drill by apache.
the class RdbmsMetastore method dataSource.
/**
* Prepares database before initializing data source based on its type,
* initializes {@link HikariDataSource} instance and configures it based on given
* Metastore configuration.
* Basic parameters such as driver, url, user name and password are set using setters.
* Other source parameters are set dynamically through the properties. See the list
* of available Hikari properties: <a href="https://github.com/brettwooldridge/HikariCP">.
*
* @param config Metastore config
* @return Hikari data source instance
* @throws RdbmsMetastoreException if unable to configure Hikari data source
*/
private HikariDataSource dataSource(DrillConfig config) {
DbHelper.init(config).prepareDatabase();
try {
Properties properties = new Properties();
if (config.hasPath(RdbmsConfigConstants.DATA_SOURCE_PROPERTIES)) {
Config propertiesConfig = config.getConfig(RdbmsConfigConstants.DATA_SOURCE_PROPERTIES);
propertiesConfig.entrySet().forEach(e -> properties.put(e.getKey(), e.getValue().unwrapped()));
}
HikariConfig hikariConfig = new HikariConfig(properties);
hikariConfig.setDriverClassName(config.getString(RdbmsConfigConstants.DATA_SOURCE_DRIVER));
hikariConfig.setJdbcUrl(config.getString(RdbmsConfigConstants.DATA_SOURCE_URL));
if (config.hasPath(RdbmsConfigConstants.DATA_SOURCE_USER_NAME)) {
hikariConfig.setUsername(config.getString(RdbmsConfigConstants.DATA_SOURCE_USER_NAME));
}
if (config.hasPath(RdbmsConfigConstants.DATA_SOURCE_PASSWORD)) {
hikariConfig.setPassword(config.getString(RdbmsConfigConstants.DATA_SOURCE_PASSWORD));
}
return new HikariDataSource(hikariConfig);
} catch (RuntimeException e) {
throw new RdbmsMetastoreException("Unable to init RDBMS Metastore data source: " + e.getMessage(), e);
}
}
use of org.apache.drill.metastore.rdbms.exception.RdbmsMetastoreException in project drill by apache.
the class RdbmsRead method internalExecute.
@Override
protected List<T> internalExecute() {
Set<MetadataMapper<T, ? extends Record>> mappers = context.transformer().toMappers(metadataTypes);
if (mappers.isEmpty()) {
return Collections.emptyList();
}
List<T> units = new ArrayList<>();
try (DSLContext executor = context.executorProvider().executor()) {
for (MetadataMapper<T, ? extends Record> mapper : mappers) {
Condition condition = mapper.toCondition(filter);
logger.debug("Query data from RDBMS Metastore table {} using condition: {}", mapper.table(), condition);
List<Field<?>> fields = columns.isEmpty() ? Arrays.asList(mapper.table().fields()) : mapper.toFields(columns);
try {
if (fields.isEmpty()) {
units.addAll(countRecords(executor, mapper, condition));
} else {
units.addAll(queryRecords(executor, mapper, fields, condition));
}
} catch (DataAccessException e) {
throw new RdbmsMetastoreException("Error when reading data from Metastore: " + e.getMessage(), e);
}
}
return units;
}
}
use of org.apache.drill.metastore.rdbms.exception.RdbmsMetastoreException in project drill by apache.
the class AbstractTransformer method toOverwrite.
protected RdbmsOperation.Overwrite toOverwrite(String metadataTypeString, List<T> units) {
MetadataType metadataType = MetadataType.fromValue(metadataTypeString);
if (metadataType == null) {
throw new RdbmsMetastoreException("Metadata type must be specified during insert / update");
} else {
MetadataMapper<T, ? extends Record> mapper = toMapper(metadataType);
List<Condition> deleteConditions = mapper.toDeleteConditions(units);
List<? extends Record> records = units.stream().map(mapper::toRecord).collect(Collectors.toList());
return new RdbmsOperation.Overwrite(mapper.table(), deleteConditions, records);
}
}
use of org.apache.drill.metastore.rdbms.exception.RdbmsMetastoreException in project drill by apache.
the class TestTablesTransformer method testToOverwriteAbsentMetadataType.
@Test
public void testToOverwriteAbsentMetadataType() {
TableMetadataUnit basicUnit = TestData.basicTableMetadataUnit();
List<TableMetadataUnit> units = Arrays.asList(basicUnit.toBuilder().metadataType(MetadataType.TABLE.name()).build(), basicUnit.toBuilder().metadataType(MetadataType.VIEW.name()).build());
try {
TRANSFORMER.toOverwrite(units);
fail();
} catch (RdbmsMetastoreException e) {
assertThat(e.getMessage(), startsWith("Metadata mapper is absent for type"));
}
}
use of org.apache.drill.metastore.rdbms.exception.RdbmsMetastoreException in project drill by apache.
the class RdbmsMetastore method initTables.
/**
* Initializes RDBMS Metastore tables structure based on {@link #LIQUIBASE_CHANGELOG_FILE} file.
* See <a href="https://www.liquibase.org/documentation/core-concepts/index.html"> for more details.
*
* @param dataSource data source
*/
private void initTables(DataSource dataSource) {
try (Connection connection = dataSource.getConnection()) {
JdbcConnection jdbcConnection = new JdbcConnection(connection);
Database database = DatabaseFactory.getInstance().findCorrectDatabaseImplementation(jdbcConnection);
ClassLoaderResourceAccessor resourceAccessor = new ClassLoaderResourceAccessor();
try (Liquibase liquibase = new Liquibase(LIQUIBASE_CHANGELOG_FILE, resourceAccessor, database)) {
liquibase.update("");
}
} catch (Exception e) {
throw new RdbmsMetastoreException("Unable to init Metastore tables using Liquibase: " + e.getMessage(), e);
}
}
Aggregations