/* * 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; }
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; }