use of com.netflix.metacat.common.server.partition.parser.PartitionParser in project metacat by Netflix.
the class FilterPartition method evaluatePartitionExpression.
/**
* Evaluates the given expression.
* @param partitionExpression expression
* @param name name
* @param path partition uri path
* @param batchid batch id
* @param values map of values
* @return true if the expression evaluates to true
*/
public boolean evaluatePartitionExpression(final String partitionExpression, final String name, final String path, final boolean batchid, final Map<String, String> values) {
if (partitionExpression != null) {
try {
if (parser == null) {
parser = new PartitionParser(new StringReader(partitionExpression));
} else {
parser.ReInit(new StringReader(partitionExpression));
}
context.clear();
if (batchid) {
PartitionUtil.getPartitionKeyValues(path, context);
}
PartitionUtil.getPartitionKeyValues(name, context);
if (values != null) {
context.putAll(values);
}
if (context.size() > 0) {
return (Boolean) parser.filter().jjtAccept(new PartitionParserEval(context), null);
} else {
return false;
}
} catch (ParseException | TokenMgrError e) {
throw new IllegalArgumentException(String.format("Invalid expression: %s", partitionExpression), e);
} catch (IllegalArgumentException e) {
throw e;
} catch (Throwable t) {
log.warn("Caught unexpected exception during evaluatePartitionExpression,", t);
return false;
}
}
return true;
}
use of com.netflix.metacat.common.server.partition.parser.PartitionParser in project metacat by Netflix.
the class HiveConnectorFastPartitionService method getDateCreatedSqlCriteria.
private String getDateCreatedSqlCriteria(final String filterExpression) {
final StringBuilder result = new StringBuilder();
Collection<String> values = Lists.newArrayList();
if (!Strings.isNullOrEmpty(filterExpression)) {
try {
values = (Collection<String>) new PartitionParser(new StringReader(filterExpression)).filter().jjtAccept(new PartitionParamParserEval(), null);
} catch (Throwable ignored) {
//
}
}
for (String value : values) {
if (result.length() != 0) {
result.append(" and ");
}
result.append(value.replace("dateCreated", "p.CREATE_TIME"));
}
return result.toString();
}
use of com.netflix.metacat.common.server.partition.parser.PartitionParser in project metacat by Netflix.
the class HiveConnectorFastPartitionService method getHandlerResults.
private <T> List<T> getHandlerResults(final String databaseName, final String tableName, final String filterExpression, final List<String> partitionIds, final String sql, final ResultSetHandler<List<T>> resultSetHandler, final Sort sort, final Pageable pageable) {
List<T> partitions;
try {
if (!Strings.isNullOrEmpty(filterExpression)) {
final PartitionFilterGenerator generator = new PartitionFilterGenerator(getPartitionKeys(databaseName, tableName));
String filterSql = (String) new PartitionParser(new StringReader(filterExpression)).filter().jjtAccept(generator, null);
if (generator.isOptimized()) {
filterSql = generator.getOptimizedSql();
}
if (filterSql != null && !filterSql.isEmpty()) {
filterSql = " and (" + filterSql + ")";
}
partitions = gethandlerresults(databaseName, tableName, filterExpression, partitionIds, sql, resultSetHandler, generator.joinSql(), filterSql, generator.getParams(), sort, pageable);
} else {
partitions = gethandlerresults(databaseName, tableName, null, partitionIds, sql, resultSetHandler, null, null, null, sort, pageable);
}
} catch (Exception e) {
log.warn("Experiment: Get partitions for for table {} filter {}" + " failed with error {}", tableName, filterExpression, e.getMessage());
registry.counter(HiveMetrics.CounterHiveExperimentGetTablePartitionsFailure.name()).increment();
partitions = gethandlerresults(databaseName, tableName, filterExpression, partitionIds, sql, resultSetHandler, null, prepareFilterSql(filterExpression), Lists.newArrayList(), sort, pageable);
}
return partitions;
}
use of com.netflix.metacat.common.server.partition.parser.PartitionParser in project metacat by Netflix.
the class S3ConnectorPartitionService method getDateCreatedSqlCriteria.
private String getDateCreatedSqlCriteria(final String filterExpression) {
final StringBuilder result = new StringBuilder();
Collection<String> values = com.google.common.collect.Lists.newArrayList();
if (!Strings.isNullOrEmpty(filterExpression)) {
try {
values = (Collection<String>) new PartitionParser(new StringReader(filterExpression)).filter().jjtAccept(new PartitionParamParserEval(), null);
} catch (Throwable ignored) {
//
}
}
for (String value : values) {
if (result.length() != 0) {
result.append(" and ");
}
result.append(value.replace("dateCreated", "to_seconds(p.date_created)"));
}
return result.toString();
}
Aggregations