public int compareTo(BoundaryDef other) { int c = getDirection().compareTo(other.getDirection()); if (c != 0) { return c; } ValueBoundaryDef vb = (ValueBoundaryDef) other; return getAmt() - vb.getAmt(); }
protected void initialize(BoundaryDef def, ShapeDetails inpShape) throws HiveException { if (def instanceof ValueBoundaryDef) { ValueBoundaryDef vDef = (ValueBoundaryDef) def; initialize(vDef.getExpressionDef(), inpShape); } }
private BoundaryDef translate(ShapeDetails inpShape, BoundarySpec bndSpec) throws SemanticException { if (bndSpec instanceof ValueBoundarySpec) { ValueBoundarySpec vBndSpec = (ValueBoundarySpec) bndSpec; ValueBoundaryDef vbDef = new ValueBoundaryDef(); vbDef.setAmt(vBndSpec.getAmt()); vbDef.setDirection(vBndSpec.getDirection()); PTFTranslator.validateNoLeadLagInValueBoundarySpec(vBndSpec.getExpression()); PTFExpressionDef exprDef = null; try { exprDef = buildExpressionDef(inpShape, vBndSpec.getExpression()); } catch (HiveException he) { throw new SemanticException(he); } PTFTranslator.validateValueBoundaryExprType(exprDef.getOI()); vbDef.setExpressionDef(exprDef); return vbDef; } else if (bndSpec instanceof RangeBoundarySpec) { RangeBoundarySpec rBndSpec = (RangeBoundarySpec) bndSpec; RangeBoundaryDef rbDef = new RangeBoundaryDef(); rbDef.setAmt(rBndSpec.getAmt()); rbDef.setDirection(rBndSpec.getDirection()); return rbDef; } else if (bndSpec instanceof CurrentRowSpec) { CurrentRowDef cbDef = new CurrentRowDef(); return cbDef; } throw new SemanticException("Unknown Boundary: " + bndSpec); }
@SuppressWarnings("incomplete-switch") public static ValueBoundaryScanner getScanner(ValueBoundaryDef vbDef, Order order) throws HiveException { PrimitiveObjectInspector pOI = (PrimitiveObjectInspector) vbDef.getOI(); switch(pOI.getPrimitiveCategory()) { case BYTE: case INT: case LONG: case SHORT: case TIMESTAMP: return new LongValueBoundaryScanner(vbDef, order, vbDef.getExpressionDef()); case DOUBLE: case FLOAT: return new DoubleValueBoundaryScanner(vbDef, order, vbDef.getExpressionDef()); case DECIMAL: return new HiveDecimalValueBoundaryScanner(vbDef, order, vbDef.getExpressionDef()); case STRING: return new StringValueBoundaryScanner(vbDef, order, vbDef.getExpressionDef()); } throw new HiveException( String.format("Internal Error: attempt to setup a Window for datatype %s", pOI.getPrimitiveCategory())); } }