use of com.thinkbiganalytics.discovery.model.DefaultQueryResult in project kylo by Teradata.
the class QueryRunner method query.
/**
* Executes the specified SELECT query and returns the results.
*
* @param query the SELECT query
* @return the query result
* @throws DataAccessException if the query cannot be executed
*/
public QueryResult query(String query) {
// Validate the query
if (!validateQuery(query)) {
throw new DataRetrievalFailureException("Invalid query: " + query);
}
// Execute the query
final DefaultQueryResult queryResult = new DefaultQueryResult(query);
jdbcTemplate.query(query, new RowCallbackHandler() {
@Override
public void processRow(ResultSet rs) throws SQLException {
// First-time initialization
if (queryResult.isEmpty()) {
QueryRunner.this.initQueryResult(queryResult, rs.getMetaData());
}
// Add row to the result
final Map<String, Object> row = new LinkedHashMap<>();
for (final QueryResultColumn column : queryResult.getColumns()) {
row.put(column.getDisplayName(), rs.getObject(column.getHiveColumnLabel()));
}
queryResult.addRow(row);
}
});
return queryResult;
}
Aggregations