Search in sources :

Example 1 with ExprNodeConstantEvaluator

use of org.apache.hadoop.hive.ql.exec.ExprNodeConstantEvaluator in project hive by apache.

the class HiveHBaseTableInputFormat method getTimestampVal.

private long getTimestampVal(IndexSearchCondition sc) throws IOException {
    long timestamp;
    try {
        ExprNodeConstantEvaluator eval = new ExprNodeConstantEvaluator(sc.getConstantDesc());
        ObjectInspector inspector = eval.initialize(null);
        Object value = eval.evaluate(null);
        if (inspector instanceof LongObjectInspector) {
            timestamp = ((LongObjectInspector) inspector).get(value);
        } else {
            PrimitiveObjectInspector primitive = (PrimitiveObjectInspector) inspector;
            timestamp = PrimitiveObjectInspectorUtils.getTimestamp(value, primitive).getTime();
        }
    } catch (HiveException e) {
        throw new IOException(e);
    }
    return timestamp;
}
Also used : ObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector) PrimitiveObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector) LongObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.LongObjectInspector) LongObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.LongObjectInspector) HiveException(org.apache.hadoop.hive.ql.metadata.HiveException) ExprNodeConstantEvaluator(org.apache.hadoop.hive.ql.exec.ExprNodeConstantEvaluator) PrimitiveObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector) IOException(java.io.IOException)

Example 2 with ExprNodeConstantEvaluator

use of org.apache.hadoop.hive.ql.exec.ExprNodeConstantEvaluator in project hive by apache.

the class HiveHBaseInputFormatUtil method setupKeyRange.

static void setupKeyRange(Scan scan, List<IndexSearchCondition> conditions, boolean isBinary) throws IOException {
    // Convert the search condition into a restriction on the HBase scan
    byte[] startRow = HConstants.EMPTY_START_ROW, stopRow = HConstants.EMPTY_END_ROW;
    for (IndexSearchCondition sc : conditions) {
        ExprNodeConstantEvaluator eval = new ExprNodeConstantEvaluator(sc.getConstantDesc());
        PrimitiveObjectInspector objInspector;
        Object writable;
        try {
            objInspector = (PrimitiveObjectInspector) eval.initialize(null);
            writable = eval.evaluate(null);
        } catch (ClassCastException cce) {
            throw new IOException("Currently only primitve types are supported. Found: " + sc.getConstantDesc().getTypeString());
        } catch (HiveException e) {
            throw new IOException(e);
        }
        byte[] constantVal = getConstantVal(writable, objInspector, isBinary);
        String comparisonOp = sc.getComparisonOp();
        if ("org.apache.hadoop.hive.ql.udf.generic.GenericUDFOPEqual".equals(comparisonOp)) {
            startRow = constantVal;
            stopRow = getNextBA(constantVal);
        } else if ("org.apache.hadoop.hive.ql.udf.generic.GenericUDFOPLessThan".equals(comparisonOp)) {
            stopRow = constantVal;
        } else if ("org.apache.hadoop.hive.ql.udf.generic.GenericUDFOPEqualOrGreaterThan".equals(comparisonOp)) {
            startRow = constantVal;
        } else if ("org.apache.hadoop.hive.ql.udf.generic.GenericUDFOPGreaterThan".equals(comparisonOp)) {
            startRow = getNextBA(constantVal);
        } else if ("org.apache.hadoop.hive.ql.udf.generic.GenericUDFOPEqualOrLessThan".equals(comparisonOp)) {
            stopRow = getNextBA(constantVal);
        } else {
            throw new IOException(comparisonOp + " is not a supported comparison operator");
        }
    }
    scan.setStartRow(startRow);
    scan.setStopRow(stopRow);
    if (LOG.isDebugEnabled()) {
        LOG.debug(Bytes.toStringBinary(startRow) + " ~ " + Bytes.toStringBinary(stopRow));
    }
}
Also used : HiveException(org.apache.hadoop.hive.ql.metadata.HiveException) IndexSearchCondition(org.apache.hadoop.hive.ql.index.IndexSearchCondition) ExprNodeConstantEvaluator(org.apache.hadoop.hive.ql.exec.ExprNodeConstantEvaluator) PrimitiveObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector) IOException(java.io.IOException)

Example 3 with ExprNodeConstantEvaluator

use of org.apache.hadoop.hive.ql.exec.ExprNodeConstantEvaluator in project hive by apache.

the class HiveHBaseTableInputFormat method setupKeyRange.

private void setupKeyRange(Scan scan, List<IndexSearchCondition> conditions, boolean isBinary) throws IOException {
    // Convert the search condition into a restriction on the HBase scan
    byte[] startRow = HConstants.EMPTY_START_ROW, stopRow = HConstants.EMPTY_END_ROW;
    for (IndexSearchCondition sc : conditions) {
        ExprNodeConstantEvaluator eval = new ExprNodeConstantEvaluator(sc.getConstantDesc());
        PrimitiveObjectInspector objInspector;
        Object writable;
        try {
            objInspector = (PrimitiveObjectInspector) eval.initialize(null);
            writable = eval.evaluate(null);
        } catch (ClassCastException cce) {
            throw new IOException("Currently only primitve types are supported. Found: " + sc.getConstantDesc().getTypeString());
        } catch (HiveException e) {
            throw new IOException(e);
        }
        byte[] constantVal = getConstantVal(writable, objInspector, isBinary);
        String comparisonOp = sc.getComparisonOp();
        if ("org.apache.hadoop.hive.ql.udf.generic.GenericUDFOPEqual".equals(comparisonOp)) {
            startRow = constantVal;
            stopRow = getNextBA(constantVal);
        } else if ("org.apache.hadoop.hive.ql.udf.generic.GenericUDFOPLessThan".equals(comparisonOp)) {
            stopRow = constantVal;
        } else if ("org.apache.hadoop.hive.ql.udf.generic.GenericUDFOPEqualOrGreaterThan".equals(comparisonOp)) {
            startRow = constantVal;
        } else if ("org.apache.hadoop.hive.ql.udf.generic.GenericUDFOPGreaterThan".equals(comparisonOp)) {
            startRow = getNextBA(constantVal);
        } else if ("org.apache.hadoop.hive.ql.udf.generic.GenericUDFOPEqualOrLessThan".equals(comparisonOp)) {
            stopRow = getNextBA(constantVal);
        } else {
            throw new IOException(comparisonOp + " is not a supported comparison operator");
        }
    }
    scan.setStartRow(startRow);
    scan.setStopRow(stopRow);
    if (LOG.isDebugEnabled()) {
        LOG.debug(Bytes.toStringBinary(startRow) + " ~ " + Bytes.toStringBinary(stopRow));
    }
}
Also used : HiveException(org.apache.hadoop.hive.ql.metadata.HiveException) IndexSearchCondition(org.apache.hadoop.hive.ql.index.IndexSearchCondition) ExprNodeConstantEvaluator(org.apache.hadoop.hive.ql.exec.ExprNodeConstantEvaluator) PrimitiveObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector) IOException(java.io.IOException)

Example 4 with ExprNodeConstantEvaluator

use of org.apache.hadoop.hive.ql.exec.ExprNodeConstantEvaluator in project hive by apache.

the class HiveHBaseInputFormatUtil method getTimestampVal.

static long getTimestampVal(IndexSearchCondition sc) throws IOException {
    long timestamp;
    try {
        ExprNodeConstantEvaluator eval = new ExprNodeConstantEvaluator(sc.getConstantDesc());
        ObjectInspector inspector = eval.initialize(null);
        Object value = eval.evaluate(null);
        if (inspector instanceof LongObjectInspector) {
            timestamp = ((LongObjectInspector) inspector).get(value);
        } else {
            PrimitiveObjectInspector primitive = (PrimitiveObjectInspector) inspector;
            timestamp = PrimitiveObjectInspectorUtils.getTimestamp(value, primitive).toEpochMilli();
        }
    } catch (HiveException e) {
        throw new IOException(e);
    }
    return timestamp;
}
Also used : PrimitiveObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector) ObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector) LongObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.LongObjectInspector) LongObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.LongObjectInspector) HiveException(org.apache.hadoop.hive.ql.metadata.HiveException) ExprNodeConstantEvaluator(org.apache.hadoop.hive.ql.exec.ExprNodeConstantEvaluator) PrimitiveObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector) IOException(java.io.IOException)

Aggregations

IOException (java.io.IOException)4 ExprNodeConstantEvaluator (org.apache.hadoop.hive.ql.exec.ExprNodeConstantEvaluator)4 HiveException (org.apache.hadoop.hive.ql.metadata.HiveException)4 PrimitiveObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector)4 IndexSearchCondition (org.apache.hadoop.hive.ql.index.IndexSearchCondition)2 ObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector)2 LongObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.primitive.LongObjectInspector)2