use of org.apache.hadoop.hive.ql.index.IndexSearchCondition in project mongo-hadoop by mongodb.
the class HiveMongoInputFormat method getFilter.
DBObject getFilter(final List<IndexSearchCondition> searchConditions, final Map<String, String> colToMongoNames) {
DBObject filter = new BasicDBObject();
for (IndexSearchCondition isc : searchConditions) {
String comparisonName = isc.getComparisonOp();
Object constant = isc.getConstantDesc().getValue();
String columnName = isc.getColumnDesc().getColumn();
String mongoName = resolveMongoName(columnName, colToMongoNames);
if (EQUAL_OP.equals(comparisonName)) {
filter.put(mongoName, constant);
} else {
String mongoOp = MONGO_OPS.get(comparisonName);
if (mongoOp != null) {
filter.put(mongoName, new BasicDBObject(mongoOp, constant));
} else {
// Log the fact that we don't support this operator.
// It's still ok to return a query; we'll just return a
// super set of the documents needed by Hive.
LOG.warn("unsupported operator type: " + comparisonName);
}
}
}
return filter;
}
use of org.apache.hadoop.hive.ql.index.IndexSearchCondition in project mongo-hadoop by mongodb.
the class HiveMongoInputFormat method getFilter.
DBObject getFilter(final JobConf conf, final Map<String, String> colToMongoNames) {
String serializedExpr = conf.get(TableScanDesc.FILTER_EXPR_CONF_STR);
if (serializedExpr != null) {
ExprNodeGenericFuncDesc expr = Utilities.deserializeExpression(serializedExpr);
IndexPredicateAnalyzer analyzer = IndexPredicateAnalyzer.createAnalyzer(false);
// Allow all column names.
String columnNamesStr = conf.get(ColumnProjectionUtils.READ_COLUMN_NAMES_CONF_STR);
String[] columnNames = StringUtils.split(columnNamesStr, '\\', StringUtils.COMMA);
for (String colName : columnNames) {
analyzer.allowColumnName(colName);
}
List<IndexSearchCondition> searchConditions = new LinkedList<IndexSearchCondition>();
analyzer.analyzePredicate(expr, searchConditions);
return getFilter(searchConditions, colToMongoNames);
}
return null;
}
use of org.apache.hadoop.hive.ql.index.IndexSearchCondition in project hive by apache.
the class TestAccumuloPredicateHandler method testPushdownComparisonOptNotSupported.
@Test
public void testPushdownComparisonOptNotSupported() {
try {
ExprNodeDesc column = new ExprNodeColumnDesc(TypeInfoFactory.stringTypeInfo, "field1", null, false);
List<ExprNodeDesc> children = Lists.newArrayList();
children.add(column);
ExprNodeGenericFuncDesc node = new ExprNodeGenericFuncDesc(TypeInfoFactory.stringTypeInfo, new GenericUDFOPNotNull(), children);
assertNotNull(node);
String filterExpr = SerializationUtilities.serializeExpression(node);
conf.set(TableScanDesc.FILTER_EXPR_CONF_STR, filterExpr);
List<IndexSearchCondition> sConditions = handler.getSearchConditions(conf);
assertEquals(sConditions.size(), 1);
IndexSearchCondition sc = sConditions.get(0);
new PushdownTuple(sc, handler.getPrimitiveComparison(sc.getColumnDesc().getTypeString(), sc), handler.getCompareOp(sc.getComparisonOp(), sc));
fail("Should fail: compare op not registered for index analyzer. Should leave undesirable residual predicate");
} catch (RuntimeException e) {
assertTrue(e.getMessage().contains("Unexpected residual predicate: field1 is not null"));
} catch (Exception e) {
fail(StringUtils.stringifyException(e));
}
}
use of org.apache.hadoop.hive.ql.index.IndexSearchCondition in project hive by apache.
the class TestAccumuloPredicateHandler method testGetRowIDSearchCondition.
@Test
public void testGetRowIDSearchCondition() {
ExprNodeDesc column = new ExprNodeColumnDesc(TypeInfoFactory.stringTypeInfo, "rid", null, false);
ExprNodeDesc constant = new ExprNodeConstantDesc(TypeInfoFactory.stringTypeInfo, "hi");
List<ExprNodeDesc> children = Lists.newArrayList();
children.add(column);
children.add(constant);
ExprNodeGenericFuncDesc node = new ExprNodeGenericFuncDesc(TypeInfoFactory.stringTypeInfo, new GenericUDFOPEqual(), children);
assertNotNull(node);
String filterExpr = SerializationUtilities.serializeExpression(node);
conf.set(TableScanDesc.FILTER_EXPR_CONF_STR, filterExpr);
List<IndexSearchCondition> sConditions = handler.getSearchConditions(conf);
assertEquals(sConditions.size(), 1);
}
use of org.apache.hadoop.hive.ql.index.IndexSearchCondition in project hive by apache.
the class TestAccumuloPredicateHandler method testPushdownColumnTypeNotSupported.
@Test(expected = NoSuchPrimitiveComparisonException.class)
public void testPushdownColumnTypeNotSupported() throws SerDeException, NoSuchPrimitiveComparisonException, NoSuchCompareOpException {
ExprNodeDesc column = new ExprNodeColumnDesc(TypeInfoFactory.floatTypeInfo, "field1", null, false);
ExprNodeDesc constant = new ExprNodeConstantDesc(TypeInfoFactory.floatTypeInfo, 5.5f);
List<ExprNodeDesc> children = Lists.newArrayList();
children.add(column);
children.add(constant);
ExprNodeGenericFuncDesc node = new ExprNodeGenericFuncDesc(TypeInfoFactory.stringTypeInfo, new GenericUDFOPEqual(), children);
assertNotNull(node);
String filterExpr = SerializationUtilities.serializeExpression(node);
conf.set(TableScanDesc.FILTER_EXPR_CONF_STR, filterExpr);
List<IndexSearchCondition> sConditions = handler.getSearchConditions(conf);
assertEquals(sConditions.size(), 1);
IndexSearchCondition sc = sConditions.get(0);
handler.getPrimitiveComparison(sc.getColumnDesc().getTypeString(), sc);
}
Aggregations