Search in sources :

Example 21 with PTFExpressionDef

use of org.apache.hadoop.hive.ql.plan.ptf.PTFExpressionDef in project hive by apache.

the class PTFTranslator method translate.

private OrderExpressionDef translate(ShapeDetails inpShape, OrderExpression oExpr) throws SemanticException {
    OrderExpressionDef oexpDef = new OrderExpressionDef();
    oexpDef.setOrder(oExpr.getOrder());
    oexpDef.setNullOrder(oExpr.getNullOrder());
    try {
        PTFExpressionDef expDef = buildExpressionDef(inpShape, oExpr.getExpression());
        oexpDef.setExpressionTreeString(expDef.getExpressionTreeString());
        oexpDef.setExprEvaluator(expDef.getExprEvaluator());
        oexpDef.setExprNode(expDef.getExprNode());
        oexpDef.setOI(expDef.getOI());
    } catch (HiveException he) {
        throw new SemanticException(he);
    }
    PTFTranslator.validateComparable(oexpDef.getOI(), String.format("Partition Expression %s is not a comparable expression", oExpr.getExpression().toStringTree()));
    return oexpDef;
}
Also used : HiveException(org.apache.hadoop.hive.ql.metadata.HiveException) PTFExpressionDef(org.apache.hadoop.hive.ql.plan.ptf.PTFExpressionDef) OrderExpressionDef(org.apache.hadoop.hive.ql.plan.ptf.OrderExpressionDef)

Example 22 with PTFExpressionDef

use of org.apache.hadoop.hive.ql.plan.ptf.PTFExpressionDef in project hive by apache.

the class TestValueBoundaryScanner method testLongEquals.

@Test
public void testLongEquals() {
    PTFExpressionDef argDef = new PTFExpressionDef();
    argDef.setOI(PrimitiveObjectInspectorFactory.writableLongObjectInspector);
    LongValueBoundaryScanner scanner = new LongValueBoundaryScanner(null, null, new OrderExpressionDef(argDef), false);
    LongWritable w1 = new LongWritable(1);
    LongWritable w2 = new LongWritable(2);
    Assert.assertTrue(scanner.isEqual(w1, w1));
    Assert.assertFalse(scanner.isEqual(w1, w2));
    Assert.assertFalse(scanner.isEqual(w2, w1));
    Assert.assertFalse(scanner.isEqual(null, w2));
    Assert.assertFalse(scanner.isEqual(w1, null));
    Assert.assertTrue(scanner.isEqual(null, null));
}
Also used : PTFExpressionDef(org.apache.hadoop.hive.ql.plan.ptf.PTFExpressionDef) LongWritable(org.apache.hadoop.io.LongWritable) OrderExpressionDef(org.apache.hadoop.hive.ql.plan.ptf.OrderExpressionDef) Test(org.junit.Test)

Example 23 with PTFExpressionDef

use of org.apache.hadoop.hive.ql.plan.ptf.PTFExpressionDef in project hive by apache.

the class TestValueBoundaryScanner method testTimestampIsDistanceGreater.

@Test
public void testTimestampIsDistanceGreater() {
    PTFExpressionDef argDef = new PTFExpressionDef();
    argDef.setOI(PrimitiveObjectInspectorFactory.writableTimestampObjectInspector);
    TimestampValueBoundaryScanner scanner = new TimestampValueBoundaryScanner(null, null, new OrderExpressionDef(argDef), false);
    Timestamp ts = new Timestamp();
    // 1000s
    ts.setTimeInMillis(1000000);
    // 1000s
    TimestampWritableV2 w1 = new TimestampWritableV2(ts);
    // 1000s
    TimestampWritableV2 w2 = new TimestampWritableV2(ts);
    // empty == epoch == 0s
    TimestampWritableV2 w3 = new TimestampWritableV2();
    // equal timestamps, distance is not greater than 0
    Assert.assertFalse(scanner.isDistanceGreater(w1, w2, 0));
    Assert.assertFalse(scanner.isDistanceGreater(w2, w1, 0));
    // null comparison, true only if one value is null
    Assert.assertTrue(scanner.isDistanceGreater(w1, null, 100));
    Assert.assertTrue(scanner.isDistanceGreater(w2, null, 100));
    Assert.assertFalse(scanner.isDistanceGreater(null, null, 100));
    // 1000s distance
    // 1000 > 999
    Assert.assertTrue(scanner.isDistanceGreater(w1, w3, 999));
    Assert.assertFalse(scanner.isDistanceGreater(w1, w3, 1000));
    Assert.assertFalse(scanner.isDistanceGreater(w1, w3, 1001));
}
Also used : PTFExpressionDef(org.apache.hadoop.hive.ql.plan.ptf.PTFExpressionDef) Timestamp(org.apache.hadoop.hive.common.type.Timestamp) TimestampWritableV2(org.apache.hadoop.hive.serde2.io.TimestampWritableV2) OrderExpressionDef(org.apache.hadoop.hive.ql.plan.ptf.OrderExpressionDef) Test(org.junit.Test)

Example 24 with PTFExpressionDef

use of org.apache.hadoop.hive.ql.plan.ptf.PTFExpressionDef in project hive by apache.

the class TestValueBoundaryScanner method testHiveDecimalEquals.

@Test
public void testHiveDecimalEquals() {
    PTFExpressionDef argDef = new PTFExpressionDef();
    argDef.setOI(PrimitiveObjectInspectorFactory.writableHiveDecimalObjectInspector);
    HiveDecimalValueBoundaryScanner scanner = new HiveDecimalValueBoundaryScanner(null, null, new OrderExpressionDef(argDef), false);
    HiveDecimalWritable w1 = new HiveDecimalWritable(1);
    HiveDecimalWritable w2 = new HiveDecimalWritable(2);
    Assert.assertTrue(scanner.isEqual(w1, w1));
    Assert.assertFalse(scanner.isEqual(w1, w2));
    Assert.assertFalse(scanner.isEqual(w2, w1));
    Assert.assertFalse(scanner.isEqual(null, w2));
    Assert.assertFalse(scanner.isEqual(w1, null));
    Assert.assertTrue(scanner.isEqual(null, null));
}
Also used : HiveDecimalWritable(org.apache.hadoop.hive.serde2.io.HiveDecimalWritable) PTFExpressionDef(org.apache.hadoop.hive.ql.plan.ptf.PTFExpressionDef) OrderExpressionDef(org.apache.hadoop.hive.ql.plan.ptf.OrderExpressionDef) Test(org.junit.Test)

Example 25 with PTFExpressionDef

use of org.apache.hadoop.hive.ql.plan.ptf.PTFExpressionDef in project hive by apache.

the class TestValueBoundaryScanner method testTimestampLocalTZEquals.

@Test
public void testTimestampLocalTZEquals() {
    PTFExpressionDef argDef = new PTFExpressionDef();
    argDef.setOI(PrimitiveObjectInspectorFactory.writableTimestampTZObjectInspector);
    TimestampLocalTZValueBoundaryScanner scanner = new TimestampLocalTZValueBoundaryScanner(null, null, new OrderExpressionDef(argDef), false);
    TimestampTZ ts = new TimestampTZ();
    ts.set(10, 0, ZoneId.systemDefault());
    TimestampLocalTZWritable w1 = new TimestampLocalTZWritable(ts);
    TimestampLocalTZWritable w2 = new TimestampLocalTZWritable(ts);
    // empty
    TimestampLocalTZWritable w3 = new TimestampLocalTZWritable();
    w3.setTimeZone(ZoneId.of("UTC"));
    Assert.assertTrue(scanner.isEqual(w1, w2));
    Assert.assertTrue(scanner.isEqual(w2, w1));
    // empty == epoch
    TimestampTZ epoch = new TimestampTZ();
    epoch.set(0, 0, ZoneId.of("UTC"));
    Assert.assertTrue(scanner.isEqual(w3, new TimestampLocalTZWritable(epoch)));
    // empty != another non-epoch
    Assert.assertFalse(scanner.isEqual(w1, w3));
    Assert.assertFalse(scanner.isEqual(null, w2));
    Assert.assertFalse(scanner.isEqual(w1, null));
    Assert.assertTrue(scanner.isEqual(null, null));
}
Also used : TimestampTZ(org.apache.hadoop.hive.common.type.TimestampTZ) TimestampLocalTZWritable(org.apache.hadoop.hive.serde2.io.TimestampLocalTZWritable) PTFExpressionDef(org.apache.hadoop.hive.ql.plan.ptf.PTFExpressionDef) OrderExpressionDef(org.apache.hadoop.hive.ql.plan.ptf.OrderExpressionDef) Test(org.junit.Test)

Aggregations

PTFExpressionDef (org.apache.hadoop.hive.ql.plan.ptf.PTFExpressionDef)26 OrderExpressionDef (org.apache.hadoop.hive.ql.plan.ptf.OrderExpressionDef)12 ArrayList (java.util.ArrayList)7 Test (org.junit.Test)7 ExprNodeDesc (org.apache.hadoop.hive.ql.plan.ExprNodeDesc)6 WindowFunctionDef (org.apache.hadoop.hive.ql.plan.ptf.WindowFunctionDef)6 StructObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.StructObjectInspector)6 HiveException (org.apache.hadoop.hive.ql.metadata.HiveException)5 ObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector)5 ShapeDetails (org.apache.hadoop.hive.ql.plan.ptf.ShapeDetails)4 ListObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.ListObjectInspector)4 WindowFrameDef (org.apache.hadoop.hive.ql.plan.ptf.WindowFrameDef)3 GenericUDAFEvaluator (org.apache.hadoop.hive.ql.udf.generic.GenericUDAFEvaluator)3 TableFunctionEvaluator (org.apache.hadoop.hive.ql.udf.ptf.TableFunctionEvaluator)3 WindowingTableFunctionResolver (org.apache.hadoop.hive.ql.udf.ptf.WindowingTableFunction.WindowingTableFunctionResolver)3 Timestamp (org.apache.hadoop.hive.common.type.Timestamp)2 SQLCheckConstraint (org.apache.hadoop.hive.metastore.api.SQLCheckConstraint)2 SQLDefaultConstraint (org.apache.hadoop.hive.metastore.api.SQLDefaultConstraint)2 SQLNotNullConstraint (org.apache.hadoop.hive.metastore.api.SQLNotNullConstraint)2 SQLUniqueConstraint (org.apache.hadoop.hive.metastore.api.SQLUniqueConstraint)2