Search in sources :

Example 1 with KuduPredicate

use of org.apache.kudu.client.KuduPredicate in project hive by apache.

the class TestKuduPredicateHandler method testComparisonPredicates.

@Test
public void testComparisonPredicates() throws Exception {
    for (ColumnSchema col : SCHEMA.getColumns()) {
        // Skip null and default columns because they don't have a value to use.
        if (col.getName().equals("null") || col.getName().equals("default")) {
            continue;
        }
        PrimitiveTypeInfo typeInfo = toHiveType(col.getType(), col.getTypeAttributes());
        ExprNodeDesc colExpr = new ExprNodeColumnDesc(typeInfo, col.getName(), null, false);
        ExprNodeDesc constExpr = new ExprNodeConstantDesc(typeInfo, ROW.getObject(col.getName()));
        List<ExprNodeDesc> children = Lists.newArrayList();
        children.add(colExpr);
        children.add(constExpr);
        for (GenericUDF udf : COMPARISON_UDFS) {
            ExprNodeGenericFuncDesc predicateExpr = new ExprNodeGenericFuncDesc(typeInfo, udf, children);
            // Verify KuduPredicateHandler.decompose
            HiveStoragePredicateHandler.DecomposedPredicate decompose = KuduPredicateHandler.decompose(predicateExpr, SCHEMA);
            // Binary predicates are not supported. (HIVE-11370)
            if (col.getName().equals("binary")) {
                assertNull(decompose);
            } else {
                assertNotNull(String.format("Unsupported comparison UDF and type (%s, %s)", udf, typeInfo), decompose);
                assertNotNull(String.format("Unsupported comparison UDF and type (%s, %s)", udf, typeInfo), decompose.pushedPredicate);
                assertNull(String.format("Unsupported comparison UDF and type (%s, %s)", udf, typeInfo), decompose.residualPredicate);
                List<KuduPredicate> predicates = expressionToPredicates(predicateExpr);
                assertEquals(1, predicates.size());
                scanWithPredicates(predicates);
            }
        }
    }
}
Also used : HiveStoragePredicateHandler(org.apache.hadoop.hive.ql.metadata.HiveStoragePredicateHandler) ExprNodeConstantDesc(org.apache.hadoop.hive.ql.plan.ExprNodeConstantDesc) GenericUDF(org.apache.hadoop.hive.ql.udf.generic.GenericUDF) ExprNodeColumnDesc(org.apache.hadoop.hive.ql.plan.ExprNodeColumnDesc) ExprNodeGenericFuncDesc(org.apache.hadoop.hive.ql.plan.ExprNodeGenericFuncDesc) ColumnSchema(org.apache.kudu.ColumnSchema) ExprNodeDesc(org.apache.hadoop.hive.ql.plan.ExprNodeDesc) PrimitiveTypeInfo(org.apache.hadoop.hive.serde2.typeinfo.PrimitiveTypeInfo) KuduPredicate(org.apache.kudu.client.KuduPredicate) Test(org.junit.Test)

Example 2 with KuduPredicate

use of org.apache.kudu.client.KuduPredicate in project hive by apache.

the class TestKuduPredicateHandler method testAndPredicates.

@Test
public void testAndPredicates() throws Exception {
    for (ColumnSchema col : SCHEMA.getColumns()) {
        // Skip null and default columns because they don't have a value to use.
        if (col.getName().equals("null") || col.getName().equals("default")) {
            continue;
        }
        PrimitiveTypeInfo typeInfo = toHiveType(col.getType(), col.getTypeAttributes());
        ExprNodeDesc colExpr = new ExprNodeColumnDesc(typeInfo, col.getName(), null, false);
        ExprNodeDesc constExpr = new ExprNodeConstantDesc(typeInfo, ROW.getObject(col.getName()));
        List<ExprNodeDesc> children = Lists.newArrayList();
        children.add(colExpr);
        children.add(constExpr);
        ExprNodeGenericFuncDesc gePredicateExpr = new ExprNodeGenericFuncDesc(typeInfo, new GenericUDFOPEqualOrGreaterThan(), children);
        ExprNodeGenericFuncDesc lePredicateExpr = new ExprNodeGenericFuncDesc(typeInfo, new GenericUDFOPEqualOrLessThan(), children);
        List<ExprNodeDesc> andChildren = Lists.newArrayList();
        andChildren.add(gePredicateExpr);
        andChildren.add(lePredicateExpr);
        ExprNodeGenericFuncDesc andPredicateExpr = new ExprNodeGenericFuncDesc(typeInfo, new GenericUDFOPAnd(), andChildren);
        // Verify KuduPredicateHandler.decompose
        HiveStoragePredicateHandler.DecomposedPredicate decompose = KuduPredicateHandler.decompose(andPredicateExpr, SCHEMA);
        // Binary predicates are not supported. (HIVE-11370)
        if (col.getName().equals("binary")) {
            assertNull(decompose);
        } else {
            assertNotNull(decompose);
            assertNotNull(decompose.pushedPredicate);
            assertNull(decompose.residualPredicate);
            List<KuduPredicate> predicates = expressionToPredicates(decompose.pushedPredicate);
            assertEquals(2, predicates.size());
            scanWithPredicates(predicates);
            // Also test NOT AND.
            List<ExprNodeDesc> notChildren = Lists.newArrayList();
            notChildren.add(andPredicateExpr);
            ExprNodeGenericFuncDesc notPredicateExpr = new ExprNodeGenericFuncDesc(typeInfo, new GenericUDFOPNot(), notChildren);
            // Verify KuduPredicateHandler.decompose
            HiveStoragePredicateHandler.DecomposedPredicate decomposeNot = KuduPredicateHandler.decompose(notPredicateExpr, SCHEMA);
            // See note in KuduPredicateHandler.newAnalyzer.
            assertNull(decomposeNot);
            List<KuduPredicate> notPredicates = expressionToPredicates(notPredicateExpr);
            assertEquals(0, notPredicates.size());
        }
    }
}
Also used : HiveStoragePredicateHandler(org.apache.hadoop.hive.ql.metadata.HiveStoragePredicateHandler) ExprNodeConstantDesc(org.apache.hadoop.hive.ql.plan.ExprNodeConstantDesc) GenericUDFOPEqualOrLessThan(org.apache.hadoop.hive.ql.udf.generic.GenericUDFOPEqualOrLessThan) ExprNodeGenericFuncDesc(org.apache.hadoop.hive.ql.plan.ExprNodeGenericFuncDesc) ColumnSchema(org.apache.kudu.ColumnSchema) PrimitiveTypeInfo(org.apache.hadoop.hive.serde2.typeinfo.PrimitiveTypeInfo) GenericUDFOPEqualOrGreaterThan(org.apache.hadoop.hive.ql.udf.generic.GenericUDFOPEqualOrGreaterThan) KuduPredicate(org.apache.kudu.client.KuduPredicate) ExprNodeColumnDesc(org.apache.hadoop.hive.ql.plan.ExprNodeColumnDesc) ExprNodeDesc(org.apache.hadoop.hive.ql.plan.ExprNodeDesc) GenericUDFOPNot(org.apache.hadoop.hive.ql.udf.generic.GenericUDFOPNot) GenericUDFOPAnd(org.apache.hadoop.hive.ql.udf.generic.GenericUDFOPAnd) Test(org.junit.Test)

Example 3 with KuduPredicate

use of org.apache.kudu.client.KuduPredicate in project hive by apache.

the class TestKuduPredicateHandler method testMixedPredicates.

@Test
public void testMixedPredicates() throws Exception {
    for (ColumnSchema col : SCHEMA.getColumns()) {
        // Skip binary columns because binary predicates are not supported. (HIVE-11370)
        if (col.getName().equals("null") || col.getName().equals("default") || col.getName().equals("binary")) {
            continue;
        }
        PrimitiveTypeInfo typeInfo = toHiveType(col.getType(), col.getTypeAttributes());
        ExprNodeDesc colExpr = new ExprNodeColumnDesc(typeInfo, col.getName(), null, false);
        ExprNodeDesc constExpr = new ExprNodeConstantDesc(typeInfo, ROW.getObject(col.getName()));
        List<ExprNodeDesc> children = Lists.newArrayList();
        children.add(colExpr);
        children.add(constExpr);
        ExprNodeGenericFuncDesc supportedPredicateExpr = new ExprNodeGenericFuncDesc(typeInfo, new GenericUDFOPEqualOrGreaterThan(), children);
        ExprNodeGenericFuncDesc unsupportedPredicateExpr = new ExprNodeGenericFuncDesc(typeInfo, new GenericUDFOPUnsupported(), children);
        List<ExprNodeDesc> andChildren = Lists.newArrayList();
        andChildren.add(supportedPredicateExpr);
        andChildren.add(unsupportedPredicateExpr);
        ExprNodeGenericFuncDesc andPredicateExpr = new ExprNodeGenericFuncDesc(typeInfo, new GenericUDFOPAnd(), andChildren);
        // Verify KuduPredicateHandler.decompose
        HiveStoragePredicateHandler.DecomposedPredicate decompose = KuduPredicateHandler.decompose(andPredicateExpr, SCHEMA);
        assertNotNull(decompose);
        assertNotNull(decompose.pushedPredicate);
        assertNotNull(decompose.residualPredicate);
        List<KuduPredicate> predicates = expressionToPredicates(decompose.pushedPredicate);
        assertEquals(1, predicates.size());
        scanWithPredicates(predicates);
    }
}
Also used : HiveStoragePredicateHandler(org.apache.hadoop.hive.ql.metadata.HiveStoragePredicateHandler) ExprNodeConstantDesc(org.apache.hadoop.hive.ql.plan.ExprNodeConstantDesc) ExprNodeGenericFuncDesc(org.apache.hadoop.hive.ql.plan.ExprNodeGenericFuncDesc) ColumnSchema(org.apache.kudu.ColumnSchema) PrimitiveTypeInfo(org.apache.hadoop.hive.serde2.typeinfo.PrimitiveTypeInfo) GenericUDFOPEqualOrGreaterThan(org.apache.hadoop.hive.ql.udf.generic.GenericUDFOPEqualOrGreaterThan) KuduPredicate(org.apache.kudu.client.KuduPredicate) ExprNodeColumnDesc(org.apache.hadoop.hive.ql.plan.ExprNodeColumnDesc) ExprNodeDesc(org.apache.hadoop.hive.ql.plan.ExprNodeDesc) GenericUDFOPAnd(org.apache.hadoop.hive.ql.udf.generic.GenericUDFOPAnd) Test(org.junit.Test)

Example 4 with KuduPredicate

use of org.apache.kudu.client.KuduPredicate in project hive by apache.

the class TestKuduPredicateHandler method testNotComparisonPredicates.

@Test
public void testNotComparisonPredicates() throws Exception {
    for (ColumnSchema col : SCHEMA.getColumns()) {
        // Skip binary columns because binary predicates are not supported. (HIVE-11370)
        if (col.getName().equals("null") || col.getName().equals("default") || col.getName().equals("binary")) {
            continue;
        }
        PrimitiveTypeInfo typeInfo = toHiveType(col.getType(), col.getTypeAttributes());
        ExprNodeDesc colExpr = new ExprNodeColumnDesc(typeInfo, col.getName(), null, false);
        ExprNodeDesc constExpr = new ExprNodeConstantDesc(typeInfo, ROW.getObject(col.getName()));
        List<ExprNodeDesc> children = Lists.newArrayList();
        children.add(colExpr);
        children.add(constExpr);
        for (GenericUDF udf : COMPARISON_UDFS) {
            ExprNodeGenericFuncDesc childExpr = new ExprNodeGenericFuncDesc(typeInfo, udf, children);
            List<ExprNodeDesc> notChildren = Lists.newArrayList();
            notChildren.add(childExpr);
            ExprNodeGenericFuncDesc predicateExpr = new ExprNodeGenericFuncDesc(typeInfo, new GenericUDFOPNot(), notChildren);
            // Verify KuduPredicateHandler.decompose
            HiveStoragePredicateHandler.DecomposedPredicate decompose = KuduPredicateHandler.decompose(predicateExpr, SCHEMA);
            // See note in KuduPredicateHandler.newAnalyzer.
            assertNull(decompose);
            List<KuduPredicate> predicates = expressionToPredicates(predicateExpr);
            if (udf instanceof GenericUDFOPEqual) {
                // Kudu doesn't support !=.
                assertTrue(predicates.isEmpty());
            } else {
                assertEquals(1, predicates.size());
                scanWithPredicates(predicates);
            }
        }
    }
}
Also used : HiveStoragePredicateHandler(org.apache.hadoop.hive.ql.metadata.HiveStoragePredicateHandler) ExprNodeConstantDesc(org.apache.hadoop.hive.ql.plan.ExprNodeConstantDesc) ExprNodeGenericFuncDesc(org.apache.hadoop.hive.ql.plan.ExprNodeGenericFuncDesc) ColumnSchema(org.apache.kudu.ColumnSchema) PrimitiveTypeInfo(org.apache.hadoop.hive.serde2.typeinfo.PrimitiveTypeInfo) KuduPredicate(org.apache.kudu.client.KuduPredicate) GenericUDF(org.apache.hadoop.hive.ql.udf.generic.GenericUDF) ExprNodeColumnDesc(org.apache.hadoop.hive.ql.plan.ExprNodeColumnDesc) GenericUDFOPEqual(org.apache.hadoop.hive.ql.udf.generic.GenericUDFOPEqual) ExprNodeDesc(org.apache.hadoop.hive.ql.plan.ExprNodeDesc) GenericUDFOPNot(org.apache.hadoop.hive.ql.udf.generic.GenericUDFOPNot) Test(org.junit.Test)

Example 5 with KuduPredicate

use of org.apache.kudu.client.KuduPredicate in project gora by apache.

the class KuduStore method deleteByQuery.

@Override
public long deleteByQuery(Query<K, T> query) throws GoraException {
    try {
        long count = 0;
        Column pkc = kuduMapping.getPrimaryKey().get(0);
        ColumnSchema column = table.getSchema().getColumn(pkc.getName());
        List<String> dbFields = new ArrayList<>();
        dbFields.add(pkc.getName());
        List<KuduPredicate> rangePredicates = KuduClientUtils.createRangePredicate(column, query.getStartKey(), query.getEndKey());
        rangePredicates.add(KuduPredicate.newIsNotNullPredicate(column));
        KuduScanner build = createScanner(rangePredicates, dbFields, query.getLimit());
        while (build.hasMoreRows()) {
            RowResultIterator nextRows = build.nextRows();
            for (RowResult it : nextRows) {
                count++;
                K key = (K) KuduClientUtils.getObjectRow(it, pkc);
                if (query.getFields() != null && query.getFields().length < kuduMapping.getFields().size()) {
                    Update updateOp = table.newUpdate();
                    PartialRow row = updateOp.getRow();
                    String[] avFields = getFieldsToQuery(query.getFields());
                    KuduClientUtils.addObjectRow(row, pkc, key);
                    for (String af : avFields) {
                        row.setNull(kuduMapping.getFields().get(af).getName());
                    }
                    session.apply(updateOp);
                } else {
                    delete(key);
                }
            }
        }
        build.close();
        return count;
    } catch (Exception e) {
        throw new GoraException(e);
    }
}
Also used : ArrayList(java.util.ArrayList) PartialRow(org.apache.kudu.client.PartialRow) ColumnSchema(org.apache.kudu.ColumnSchema) Update(org.apache.kudu.client.Update) KuduPredicate(org.apache.kudu.client.KuduPredicate) KuduException(org.apache.kudu.client.KuduException) GoraException(org.apache.gora.util.GoraException) IOException(java.io.IOException) RowResultIterator(org.apache.kudu.client.RowResultIterator) RowResult(org.apache.kudu.client.RowResult) GoraException(org.apache.gora.util.GoraException) Column(org.apache.gora.kudu.mapping.Column) KuduScanner(org.apache.kudu.client.KuduScanner)

Aggregations

KuduPredicate (org.apache.kudu.client.KuduPredicate)16 ColumnSchema (org.apache.kudu.ColumnSchema)10 HiveStoragePredicateHandler (org.apache.hadoop.hive.ql.metadata.HiveStoragePredicateHandler)7 ExprNodeColumnDesc (org.apache.hadoop.hive.ql.plan.ExprNodeColumnDesc)7 ExprNodeDesc (org.apache.hadoop.hive.ql.plan.ExprNodeDesc)7 ExprNodeGenericFuncDesc (org.apache.hadoop.hive.ql.plan.ExprNodeGenericFuncDesc)7 PrimitiveTypeInfo (org.apache.hadoop.hive.serde2.typeinfo.PrimitiveTypeInfo)7 Test (org.junit.Test)7 ArrayList (java.util.ArrayList)6 ExprNodeConstantDesc (org.apache.hadoop.hive.ql.plan.ExprNodeConstantDesc)6 KuduScanner (org.apache.kudu.client.KuduScanner)6 IOException (java.io.IOException)5 GoraException (org.apache.gora.util.GoraException)4 GenericUDFOPNot (org.apache.hadoop.hive.ql.udf.generic.GenericUDFOPNot)4 KuduException (org.apache.kudu.client.KuduException)4 GenericUDF (org.apache.hadoop.hive.ql.udf.generic.GenericUDF)3 GenericUDFOPEqualOrGreaterThan (org.apache.hadoop.hive.ql.udf.generic.GenericUDFOPEqualOrGreaterThan)3 RowResult (org.apache.kudu.client.RowResult)3 GenericUDFOPAnd (org.apache.hadoop.hive.ql.udf.generic.GenericUDFOPAnd)2 GenericUDFOPEqualOrLessThan (org.apache.hadoop.hive.ql.udf.generic.GenericUDFOPEqualOrLessThan)2