*/
@Override
public void setupOutputOI() throws WindowingException
{
NPath evaluator = (NPath) getEvaluator();
TableFuncDef tDef = evaluator.getTableDef();
ArrayList<ArgDef> args = tDef.getArgs();
int argsNum = args == null ? 0 : args.size();
if ( argsNum < 4 )
{
throwErrorWithSignature("at least 4 arguments required");
}
/*
* validate and setup patternStr
*/
ArgDef symboPatternArg = args.get(0);
ObjectInspector symbolPatternArgOI = symboPatternArg.getOI();
if ( !ObjectInspectorUtils.isConstantObjectInspector(symbolPatternArgOI) ||
(symbolPatternArgOI.getCategory() != ObjectInspector.Category.PRIMITIVE) ||
((PrimitiveObjectInspector)symbolPatternArgOI).getPrimitiveCategory() != PrimitiveObjectInspector.PrimitiveCategory.STRING )
{
throwErrorWithSignature("Currently the symbol Pattern must be a Constant String.");
}
evaluator.patternStr = ((ConstantObjectInspector)symbolPatternArgOI).getWritableConstantValue().toString();
/*
* validate and setup SymbolInfo
*/
int symbolArgsSz = argsNum - 2;
if ( symbolArgsSz % 2 != 0)
{
throwErrorWithSignature("Symbol Name, Expression need to be specified in pairs: there are odd number of symbol args");
}
evaluator.symInfo = new SymbolsInfo(symbolArgsSz/2);
for(int i=1; i <= symbolArgsSz; i += 2)
{
ArgDef symbolNameArg = args.get(i);
ObjectInspector symbolNameArgOI = symbolNameArg.getOI();
if ( !ObjectInspectorUtils.isConstantObjectInspector(symbolNameArgOI) ||
(symbolNameArgOI.getCategory() != ObjectInspector.Category.PRIMITIVE) ||
((PrimitiveObjectInspector)symbolNameArgOI).getPrimitiveCategory() != PrimitiveObjectInspector.PrimitiveCategory.STRING )
{
throwErrorWithSignature(sprintf("Currently a Symbol Name(%s) must be a Constant String", symbolNameArg.getExpression().toStringTree()));
}
String symbolName = ((ConstantObjectInspector)symbolNameArgOI).getWritableConstantValue().toString();
ArgDef symolExprArg = args.get(i+1);
ObjectInspector symolExprArgOI = symolExprArg.getOI();
if ( (symolExprArgOI.getCategory() != ObjectInspector.Category.PRIMITIVE) ||
((PrimitiveObjectInspector)symolExprArgOI).getPrimitiveCategory() != PrimitiveObjectInspector.PrimitiveCategory.BOOLEAN )
{
throwErrorWithSignature(sprintf("Currently a Symbol Expression(%s) must be a boolean expression", symolExprArg.getExpression().toStringTree()));
}
evaluator.symInfo.add(symbolName, symolExprArg);
}
/*
* validate and setup resultExprStr
*/
ArgDef resultExprArg = args.get(argsNum - 1);
ObjectInspector resultExprArgOI = resultExprArg.getOI();
if ( !ObjectInspectorUtils.isConstantObjectInspector(resultExprArgOI) ||
(resultExprArgOI.getCategory() != ObjectInspector.Category.PRIMITIVE) ||
((PrimitiveObjectInspector)resultExprArgOI).getPrimitiveCategory() != PrimitiveObjectInspector.PrimitiveCategory.STRING )
{
throwErrorWithSignature("Currently the result Expr parameter must be a Constant String.");
}
evaluator.resultExprStr = ((ConstantObjectInspector)resultExprArgOI).getWritableConstantValue().toString();
/*
* setup SymbolFunction chain.
*/
SymbolParser syP = new SymbolParser(evaluator.patternStr,
evaluator.symInfo.symbolExprsNames,
evaluator.symInfo.symbolExprsEvaluators, evaluator.symInfo.symbolExprsOIs);
syP.parse();
evaluator.syFn = syP.getSymbolFunction();
/*
* setup OI for input to resultExpr select list
*/
StructObjectInspector selectListInputOI = (StructObjectInspector) NPathUtils.createSelectListInputOI(tDef.getInput().getOI());
/*
* parse ResultExpr Str and setup OI.
*/
ResultExpressionParser resultExprParser = new ResultExpressionParser(evaluator.resultExprStr, selectListInputOI);