use of org.apache.phoenix.parse.UDFParseNode in project phoenix by apache.
the class JoinCompiler method getSubqueryForOptimizedPlan.
private static SelectStatement getSubqueryForOptimizedPlan(HintNode hintNode, List<ColumnDef> dynamicCols, TableRef tableRef, Map<ColumnRef, ColumnRefType> columnRefs, ParseNode where, List<ParseNode> groupBy, List<OrderByNode> orderBy, boolean isWildCardSelect, boolean hasSequence, Map<String, UDFParseNode> udfParseNodes) {
String schemaName = tableRef.getTable().getSchemaName().getString();
TableName tName = TableName.create(schemaName.length() == 0 ? null : schemaName, tableRef.getTable().getTableName().getString());
List<AliasedNode> selectList = new ArrayList<AliasedNode>();
if (isWildCardSelect) {
selectList.add(NODE_FACTORY.aliasedNode(null, WildcardParseNode.INSTANCE));
} else {
for (ColumnRef colRef : columnRefs.keySet()) {
if (colRef.getTableRef().equals(tableRef)) {
ParseNode node = NODE_FACTORY.column(tName, '"' + colRef.getColumn().getName().getString() + '"', null);
if (groupBy != null) {
node = NODE_FACTORY.function(CountAggregateFunction.NAME, Collections.singletonList(node));
}
selectList.add(NODE_FACTORY.aliasedNode(null, node));
}
}
}
String tableAlias = tableRef.getTableAlias();
TableNode from = NODE_FACTORY.namedTable(tableAlias == null ? null : '"' + tableAlias + '"', tName, dynamicCols);
return NODE_FACTORY.select(from, hintNode, false, selectList, where, groupBy, null, orderBy, null, null, 0, groupBy != null, hasSequence, Collections.<SelectStatement>emptyList(), udfParseNodes);
}
use of org.apache.phoenix.parse.UDFParseNode in project phoenix by apache.
the class ExpressionCompiler method visitLeave.
@Override
public /**
* @param node a function expression node
* @param children the child expression arguments to the function expression node.
*/
Expression visitLeave(FunctionParseNode node, List<Expression> children) throws SQLException {
PFunction function = null;
if (node instanceof UDFParseNode) {
function = context.getResolver().resolveFunction(node.getName());
BuiltInFunctionInfo info = new BuiltInFunctionInfo(function);
node = new UDFParseNode(node.getName(), node.getChildren(), info);
}
children = node.validate(children, context);
Expression expression = null;
if (function == null) {
expression = node.create(children, context);
} else {
expression = node.create(children, function, context);
}
ImmutableBytesWritable ptr = context.getTempPtr();
BuiltInFunctionInfo info = node.getInfo();
for (int i = 0; i < info.getRequiredArgCount(); i++) {
// we can get the proper type to use.
if (node.evalToNullIfParamIsNull(context, i)) {
Expression child = children.get(i);
if (ExpressionUtil.isNull(child, ptr)) {
return ExpressionUtil.getNullExpression(expression);
}
}
}
if (ExpressionUtil.isConstant(expression)) {
return ExpressionUtil.getConstantExpression(expression, ptr);
}
expression = addExpression(expression);
expression = wrapGroupByExpression(expression);
if (aggregateFunction == node) {
// Turn back off on the way out
aggregateFunction = null;
}
return expression;
}
Aggregations