use of com.thinkbiganalytics.feedmgr.nifi.controllerservice.ExecuteQueryControllerServiceRequest.ExecuteQueryControllerServiceRequestBuilder in project kylo by Teradata.
the class DBCPConnectionPoolService method generatePreviewQueryForDatasource.
/**
* Generates a preview query on a table that is appropriate for the type of specified data source.
*
* @param datasource the JDBC datasource
* @param schema the schema determining the SQL dialect, or null/empty for the default dialect
* @param tableName the name of the table
* @param limit the result size
* @return the query string
* @throws IllegalArgumentException if the datasource is invalid
*/
@Nonnull
public String generatePreviewQueryForDatasource(@Nonnull final JdbcDatasource datasource, @Nonnull final String schema, @Nonnull final String tableName, final int limit) {
final Optional<ControllerServiceDTO> controllerService = Optional.ofNullable(datasource.getControllerServiceId()).map(id -> getControllerService(id, null));
if (controllerService.isPresent()) {
final DatabaseType dbType = DatabaseType.fromJdbcConnectionString(datasource.getDatabaseConnectionUrl());
final ExecuteQueryControllerServiceRequest serviceProperties = new ExecuteQueryControllerServiceRequestBuilder(controllerService.get()).previewQuery(dbType, schema, tableName, limit).build();
return serviceProperties.getQuery();
} else {
log.error("Cannot execute query for datasource: {}", datasource);
throw new IllegalArgumentException("Missing controller service for datasource: " + datasource);
}
}
use of com.thinkbiganalytics.feedmgr.nifi.controllerservice.ExecuteQueryControllerServiceRequest.ExecuteQueryControllerServiceRequestBuilder in project kylo by Teradata.
the class DBCPConnectionPoolService method executeQueryForDatasource.
/**
* Executes the specified SELECT query in the context of the specified data source.
*
* @param datasource the JDBC datasource
* @param query the query to execute
* @return the query results
* @throws DataAccessException if the query cannot be executed
* @throws IllegalArgumentException if the datasource is invalid
*/
@Nonnull
public QueryResult executeQueryForDatasource(@Nonnull final JdbcDatasource datasource, @Nonnull final String query) {
final Optional<ControllerServiceDTO> controllerService = Optional.ofNullable(datasource.getControllerServiceId()).map(id -> getControllerService(id, null));
if (controllerService.isPresent()) {
final ExecuteQueryControllerServiceRequestBuilder builder = new ExecuteQueryControllerServiceRequestBuilder(controllerService.get());
final ExecuteQueryControllerServiceRequest serviceProperties = builder.password(datasource.getPassword()).query(query).useEnvironmentProperties(false).build();
final PoolingDataSourceService.DataSourceProperties dataSourceProperties = getDataSourceProperties(serviceProperties);
return executeQueryForControllerService(dataSourceProperties, serviceProperties);
} else {
log.error("Cannot execute query for datasource: {}", datasource);
throw new IllegalArgumentException("Missing controller service for datasource: " + datasource);
}
}
use of com.thinkbiganalytics.feedmgr.nifi.controllerservice.ExecuteQueryControllerServiceRequest.ExecuteQueryControllerServiceRequestBuilder in project kylo by Teradata.
the class DBCPConnectionPoolService method executePreviewQueryForControllerService.
/**
* Executes preview query on a table, in the context of the specified controller service, based
* on the supplied schema (if provided) and limit.
*
* @param serviceId a NiFi controller service id
* @param serviceName a NiFi controller service name
* @param tableName the name of the table
* @param schema the schema determining the SQL dialect, or null/empty for the default dialect
* @param limit the result size
* @return the query results
* @throws DataAccessException if the query cannot be executed
* @throws IllegalArgumentException if the controller service cannot be found, the schema/tableName is empty, or the limit is less than zero
*/
public QueryResult executePreviewQueryForControllerService(final String serviceId, final String serviceName, @Nonnull final String schema, @Nonnull final String tableName, final int limit) {
Validate.notEmpty(schema, "No schema provided");
Validate.notEmpty(tableName, "No table name provided");
Validate.isTrue(limit >= 0, "The query result size must be greater than or equal to 0");
final ControllerServiceDTO controllerService = getControllerService(serviceId, serviceName);
if (controllerService != null) {
final ExecuteQueryControllerServiceRequest serviceProperties = new ExecuteQueryControllerServiceRequestBuilder(controllerService).build();
final PoolingDataSourceService.DataSourceProperties dataSourceProperties = getDataSourceProperties(serviceProperties);
final DatabaseType dbType = DatabaseType.fromJdbcConnectionString(dataSourceProperties.getUrl());
final ExecuteQueryControllerServiceRequest previewRequest = new ExecuteQueryControllerServiceRequestBuilder(controllerService).using(serviceProperties).previewQuery(dbType, schema, tableName, limit).build();
return executeQueryForControllerService(dataSourceProperties, previewRequest);
} else {
log.error("Cannot execute query for controller service. Unable to obtain controller service: {}, {}", serviceId, serviceName);
throw new IllegalArgumentException("Not a valid controller service: " + serviceId + ", " + serviceName);
}
}
use of com.thinkbiganalytics.feedmgr.nifi.controllerservice.ExecuteQueryControllerServiceRequest.ExecuteQueryControllerServiceRequestBuilder in project kylo by Teradata.
the class DBCPConnectionPoolService method executeQueryForControllerService.
/**
* Executes the specified SELECT query in the context of the specified controller service.
*
* @param serviceId a NiFi controller service id
* @param serviceName a NiFi controller service name
* @param query the query to execute
* @return the query results
* @throws DataAccessException if the query cannot be executed
* @throws IllegalArgumentException if the controller service cannot be found
*/
@Nonnull
public QueryResult executeQueryForControllerService(@Nonnull final String serviceId, @Nonnull final String serviceName, @Nonnull final String query) {
final ControllerServiceDTO controllerService = getControllerService(serviceId, serviceName);
if (controllerService != null) {
final ExecuteQueryControllerServiceRequestBuilder builder = new ExecuteQueryControllerServiceRequestBuilder(controllerService);
final ExecuteQueryControllerServiceRequest serviceProperties = builder.query(query).build();
final PoolingDataSourceService.DataSourceProperties dataSourceProperties = getDataSourceProperties(serviceProperties);
return executeQueryForControllerService(dataSourceProperties, serviceProperties);
} else {
log.error("Cannot execute query for controller service. Unable to obtain controller service: {}, {}", serviceId, serviceName);
throw new IllegalArgumentException("Not a valid controller service: " + serviceId + ", " + serviceName);
}
}
use of com.thinkbiganalytics.feedmgr.nifi.controllerservice.ExecuteQueryControllerServiceRequest.ExecuteQueryControllerServiceRequestBuilder in project kylo by Teradata.
the class DBCPConnectionPoolService method generatePreviewQueryForControllerService.
/**
* Generates a preview query on a table, in the context of the specified controller service, based
* on the supplied schema (if provided) and limit.
*
* @param serviceId a NiFi controller service id
* @param serviceName a NiFi controller service name
* @param schema the schema determining the SQL dialect, or null/empty for the default dialect
* @param tableName the name of the table
* @param limit the result size
* @return the query results
* @throws DataAccessException if the query cannot be executed
* @throws IllegalArgumentException if the controller service cannot be found, the tableName is empty, or the limit is less than zero
*/
public String generatePreviewQueryForControllerService(final String serviceId, final String serviceName, @Nonnull final String schema, @Nonnull final String tableName, final int limit) {
Validate.notEmpty(schema, "No schema provided");
Validate.notEmpty(tableName, "No table name provided");
Validate.isTrue(limit >= 0, "The query result size must be greater than or equal to 0");
final ControllerServiceDTO controllerService = getControllerService(serviceId, serviceName);
if (controllerService != null) {
final ExecuteQueryControllerServiceRequest serviceProperties = new ExecuteQueryControllerServiceRequestBuilder(controllerService).build();
final PoolingDataSourceService.DataSourceProperties dataSourceProperties = getDataSourceProperties(serviceProperties);
final DatabaseType dbType = DatabaseType.fromJdbcConnectionString(dataSourceProperties.getUrl());
final ExecuteQueryControllerServiceRequest previewRequest = new ExecuteQueryControllerServiceRequestBuilder(controllerService).using(serviceProperties).previewQuery(dbType, schema, tableName, limit).build();
return previewRequest.getQuery();
} else {
log.error("Cannot execute query for controller service. Unable to obtain controller service: {}, {}", serviceId, serviceName);
throw new IllegalArgumentException("Not a valid controller service: " + serviceId + ", " + serviceName);
}
}
Aggregations