diff --git a/ql/src/java/org/apache/hadoop/hive/ql/exec/FunctionRegistry.java b/ql/src/java/org/apache/hadoop/hive/ql/exec/FunctionRegistry.java index 47e68fdf4352..96ea7c9f0051 100644 --- a/ql/src/java/org/apache/hadoop/hive/ql/exec/FunctionRegistry.java +++ b/ql/src/java/org/apache/hadoop/hive/ql/exec/FunctionRegistry.java @@ -129,7 +129,7 @@ import org.apache.hadoop.hive.ql.udf.generic.*; import org.apache.hadoop.hive.ql.udf.generic.GenericUDFLeadLag.GenericUDFLag; import org.apache.hadoop.hive.ql.udf.generic.GenericUDFLeadLag.GenericUDFLead; -import org.apache.hadoop.hive.ql.udf.ptf.NPath.NPathResolver; +import org.apache.hadoop.hive.ql.udf.ptf.MatchPath.MatchPathResolver; import org.apache.hadoop.hive.ql.udf.ptf.Noop.NoopResolver; import org.apache.hadoop.hive.ql.udf.ptf.NoopWithMap.NoopWithMapResolver; import org.apache.hadoop.hive.ql.udf.ptf.TableFunctionResolver; @@ -452,7 +452,7 @@ public final class FunctionRegistry { registerTableFunction(NOOP_TABLE_FUNCTION, NoopResolver.class); registerTableFunction(NOOP_MAP_TABLE_FUNCTION, NoopWithMapResolver.class); registerTableFunction(WINDOWING_TABLE_FUNCTION, WindowingTableFunctionResolver.class); - registerTableFunction("npath", NPathResolver.class); + registerTableFunction("matchpath", MatchPathResolver.class); } public static void registerTemporaryUDF(String functionName, diff --git a/ql/src/java/org/apache/hadoop/hive/ql/udf/ptf/NPath.java b/ql/src/java/org/apache/hadoop/hive/ql/udf/ptf/MatchPath.java similarity index 95% rename from ql/src/java/org/apache/hadoop/hive/ql/udf/ptf/NPath.java rename to ql/src/java/org/apache/hadoop/hive/ql/udf/ptf/MatchPath.java index a052244455e5..31fa5e39cbe5 100644 --- a/ql/src/java/org/apache/hadoop/hive/ql/udf/ptf/NPath.java +++ b/ql/src/java/org/apache/hadoop/hive/ql/udf/ptf/MatchPath.java @@ -77,7 +77,7 @@ * "tpath" is available. Path is a collection of rows that represents the matching Path. * */ -public class NPath extends TableFunctionEvaluator +public class MatchPath extends TableFunctionEvaluator { private transient String patternStr; private transient SymbolsInfo symInfo; @@ -85,7 +85,7 @@ public class NPath extends TableFunctionEvaluator private transient SymbolFunction syFn; private ResultExprInfo resultExprInfo; /* - * the names of the Columns of the input to NPath. Used to setup the tpath Struct column. + * the names of the Columns of the input to MatchPath. Used to setup the tpath Struct column. */ private HashMap inputColumnNamesMap; @@ -100,7 +100,7 @@ public void execute(PTFPartitionIterator pItr, PTFPartition outP) throws if (syFnRes.matches ) { int sz = syFnRes.nextRow - (pItr.getIndex() - 1); - Object selectListInput = NPath.getSelectListInput(iRow, + Object selectListInput = MatchPath.getSelectListInput(iRow, tDef.getInput().getOutputShape().getOI(), pItr, sz); ArrayList oRow = new ArrayList(); for(ExprNodeEvaluator resExprEval : resultExprInfo.resultExprEvals) @@ -115,7 +115,7 @@ public void execute(PTFPartitionIterator pItr, PTFPartition outP) throws static void throwErrorWithSignature(String message) throws SemanticException { throw new SemanticException(String.format( - "NPath signature is: SymbolPattern, one or more SymbolName, " + + "MatchPath signature is: SymbolPattern, one or more SymbolName, " + "expression pairs, the result expression as a select list. Error %s", message)); } @@ -128,7 +128,7 @@ public void setInputColumnNames(HashMap inputColumnNamesMap) { this.inputColumnNamesMap = inputColumnNamesMap; } - public static class NPathResolver extends TableFunctionResolver + public static class MatchPathResolver extends TableFunctionResolver { @Override @@ -136,7 +136,7 @@ protected TableFunctionEvaluator createEvaluator(PTFDesc ptfDesc, PartitionedTableFunctionDef tDef) { - return new NPath(); + return new MatchPath(); } /** @@ -158,7 +158,7 @@ protected TableFunctionEvaluator createEvaluator(PTFDesc ptfDesc, @Override public void setupOutputOI() throws SemanticException { - NPath evaluator = (NPath) getEvaluator(); + MatchPath evaluator = (MatchPath) getEvaluator(); PartitionedTableFunctionDef tDef = evaluator.getTableDef(); ArrayList args = tDef.getArgs(); @@ -177,7 +177,7 @@ public void setupOutputOI() throws SemanticException /* * setup OI for input to resultExpr select list */ - RowResolver selectListInputRR = NPath.createSelectListRR(evaluator, tDef.getInput()); + RowResolver selectListInputRR = MatchPath.createSelectListRR(evaluator, tDef.getInput()); /* * parse ResultExpr Str and setup OI. @@ -198,7 +198,7 @@ public void setupOutputOI() throws SemanticException /* * validate and setup patternStr */ - private void validateAndSetupPatternStr(NPath evaluator, + private void validateAndSetupPatternStr(MatchPath evaluator, ArrayList args) throws SemanticException { PTFExpressionDef symboPatternArg = args.get(0); ObjectInspector symbolPatternArgOI = symboPatternArg.getOI(); @@ -218,7 +218,7 @@ private void validateAndSetupPatternStr(NPath evaluator, /* * validate and setup SymbolInfo */ - private void validateAndSetupSymbolInfo(NPath evaluator, + private void validateAndSetupSymbolInfo(MatchPath evaluator, ArrayList args, int argsNum) throws SemanticException { int symbolArgsSz = argsNum - 2; @@ -262,7 +262,7 @@ private void validateAndSetupSymbolInfo(NPath evaluator, /* * validate and setup resultExprStr */ - private void validateAndSetupResultExprStr(NPath evaluator, + private void validateAndSetupResultExprStr(MatchPath evaluator, ArrayList args, int argsNum) throws SemanticException { PTFExpressionDef resultExprArg = args.get(argsNum - 1); @@ -283,7 +283,7 @@ private void validateAndSetupResultExprStr(NPath evaluator, /* * setup SymbolFunction chain. */ - private void setupSymbolFunctionChain(NPath evaluator) throws SemanticException { + private void setupSymbolFunctionChain(MatchPath evaluator) throws SemanticException { SymbolParser syP = new SymbolParser(evaluator.patternStr, evaluator.symInfo.symbolExprsNames, evaluator.symInfo.symbolExprsEvaluators, evaluator.symInfo.symbolExprsOIs); @@ -300,7 +300,7 @@ public boolean transformsRawInput() @Override public void initializeOutputOI() throws HiveException { try { - NPath evaluator = (NPath) getEvaluator(); + MatchPath evaluator = (MatchPath) getEvaluator(); PartitionedTableFunctionDef tDef = evaluator.getTableDef(); ArrayList args = tDef.getArgs(); @@ -314,7 +314,7 @@ public void initializeOutputOI() throws HiveException { /* * setup OI for input to resultExpr select list */ - StructObjectInspector selectListInputOI = NPath.createSelectListOI( evaluator, + StructObjectInspector selectListInputOI = MatchPath.createSelectListOI( evaluator, tDef.getInput()); ResultExprInfo resultExprInfo = evaluator.resultExprInfo; ArrayList selectListExprOIs = new ArrayList(); @@ -340,7 +340,7 @@ public void initializeOutputOI() throws HiveException { @Override public ArrayList getOutputColumnNames() { - NPath evaluator = (NPath) getEvaluator(); + MatchPath evaluator = (MatchPath) getEvaluator(); return evaluator.resultExprInfo.getResultExprNames(); } @@ -788,7 +788,7 @@ else if (exprNode instanceof ExprNodeColumnDesc) ExprNodeColumnDesc colDesc = (ExprNodeColumnDesc) exprNode; return colDesc.getColumn(); } - return "npath_col_" + colIdx; + return "matchpath_col_" + colIdx; } public static ExprNodeDesc buildExprNode(ASTNode expr, @@ -815,7 +815,7 @@ public static ExprNodeDesc buildExprNode(ASTNode expr, /* * add array to the list of columns */ - protected static RowResolver createSelectListRR(NPath evaluator, + protected static RowResolver createSelectListRR(MatchPath evaluator, PTFInputDef inpDef) throws SemanticException { RowResolver rr = new RowResolver(); RowResolver inputRR = inpDef.getOutputShape().getRr(); @@ -863,7 +863,7 @@ protected static RowResolver createSelectListRR(NPath evaluator, return rr; } - protected static StructObjectInspector createSelectListOI(NPath evaluator, PTFInputDef inpDef) { + protected static StructObjectInspector createSelectListOI(MatchPath evaluator, PTFInputDef inpDef) { StructObjectInspector inOI = inpDef.getOutputShape().getOI(); ArrayList inputColumnNames = new ArrayList(); ArrayList selectListNames = new ArrayList(); @@ -885,13 +885,13 @@ protected static StructObjectInspector createSelectListOI(NPath evaluator, PTFIn ArrayList selectFieldOIs = new ArrayList(); selectFieldOIs.addAll(fieldOIs); selectFieldOIs.add(pathAttrOI); - selectListNames.add(NPath.PATHATTR_NAME); + selectListNames.add(MatchPath.PATHATTR_NAME); return ObjectInspectorFactory.getStandardStructObjectInspector( selectListNames, selectFieldOIs); } public static Object getSelectListInput(Object currRow, ObjectInspector rowOI, - PTFPartitionIterator pItr, int sz) { + PTFPartitionIterator pItr, int sz) throws HiveException { ArrayList oRow = new ArrayList(); List currRowAsStdObject = (List) ObjectInspectorUtils .copyToStandardObject(currRow, rowOI); @@ -901,7 +901,7 @@ public static Object getSelectListInput(Object currRow, ObjectInspector rowOI, } public static ArrayList getPath(Object currRow, ObjectInspector rowOI, - PTFPartitionIterator pItr, int sz) { + PTFPartitionIterator pItr, int sz) throws HiveException { int idx = pItr.getIndex() - 1; ArrayList path = new ArrayList(); path.add(ObjectInspectorUtils.copyToStandardObject(currRow, rowOI)); diff --git a/ql/src/test/queries/clientpositive/ptf_npath.q b/ql/src/test/queries/clientpositive/ptf_matchpath.q similarity index 86% rename from ql/src/test/queries/clientpositive/ptf_npath.q rename to ql/src/test/queries/clientpositive/ptf_matchpath.q index 1e91a5ffcd8b..72eeb104d529 100644 --- a/ql/src/test/queries/clientpositive/ptf_npath.q +++ b/ql/src/test/queries/clientpositive/ptf_matchpath.q @@ -12,9 +12,9 @@ FL_NUM string LOAD DATA LOCAL INPATH '../data/files/flights_tiny.txt' OVERWRITE INTO TABLE flights_tiny; --- 1. basic Npath test +-- 1. basic Matchpath test select origin_city_name, fl_num, year, month, day_of_month, sz, tpath -from npath(on +from matchpath(on flights_tiny distribute by fl_num sort by year, month, day_of_month @@ -23,11 +23,11 @@ from npath(on arg4('origin_city_name, fl_num, year, month, day_of_month, size(tpath) as sz, tpath[0].day_of_month as tpath') ); --- 2. Npath on 1 partition +-- 2. Matchpath on 1 partition select origin_city_name, fl_num, year, month, day_of_month, sz, tpath -from npath(on +from matchpath(on flights_tiny - sort by year, month, day_of_month + sort by fl_num, year, month, day_of_month arg1('LATE.LATE+'), arg2('LATE'), arg3(arr_delay > 15), arg4('origin_city_name, fl_num, year, month, day_of_month, size(tpath) as sz, tpath[0].day_of_month as tpath') diff --git a/ql/src/test/queries/clientpositive/ptf_register_tblfn.q b/ql/src/test/queries/clientpositive/ptf_register_tblfn.q index 490c1b14e28e..a2140cd049f2 100644 --- a/ql/src/test/queries/clientpositive/ptf_register_tblfn.q +++ b/ql/src/test/queries/clientpositive/ptf_register_tblfn.q @@ -12,12 +12,12 @@ FL_NUM string LOAD DATA LOCAL INPATH '../data/files/flights_tiny.txt' OVERWRITE INTO TABLE flights_tiny; -create temporary function npathtest as 'org.apache.hadoop.hive.ql.udf.ptf.NPath$NPathResolver'; +create temporary function matchpathtest as 'org.apache.hadoop.hive.ql.udf.ptf.MatchPath$MatchPathResolver'; --- 1. basic Npath test +-- 1. basic Matchpath test select origin_city_name, fl_num, year, month, day_of_month, sz, tpath -from npathtest(on +from matchpathtest(on flights_tiny distribute by fl_num sort by year, month, day_of_month @@ -26,4 +26,4 @@ from npathtest(on arg4('origin_city_name, fl_num, year, month, day_of_month, size(tpath) as sz, tpath[0].day_of_month as tpath') ); -drop temporary function npathtest; +drop temporary function matchpathtest; diff --git a/ql/src/test/results/clientpositive/ptf_npath.q.out b/ql/src/test/results/clientpositive/ptf_matchpath.q.out similarity index 86% rename from ql/src/test/results/clientpositive/ptf_npath.q.out rename to ql/src/test/results/clientpositive/ptf_matchpath.q.out index 17a5a1bd60a7..ed57dcbfb209 100644 --- a/ql/src/test/results/clientpositive/ptf_npath.q.out +++ b/ql/src/test/results/clientpositive/ptf_matchpath.q.out @@ -29,9 +29,9 @@ PREHOOK: Output: default@flights_tiny POSTHOOK: query: LOAD DATA LOCAL INPATH '../data/files/flights_tiny.txt' OVERWRITE INTO TABLE flights_tiny POSTHOOK: type: LOAD POSTHOOK: Output: default@flights_tiny -PREHOOK: query: -- 1. basic Npath test +PREHOOK: query: -- 1. basic Matchpath test select origin_city_name, fl_num, year, month, day_of_month, sz, tpath -from npath(on +from matchpath(on flights_tiny distribute by fl_num sort by year, month, day_of_month @@ -42,9 +42,9 @@ from npath(on PREHOOK: type: QUERY PREHOOK: Input: default@flights_tiny #### A masked pattern was here #### -POSTHOOK: query: -- 1. basic Npath test +POSTHOOK: query: -- 1. basic Matchpath test select origin_city_name, fl_num, year, month, day_of_month, sz, tpath -from npath(on +from matchpath(on flights_tiny distribute by fl_num sort by year, month, day_of_month @@ -71,11 +71,11 @@ Washington 7291 2010 10 27 2 27 Chicago 897 2010 10 20 4 20 Chicago 897 2010 10 21 3 21 Chicago 897 2010 10 22 2 22 -PREHOOK: query: -- 2. Npath on 1 partition +PREHOOK: query: -- 2. Matchpath on 1 partition select origin_city_name, fl_num, year, month, day_of_month, sz, tpath -from npath(on +from matchpath(on flights_tiny - sort by year, month, day_of_month + sort by fl_num, year, month, day_of_month arg1('LATE.LATE+'), arg2('LATE'), arg3(arr_delay > 15), arg4('origin_city_name, fl_num, year, month, day_of_month, size(tpath) as sz, tpath[0].day_of_month as tpath') @@ -84,11 +84,11 @@ where fl_num = 1142 PREHOOK: type: QUERY PREHOOK: Input: default@flights_tiny #### A masked pattern was here #### -POSTHOOK: query: -- 2. Npath on 1 partition +POSTHOOK: query: -- 2. Matchpath on 1 partition select origin_city_name, fl_num, year, month, day_of_month, sz, tpath -from npath(on +from matchpath(on flights_tiny - sort by year, month, day_of_month + sort by fl_num, year, month, day_of_month arg1('LATE.LATE+'), arg2('LATE'), arg3(arr_delay > 15), arg4('origin_city_name, fl_num, year, month, day_of_month, size(tpath) as sz, tpath[0].day_of_month as tpath') @@ -97,6 +97,8 @@ where fl_num = 1142 POSTHOOK: type: QUERY POSTHOOK: Input: default@flights_tiny #### A masked pattern was here #### -Baltimore 1142 2010 10 21 2 21 -Baltimore 1142 2010 10 22 2 22 +Baltimore 1142 2010 10 20 6 20 +Baltimore 1142 2010 10 21 5 21 +Baltimore 1142 2010 10 22 4 22 Baltimore 1142 2010 10 25 3 25 +Baltimore 1142 2010 10 26 2 26 diff --git a/ql/src/test/results/clientpositive/ptf_register_tblfn.q.out b/ql/src/test/results/clientpositive/ptf_register_tblfn.q.out index 2808e1f02b14..0e99d6dbf280 100644 --- a/ql/src/test/results/clientpositive/ptf_register_tblfn.q.out +++ b/ql/src/test/results/clientpositive/ptf_register_tblfn.q.out @@ -29,13 +29,13 @@ PREHOOK: Output: default@flights_tiny POSTHOOK: query: LOAD DATA LOCAL INPATH '../data/files/flights_tiny.txt' OVERWRITE INTO TABLE flights_tiny POSTHOOK: type: LOAD POSTHOOK: Output: default@flights_tiny -PREHOOK: query: create temporary function npathtest as 'org.apache.hadoop.hive.ql.udf.ptf.NPath$NPathResolver' +PREHOOK: query: create temporary function matchpathtest as 'org.apache.hadoop.hive.ql.udf.ptf.MatchPath$MatchPathResolver' PREHOOK: type: CREATEFUNCTION -POSTHOOK: query: create temporary function npathtest as 'org.apache.hadoop.hive.ql.udf.ptf.NPath$NPathResolver' +POSTHOOK: query: create temporary function matchpathtest as 'org.apache.hadoop.hive.ql.udf.ptf.MatchPath$MatchPathResolver' POSTHOOK: type: CREATEFUNCTION -PREHOOK: query: -- 1. basic Npath test +PREHOOK: query: -- 1. basic Matchpath test select origin_city_name, fl_num, year, month, day_of_month, sz, tpath -from npathtest(on +from matchpathtest(on flights_tiny distribute by fl_num sort by year, month, day_of_month @@ -46,9 +46,9 @@ from npathtest(on PREHOOK: type: QUERY PREHOOK: Input: default@flights_tiny #### A masked pattern was here #### -POSTHOOK: query: -- 1. basic Npath test +POSTHOOK: query: -- 1. basic Matchpath test select origin_city_name, fl_num, year, month, day_of_month, sz, tpath -from npathtest(on +from matchpathtest(on flights_tiny distribute by fl_num sort by year, month, day_of_month @@ -75,7 +75,7 @@ Washington 7291 2010 10 27 2 27 Chicago 897 2010 10 20 4 20 Chicago 897 2010 10 21 3 21 Chicago 897 2010 10 22 2 22 -PREHOOK: query: drop temporary function npathtest +PREHOOK: query: drop temporary function matchpathtest PREHOOK: type: DROPFUNCTION -POSTHOOK: query: drop temporary function npathtest +POSTHOOK: query: drop temporary function matchpathtest POSTHOOK: type: DROPFUNCTION diff --git a/ql/src/test/results/clientpositive/show_functions.q.out b/ql/src/test/results/clientpositive/show_functions.q.out index e8e7233113be..20d63172998b 100644 --- a/ql/src/test/results/clientpositive/show_functions.q.out +++ b/ql/src/test/results/clientpositive/show_functions.q.out @@ -103,6 +103,7 @@ ltrim map map_keys map_values +matchpath max min minute @@ -113,7 +114,6 @@ ngrams noop noopwithmap not -npath ntile nvl or