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;
}
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));
}
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));
}
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));
}
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));
}
Aggregations