Search in sources :

Example 1 with UDFParseNode

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);
}
Also used : TableName(org.apache.phoenix.parse.TableName) ArrayList(java.util.ArrayList) TableNode(org.apache.phoenix.parse.TableNode) JoinTableNode(org.apache.phoenix.parse.JoinTableNode) NamedTableNode(org.apache.phoenix.parse.NamedTableNode) BindTableNode(org.apache.phoenix.parse.BindTableNode) DerivedTableNode(org.apache.phoenix.parse.DerivedTableNode) UDFParseNode(org.apache.phoenix.parse.UDFParseNode) ComparisonParseNode(org.apache.phoenix.parse.ComparisonParseNode) ColumnParseNode(org.apache.phoenix.parse.ColumnParseNode) AndParseNode(org.apache.phoenix.parse.AndParseNode) WildcardParseNode(org.apache.phoenix.parse.WildcardParseNode) TableWildcardParseNode(org.apache.phoenix.parse.TableWildcardParseNode) EqualParseNode(org.apache.phoenix.parse.EqualParseNode) ParseNode(org.apache.phoenix.parse.ParseNode) ColumnRef(org.apache.phoenix.schema.ColumnRef) LocalIndexDataColumnRef(org.apache.phoenix.schema.LocalIndexDataColumnRef) AliasedNode(org.apache.phoenix.parse.AliasedNode)

Example 2 with UDFParseNode

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;
}
Also used : UDFParseNode(org.apache.phoenix.parse.UDFParseNode) ImmutableBytesWritable(org.apache.hadoop.hbase.io.ImmutableBytesWritable) PFunction(org.apache.phoenix.parse.PFunction) DecimalAddExpression(org.apache.phoenix.expression.DecimalAddExpression) TimestampSubtractExpression(org.apache.phoenix.expression.TimestampSubtractExpression) ArrayConstructorExpression(org.apache.phoenix.expression.ArrayConstructorExpression) Expression(org.apache.phoenix.expression.Expression) LikeExpression(org.apache.phoenix.expression.LikeExpression) ByteBasedLikeExpression(org.apache.phoenix.expression.ByteBasedLikeExpression) DoubleSubtractExpression(org.apache.phoenix.expression.DoubleSubtractExpression) LiteralExpression(org.apache.phoenix.expression.LiteralExpression) InListExpression(org.apache.phoenix.expression.InListExpression) DateSubtractExpression(org.apache.phoenix.expression.DateSubtractExpression) ArrayElemRefExpression(org.apache.phoenix.expression.function.ArrayElemRefExpression) CaseExpression(org.apache.phoenix.expression.CaseExpression) DoubleDivideExpression(org.apache.phoenix.expression.DoubleDivideExpression) NotExpression(org.apache.phoenix.expression.NotExpression) DoubleAddExpression(org.apache.phoenix.expression.DoubleAddExpression) DecimalDivideExpression(org.apache.phoenix.expression.DecimalDivideExpression) RowKeyColumnExpression(org.apache.phoenix.expression.RowKeyColumnExpression) RowValueConstructorExpression(org.apache.phoenix.expression.RowValueConstructorExpression) RoundTimestampExpression(org.apache.phoenix.expression.function.RoundTimestampExpression) StringConcatExpression(org.apache.phoenix.expression.StringConcatExpression) ComparisonExpression(org.apache.phoenix.expression.ComparisonExpression) TimestampAddExpression(org.apache.phoenix.expression.TimestampAddExpression) CoerceExpression(org.apache.phoenix.expression.CoerceExpression) StringBasedLikeExpression(org.apache.phoenix.expression.StringBasedLikeExpression) ArrayAnyComparisonExpression(org.apache.phoenix.expression.function.ArrayAnyComparisonExpression) DecimalSubtractExpression(org.apache.phoenix.expression.DecimalSubtractExpression) ModulusExpression(org.apache.phoenix.expression.ModulusExpression) DoubleMultiplyExpression(org.apache.phoenix.expression.DoubleMultiplyExpression) DecimalMultiplyExpression(org.apache.phoenix.expression.DecimalMultiplyExpression) DateAddExpression(org.apache.phoenix.expression.DateAddExpression) RoundDecimalExpression(org.apache.phoenix.expression.function.RoundDecimalExpression) LongAddExpression(org.apache.phoenix.expression.LongAddExpression) LongSubtractExpression(org.apache.phoenix.expression.LongSubtractExpression) IsNullExpression(org.apache.phoenix.expression.IsNullExpression) AndExpression(org.apache.phoenix.expression.AndExpression) LongMultiplyExpression(org.apache.phoenix.expression.LongMultiplyExpression) ArrayAllComparisonExpression(org.apache.phoenix.expression.function.ArrayAllComparisonExpression) OrExpression(org.apache.phoenix.expression.OrExpression) LongDivideExpression(org.apache.phoenix.expression.LongDivideExpression) BuiltInFunctionInfo(org.apache.phoenix.parse.FunctionParseNode.BuiltInFunctionInfo)

Aggregations

ArrayList (java.util.ArrayList)1 ImmutableBytesWritable (org.apache.hadoop.hbase.io.ImmutableBytesWritable)1 AndExpression (org.apache.phoenix.expression.AndExpression)1 ArrayConstructorExpression (org.apache.phoenix.expression.ArrayConstructorExpression)1 ByteBasedLikeExpression (org.apache.phoenix.expression.ByteBasedLikeExpression)1 CaseExpression (org.apache.phoenix.expression.CaseExpression)1 CoerceExpression (org.apache.phoenix.expression.CoerceExpression)1 ComparisonExpression (org.apache.phoenix.expression.ComparisonExpression)1 DateAddExpression (org.apache.phoenix.expression.DateAddExpression)1 DateSubtractExpression (org.apache.phoenix.expression.DateSubtractExpression)1 DecimalAddExpression (org.apache.phoenix.expression.DecimalAddExpression)1 DecimalDivideExpression (org.apache.phoenix.expression.DecimalDivideExpression)1 DecimalMultiplyExpression (org.apache.phoenix.expression.DecimalMultiplyExpression)1 DecimalSubtractExpression (org.apache.phoenix.expression.DecimalSubtractExpression)1 DoubleAddExpression (org.apache.phoenix.expression.DoubleAddExpression)1 DoubleDivideExpression (org.apache.phoenix.expression.DoubleDivideExpression)1 DoubleMultiplyExpression (org.apache.phoenix.expression.DoubleMultiplyExpression)1 DoubleSubtractExpression (org.apache.phoenix.expression.DoubleSubtractExpression)1 Expression (org.apache.phoenix.expression.Expression)1 InListExpression (org.apache.phoenix.expression.InListExpression)1