public static SymbolFunctionResult match( SymbolFunction syFn, Object row, PTFPartitionIterator<Object> pItr) throws HiveException { int resetToIdx = pItr.getIndex() - 1; try { return syFn.match(row, pItr); } finally { pItr.resetToIndex(resetToIdx); } }
public static ArrayList<Object> getPath( Object currRow, ObjectInspector rowOI, PTFPartitionIterator<Object> pItr, int sz) throws HiveException { int idx = pItr.getIndex() - 1; ArrayList<Object> path = new ArrayList<Object>(); path.add(ObjectInspectorUtils.copyToStandardObject(currRow, rowOI)); int pSz = 1; while (pSz < sz && pItr.hasNext()) { currRow = pItr.next(); path.add(ObjectInspectorUtils.copyToStandardObject(currRow, rowOI)); pSz++; } pItr.resetToIndex(idx); return path; }
/* * Iterate over the Symbol Functions in the Chain: * - If we are not at the end of the Iterator (i.e. row != null ) * - match the current componentFn * - if it returns false, then return false * - otherwise set row to the next row from the Iterator. * - if we are at the end of the Iterator * - skip any optional Symbol Fns (star patterns) at the end. * - but if we come to a non optional Symbol Fn, return false. * - if we match all Fns in the chain return true. */ @Override protected SymbolFunctionResult match(Object row, PTFPartitionIterator<Object> pItr) throws HiveException { SymbolFunctionResult componentResult = null; for (SymbolFunction sFn : components) { if (row != null) { componentResult = sFn.match(row, pItr); if (!componentResult.matches) { result.matches = false; result.nextRow = componentResult.nextRow; return result; } row = pItr.resetToIndex(componentResult.nextRow); } else { if (!sFn.isOptional()) { result.matches = false; result.nextRow = componentResult.nextRow; return result; } } } result.matches = true; result.nextRow = componentResult.nextRow; return result; }
@Override protected SymbolFunctionResult match(Object row, PTFPartitionIterator<Object> pItr) throws HiveException { result.matches = true; SymbolFunctionResult rowResult = symbolFn.match(row, pItr); while (rowResult.matches && pItr.hasNext()) { row = pItr.next(); rowResult = symbolFn.match(row, pItr); } result.nextRow = pItr.getIndex(); if (pItr.hasNext()) { result.nextRow -= 1; } return result; }
@Override public void execute(PTFPartitionIterator<Object> pItr, PTFPartition outP) throws HiveException { while (pItr.hasNext()) { Object iRow = pItr.next(); SymbolFunctionResult syFnRes = SymbolFunction.match(syFn, iRow, pItr); if (syFnRes.matches) { int sz = syFnRes.nextRow - (pItr.getIndex() - 1); Object selectListInput = MatchPath.getSelectListInput( iRow, tableDef.getInput().getOutputShape().getOI(), pItr, sz); ArrayList<Object> oRow = new ArrayList<Object>(); for (ExprNodeEvaluator resExprEval : resultExprInfo.resultExprEvals) { oRow.add(resExprEval.evaluate(selectListInput)); } outP.append(oRow); } } }
@Override protected SymbolFunctionResult match(Object row, PTFPartitionIterator<Object> pItr) throws HiveException { Object val = null; val = symbolExprEval.evaluate(row); val = converter.convert(val); result.matches = ((Boolean) val).booleanValue(); result.nextRow = pItr.getIndex(); return result; }