Search in sources :

Example 16 with IndexSearchCondition

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;
}
Also used : BasicDBObject(com.mongodb.BasicDBObject) IndexSearchCondition(org.apache.hadoop.hive.ql.index.IndexSearchCondition) DBObject(com.mongodb.DBObject) BasicDBObject(com.mongodb.BasicDBObject) BSONObject(org.bson.BSONObject) DBObject(com.mongodb.DBObject) BasicDBObject(com.mongodb.BasicDBObject)

Example 17 with IndexSearchCondition

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;
}
Also used : IndexSearchCondition(org.apache.hadoop.hive.ql.index.IndexSearchCondition) ExprNodeGenericFuncDesc(org.apache.hadoop.hive.ql.plan.ExprNodeGenericFuncDesc) IndexPredicateAnalyzer(org.apache.hadoop.hive.ql.index.IndexPredicateAnalyzer) LinkedList(java.util.LinkedList)

Example 18 with IndexSearchCondition

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));
    }
}
Also used : IndexSearchCondition(org.apache.hadoop.hive.ql.index.IndexSearchCondition) ExprNodeColumnDesc(org.apache.hadoop.hive.ql.plan.ExprNodeColumnDesc) ExprNodeGenericFuncDesc(org.apache.hadoop.hive.ql.plan.ExprNodeGenericFuncDesc) ExprNodeDesc(org.apache.hadoop.hive.ql.plan.ExprNodeDesc) TooManyAccumuloColumnsException(org.apache.hadoop.hive.accumulo.serde.TooManyAccumuloColumnsException) SerDeException(org.apache.hadoop.hive.serde2.SerDeException) GenericUDFOPNotNull(org.apache.hadoop.hive.ql.udf.generic.GenericUDFOPNotNull) Test(org.junit.Test)

Example 19 with IndexSearchCondition

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);
}
Also used : ExprNodeConstantDesc(org.apache.hadoop.hive.ql.plan.ExprNodeConstantDesc) IndexSearchCondition(org.apache.hadoop.hive.ql.index.IndexSearchCondition) ExprNodeColumnDesc(org.apache.hadoop.hive.ql.plan.ExprNodeColumnDesc) GenericUDFOPEqual(org.apache.hadoop.hive.ql.udf.generic.GenericUDFOPEqual) ExprNodeGenericFuncDesc(org.apache.hadoop.hive.ql.plan.ExprNodeGenericFuncDesc) ExprNodeDesc(org.apache.hadoop.hive.ql.plan.ExprNodeDesc) Test(org.junit.Test)

Example 20 with IndexSearchCondition

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);
}
Also used : ExprNodeConstantDesc(org.apache.hadoop.hive.ql.plan.ExprNodeConstantDesc) IndexSearchCondition(org.apache.hadoop.hive.ql.index.IndexSearchCondition) ExprNodeColumnDesc(org.apache.hadoop.hive.ql.plan.ExprNodeColumnDesc) GenericUDFOPEqual(org.apache.hadoop.hive.ql.udf.generic.GenericUDFOPEqual) ExprNodeGenericFuncDesc(org.apache.hadoop.hive.ql.plan.ExprNodeGenericFuncDesc) ExprNodeDesc(org.apache.hadoop.hive.ql.plan.ExprNodeDesc) Test(org.junit.Test)

Aggregations

IndexSearchCondition (org.apache.hadoop.hive.ql.index.IndexSearchCondition)25 IndexPredicateAnalyzer (org.apache.hadoop.hive.ql.index.IndexPredicateAnalyzer)12 ArrayList (java.util.ArrayList)11 ExprNodeDesc (org.apache.hadoop.hive.ql.plan.ExprNodeDesc)10 ExprNodeGenericFuncDesc (org.apache.hadoop.hive.ql.plan.ExprNodeGenericFuncDesc)9 IOException (java.io.IOException)7 HashMap (java.util.HashMap)4 List (java.util.List)4 DecomposedPredicate (org.apache.hadoop.hive.ql.metadata.HiveStoragePredicateHandler.DecomposedPredicate)4 ExprNodeColumnDesc (org.apache.hadoop.hive.ql.plan.ExprNodeColumnDesc)4 ExprNodeConstantDesc (org.apache.hadoop.hive.ql.plan.ExprNodeConstantDesc)4 Test (org.junit.Test)4 GenericUDFOPEqual (org.apache.hadoop.hive.ql.udf.generic.GenericUDFOPEqual)3 LinkedList (java.util.LinkedList)2 FilterList (org.apache.hadoop.hbase.filter.FilterList)2 ExprNodeConstantEvaluator (org.apache.hadoop.hive.ql.exec.ExprNodeConstantEvaluator)2 HiveException (org.apache.hadoop.hive.ql.metadata.HiveException)2 PrimitiveObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector)2 StructTypeInfo (org.apache.hadoop.hive.serde2.typeinfo.StructTypeInfo)2 TypeInfo (org.apache.hadoop.hive.serde2.typeinfo.TypeInfo)2