rendering hive tables with new lines
@@ -37,6 +37,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.dao.DataAccessException;
+import org.springframework.dao.DataRetrievalFailureException;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
@@ -44,6 +45,7 @@ import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
@@ -192,13 +194,21 @@ public class HiveService {
return "SELECT kylo_.* FROM (" + query + ") kylo_ LIMIT 1000";
}
+ private boolean validateQuery(String query) {
+ String[] validSql = new String[]{"show", "select","desc","describe"};
+ String testQuery = StringUtils.trimToEmpty(query).toLowerCase();
+ if (StringUtils.isNotEmpty(testQuery) && Arrays.stream(validSql).anyMatch(start -> testQuery.startsWith(start))) {
+ return true;
+ }
+ return false;
+ }
public QueryResult query(String query) throws DataAccessException {
final DefaultQueryResult queryResult = new DefaultQueryResult(query);
final List<QueryResultColumn> columns = new ArrayList<>();
final Map<String, Integer> displayNameMap = new HashMap<>();
- if (query != null && !query.toLowerCase().startsWith("show")) {
- query = safeQuery(query);
+ if(!validateQuery(query)){
+ throw new DataRetrievalFailureException("Invalid Query: "+query);
}
try {
// Setting in order to query complex formats like parquet
@@ -215,7 +225,7 @@ public class HiveService {
String displayName = rsMetaData.getColumnLabel(i);
column.setHiveColumnLabel(displayName);
//remove the table name if it exists
- displayName = StringUtils.substringAfterLast(displayName, ".");
+ displayName =StringUtils.contains(displayName,".") ? StringUtils.substringAfterLast(displayName, ".") : displayName;
Integer count = 0;
if (displayNameMap.containsKey(displayName)) {
count = displayNameMap.get(displayName);
