@Override public Expression visitLeave(AndParseNode node, List<Expression> children) throws SQLException { return wrapGroupByExpression(AndExpression.create(children)); }
@Override public Expression visitLeave(OrParseNode node, List<Expression> children) throws SQLException { return wrapGroupByExpression(orExpression(children)); }
@Override public Expression visitLeave(RowValueConstructorParseNode node, List<Expression> l) throws SQLException { // Don't trim trailing nulls here, as we'd potentially be dropping bind // variables that aren't bound yet. return wrapGroupByExpression(new RowValueConstructorExpression(l, node.isStateless())); }
@Override public Expression visitLeave(CaseParseNode node, List<Expression> l) throws SQLException { final Expression caseExpression = CaseExpression.create(l); for (int i = 0; i < node.getChildren().size(); i+=2) { ParseNode childNode = node.getChildren().get(i); if (childNode instanceof BindParseNode) { context.getBindManager().addParamMetaData((BindParseNode)childNode, new DelegateDatum(caseExpression)); } } return wrapGroupByExpression(caseExpression); }
@Override public Expression visitLeave(IsNullParseNode node, List<Expression> children) throws SQLException { ParseNode childNode = node.getChildren().get(0); Expression child = children.get(0); if (childNode instanceof BindParseNode) { // TODO: valid/possibe? context.getBindManager().addParamMetaData((BindParseNode)childNode, child); } return wrapGroupByExpression(IsNullExpression.create(child, node.isNegate(), context.getTempPtr())); }
@Override public Expression visitLeave(NotParseNode node, List<Expression> children) throws SQLException { ParseNode childNode = node.getChildren().get(0); Expression child = children.get(0); if (!PBoolean.INSTANCE.isCoercibleTo(child.getDataType())) { throw TypeMismatchException.newException(PBoolean.INSTANCE, child.getDataType(), node.toString()); } if (childNode instanceof BindParseNode) { // TODO: valid/possibe? context.getBindManager().addParamMetaData((BindParseNode)childNode, child); } return wrapGroupByExpression(NotExpression.create(child, context.getTempPtr())); }
addBindParamMetaData(lhsNode, rhsNode, lhsExpr, rhsExpr); return wrapGroupByExpression(ComparisonExpression.create(op, children, context.getTempPtr(), context.getCurrentTable().getTable().rowKeyOrderOptimizable()));
@Override public Expression visitLeave(StringConcatParseNode node, List<Expression> children) throws SQLException { final StringConcatExpression expression=new StringConcatExpression(children); for (int i = 0; i < children.size(); i++) { ParseNode childNode=node.getChildren().get(i); if(childNode instanceof BindParseNode) { context.getBindManager().addParamMetaData((BindParseNode)childNode,expression); } PDataType type=children.get(i).getDataType(); if(type == PVarbinary.INSTANCE){ throw new SQLExceptionInfo.Builder(SQLExceptionCode.TYPE_NOT_SUPPORTED_FOR_OPERATOR) .setMessage("Concatenation does not support "+ type +" in expression" + node).build().buildException(); } } ImmutableBytesWritable ptr = context.getTempPtr(); if (ExpressionUtil.isConstant(expression)) { return ExpressionUtil.getConstantExpression(expression, ptr); } return wrapGroupByExpression(expression); }
@Override public Expression visitLeave(InListParseNode node, List<Expression> l) throws SQLException { List<Expression> inChildren = l; Expression firstChild = inChildren.get(0); ImmutableBytesWritable ptr = context.getTempPtr(); PDataType firstChildType = firstChild.getDataType(); ParseNode firstChildNode = node.getChildren().get(0); if (firstChildNode instanceof BindParseNode) { PDatum datum = firstChild; if (firstChildType == null) { datum = inferBindDatum(inChildren); } context.getBindManager().addParamMetaData((BindParseNode)firstChildNode, datum); } for (int i = 1; i < l.size(); i++) { ParseNode childNode = node.getChildren().get(i); if (childNode instanceof BindParseNode) { context.getBindManager().addParamMetaData((BindParseNode)childNode, firstChild); } } return wrapGroupByExpression(InListExpression.create(inChildren, node.isNegate(), ptr, context.getCurrentTable().getTable().rowKeyOrderOptimizable())); }
private Expression visitLeave(ArithmeticParseNode node, List<Expression> children, ArithmeticExpressionBinder binder, ArithmeticExpressionFactory factory) throws SQLException { boolean isNull = false; for (Expression child : children) { boolean isChildLiteral = (child instanceof LiteralExpression); isNull |= isChildLiteral && ((LiteralExpression)child).getValue() == null; } Expression expression = factory.create(node, children); for (int i = 0; i < node.getChildren().size(); i++) { ParseNode childNode = node.getChildren().get(i); if (childNode instanceof BindParseNode) { context.getBindManager().addParamMetaData((BindParseNode)childNode, binder == null ? expression : binder.getBindMetaData(i, children, expression)); } } ImmutableBytesWritable ptr = context.getTempPtr(); // If all children are literals, just evaluate now if (ExpressionUtil.isConstant(expression)) { return ExpressionUtil.getConstantExpression(expression, ptr); } else if (isNull) { return LiteralExpression.newConstant(null, expression.getDataType(), expression.getDeterminism()); } // Otherwise create and return the expression return wrapGroupByExpression(expression); }
@Override public Expression visitLeave(CastParseNode node, List<Expression> children) throws SQLException { ParseNode childNode = node.getChildren().get(0); PDataType targetDataType = node.getDataType(); Expression childExpr = children.get(0); PDataType fromDataType = childExpr.getDataType(); if (childNode instanceof BindParseNode) { context.getBindManager().addParamMetaData((BindParseNode)childNode, childExpr); } Expression expr = childExpr; if(fromDataType != null) { /* * IndexStatementRewriter creates a CAST parse node when rewriting the query to use * indexed columns. Without this check present we wrongly and unnecessarily * end up creating a RoundExpression. */ if (context.getCurrentTable().getTable().getType() != PTableType.INDEX) { expr = convertToRoundExpressionIfNeeded(fromDataType, targetDataType, children); } } boolean rowKeyOrderOptimizable = context.getCurrentTable().getTable().rowKeyOrderOptimizable(); return wrapGroupByExpression(CoerceExpression.create(expr, targetDataType, SortOrder.getDefault(), expr.getMaxLength(), rowKeyOrderOptimizable)); }
return wrapGroupByExpression(arrayExpression);
expression = new NotExpression(expression); return wrapGroupByExpression(expression);
@Override public Expression visit(ColumnParseNode node) throws SQLException { ColumnRef ref = resolveColumn(node); TableRef tableRef = ref.getTableRef(); ImmutableBytesWritable ptr = context.getTempPtr(); PColumn column = ref.getColumn(); // If we have an UPDATABLE view, then we compile those view constants (i.e. columns in equality constraints // in the view) to constants. This allows the optimize to optimize out reference to them in various scenarios. // If the column is matched in a WHERE clause against a constant not equal to it's constant, then the entire // query would become degenerate. if (!resolveViewConstants && IndexUtil.getViewConstantValue(column, ptr)) { return LiteralExpression.newConstant(column.getDataType().toObject(ptr), column.getDataType()); } if (tableRef.equals(context.getCurrentTable()) && !SchemaUtil.isPKColumn(column)) { // project only kv columns addColumn(column); } Expression expression = ref.newColumnExpression(node.isTableNameCaseSensitive(), node.isCaseSensitive()); Expression wrappedExpression = wrapGroupByExpression(expression); // If we're in an aggregate expression // and we're not in the context of an aggregate function // and we didn't just wrap our column reference // then we're mixing aggregate and non aggregate expressions in the same expression. // This catches cases like this: SELECT sum(a_integer) + a_integer FROM atable GROUP BY a_string if (isAggregate && aggregateFunction == null && wrappedExpression == expression) { throwNonAggExpressionInAggException(expression.toString()); } return wrappedExpression; }
expression = wrapGroupByExpression(expression); if (aggregateFunction == node) {
@Override public Expression visitLeave(CaseParseNode node, List<Expression> l) throws SQLException { final Expression caseExpression = CaseExpression.create(l); for (int i = 0; i < node.getChildren().size(); i+=2) { ParseNode childNode = node.getChildren().get(i); if (childNode instanceof BindParseNode) { context.getBindManager().addParamMetaData((BindParseNode)childNode, new DelegateDatum(caseExpression)); } } return wrapGroupByExpression(caseExpression); }
@Override public Expression visitLeave(IsNullParseNode node, List<Expression> children) throws SQLException { ParseNode childNode = node.getChildren().get(0); Expression child = children.get(0); if (childNode instanceof BindParseNode) { // TODO: valid/possibe? context.getBindManager().addParamMetaData((BindParseNode)childNode, child); } return wrapGroupByExpression(IsNullExpression.create(child, node.isNegate(), context.getTempPtr())); }
@Override public Expression visitLeave(IsNullParseNode node, List<Expression> children) throws SQLException { ParseNode childNode = node.getChildren().get(0); Expression child = children.get(0); if (childNode instanceof BindParseNode) { // TODO: valid/possibe? context.getBindManager().addParamMetaData((BindParseNode)childNode, child); } return wrapGroupByExpression(IsNullExpression.create(child, node.isNegate(), context.getTempPtr())); }
@Override public Expression visitLeave(NotParseNode node, List<Expression> children) throws SQLException { ParseNode childNode = node.getChildren().get(0); Expression child = children.get(0); if (!PBoolean.INSTANCE.isCoercibleTo(child.getDataType())) { throw TypeMismatchException.newException(PBoolean.INSTANCE, child.getDataType(), node.toString()); } if (childNode instanceof BindParseNode) { // TODO: valid/possibe? context.getBindManager().addParamMetaData((BindParseNode)childNode, child); } return wrapGroupByExpression(NotExpression.create(child, context.getTempPtr())); }
@Override public Expression visitLeave(NotParseNode node, List<Expression> children) throws SQLException { ParseNode childNode = node.getChildren().get(0); Expression child = children.get(0); if (!PBoolean.INSTANCE.isCoercibleTo(child.getDataType())) { throw TypeMismatchException.newException(PBoolean.INSTANCE, child.getDataType(), node.toString()); } if (childNode instanceof BindParseNode) { // TODO: valid/possibe? context.getBindManager().addParamMetaData((BindParseNode)childNode, child); } return wrapGroupByExpression(NotExpression.create(child, context.getTempPtr())); }