Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HIVE-5087 Rename npath UDF to matchpath #33

Open
wants to merge 1 commit into
base: shark-0.11
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,15 @@
* "tpath" is available. Path is a collection of rows that represents the matching Path.
* </ol>
*/
public class NPath extends TableFunctionEvaluator
public class MatchPath extends TableFunctionEvaluator
{
private transient String patternStr;
private transient SymbolsInfo symInfo;
private transient String resultExprStr;
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<String,String> inputColumnNamesMap;

Expand All @@ -100,7 +100,7 @@ public void execute(PTFPartitionIterator<Object> 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<Object> oRow = new ArrayList<Object>();
for(ExprNodeEvaluator resExprEval : resultExprInfo.resultExprEvals)
Expand All @@ -115,7 +115,7 @@ public void execute(PTFPartitionIterator<Object> 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));
}
Expand All @@ -128,15 +128,15 @@ public void setInputColumnNames(HashMap<String,String> inputColumnNamesMap) {
this.inputColumnNamesMap = inputColumnNamesMap;
}

public static class NPathResolver extends TableFunctionResolver
public static class MatchPathResolver extends TableFunctionResolver
{

@Override
protected TableFunctionEvaluator createEvaluator(PTFDesc ptfDesc,
PartitionedTableFunctionDef tDef)
{

return new NPath();
return new MatchPath();
}

/**
Expand All @@ -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<PTFExpressionDef> args = tDef.getArgs();
Expand All @@ -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.
Expand All @@ -198,7 +198,7 @@ public void setupOutputOI() throws SemanticException
/*
* validate and setup patternStr
*/
private void validateAndSetupPatternStr(NPath evaluator,
private void validateAndSetupPatternStr(MatchPath evaluator,
ArrayList<PTFExpressionDef> args) throws SemanticException {
PTFExpressionDef symboPatternArg = args.get(0);
ObjectInspector symbolPatternArgOI = symboPatternArg.getOI();
Expand All @@ -218,7 +218,7 @@ private void validateAndSetupPatternStr(NPath evaluator,
/*
* validate and setup SymbolInfo
*/
private void validateAndSetupSymbolInfo(NPath evaluator,
private void validateAndSetupSymbolInfo(MatchPath evaluator,
ArrayList<PTFExpressionDef> args,
int argsNum) throws SemanticException {
int symbolArgsSz = argsNum - 2;
Expand Down Expand Up @@ -262,7 +262,7 @@ private void validateAndSetupSymbolInfo(NPath evaluator,
/*
* validate and setup resultExprStr
*/
private void validateAndSetupResultExprStr(NPath evaluator,
private void validateAndSetupResultExprStr(MatchPath evaluator,
ArrayList<PTFExpressionDef> args,
int argsNum) throws SemanticException {
PTFExpressionDef resultExprArg = args.get(argsNum - 1);
Expand All @@ -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);
Expand All @@ -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<PTFExpressionDef> args = tDef.getArgs();
Expand All @@ -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<ObjectInspector> selectListExprOIs = new ArrayList<ObjectInspector>();
Expand All @@ -340,7 +340,7 @@ public void initializeOutputOI() throws HiveException {

@Override
public ArrayList<String> getOutputColumnNames() {
NPath evaluator = (NPath) getEvaluator();
MatchPath evaluator = (MatchPath) getEvaluator();
return evaluator.resultExprInfo.getResultExprNames();
}

Expand Down Expand Up @@ -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,
Expand All @@ -815,7 +815,7 @@ public static ExprNodeDesc buildExprNode(ASTNode expr,
/*
* add array<struct> 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();
Expand Down Expand Up @@ -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<String> inputColumnNames = new ArrayList<String>();
ArrayList<String> selectListNames = new ArrayList<String>();
Expand All @@ -885,13 +885,13 @@ protected static StructObjectInspector createSelectListOI(NPath evaluator, PTFIn
ArrayList<ObjectInspector> selectFieldOIs = new ArrayList<ObjectInspector>();
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<Object> pItr, int sz) {
PTFPartitionIterator<Object> pItr, int sz) throws HiveException {
ArrayList<Object> oRow = new ArrayList<Object>();
List<?> currRowAsStdObject = (List<?>) ObjectInspectorUtils
.copyToStandardObject(currRow, rowOI);
Expand All @@ -901,7 +901,7 @@ public static Object getSelectListInput(Object currRow, ObjectInspector rowOI,
}

public static ArrayList<Object> getPath(Object currRow, ObjectInspector rowOI,
PTFPartitionIterator<Object> pItr, int sz) {
PTFPartitionIterator<Object> pItr, int sz) throws HiveException {
int idx = pItr.getIndex() - 1;
ArrayList<Object> path = new ArrayList<Object>();
path.add(ObjectInspectorUtils.copyToStandardObject(currRow, rowOI));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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')
Expand Down
8 changes: 4 additions & 4 deletions ql/src/test/queries/clientpositive/ptf_register_tblfn.q
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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')
Expand All @@ -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')
Expand All @@ -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
16 changes: 8 additions & 8 deletions ql/src/test/results/clientpositive/ptf_register_tblfn.q.out
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
2 changes: 1 addition & 1 deletion ql/src/test/results/clientpositive/show_functions.q.out
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ ltrim
map
map_keys
map_values
matchpath
max
min
minute
Expand All @@ -113,7 +114,6 @@ ngrams
noop
noopwithmap
not
npath
ntile
nvl
or
Expand Down