Search in sources :

Example 11 with QueryExpression

use of com.alibaba.cobar.parser.ast.expression.misc.QueryExpression in project cobar by alibaba.

the class PartitionKeyVisitor method visit.

@Override
public void visit(SubqueryFactor node) {
    QueryExpression query = node.getSubquery();
    visitChild(2, verdictColumn, verdictGroupFunc, query);
}
Also used : QueryExpression(com.alibaba.cobar.parser.ast.expression.misc.QueryExpression)

Example 12 with QueryExpression

use of com.alibaba.cobar.parser.ast.expression.misc.QueryExpression in project cobar by alibaba.

the class PartitionKeyVisitor method insertReplace.

private void insertReplace(DMLInsertReplaceStatement node) {
    Identifier table = node.getTable();
    List<Identifier> collist = node.getColumnNameList();
    QueryExpression query = node.getSelect();
    List<RowExpression> rows = node.getRowList();
    tableAsTableFactor(table);
    String tableName = table.getIdTextUpUnescape();
    visitChild(2, false, false, collist);
    if (query != null) {
        query.accept(this);
        return;
    }
    for (RowExpression row : rows) {
        visitChild(2, false, false, row);
    }
    Map<String, List<Object>> colVals = ensureColumnValueByTable(tableName);
    Map<String, Map<Object, Set<Pair<Expression, ASTNode>>>> colValsIndex = ensureColumnValueIndexByTable(tableName);
    if (collist != null) {
        for (int i = 0; i < collist.size(); ++i) {
            String colName = collist.get(i).getIdTextUpUnescape();
            if (isRuledColumn(tableName, colName)) {
                List<Object> valueList = ensureColumnValueList(colVals, colName);
                Map<Object, Set<Pair<Expression, ASTNode>>> valMap = ensureColumnValueIndexObjMap(colValsIndex, colName);
                for (RowExpression row : rows) {
                    Expression expr = row.getRowExprList().get(i);
                    Object value = expr == null ? null : expr.evaluation(evaluationParameter);
                    if (value != Expression.UNEVALUATABLE) {
                        valueList.add(value);
                        addIntoColumnValueIndex(valMap, value, row, node);
                    }
                }
            }
        }
    }
}
Also used : SmallSet(com.alibaba.cobar.util.SmallSet) Set(java.util.Set) HashSet(java.util.HashSet) ShowCharaterSet(com.alibaba.cobar.parser.ast.stmt.dal.ShowCharaterSet) RowExpression(com.alibaba.cobar.parser.ast.expression.primary.RowExpression) LiteralString(com.alibaba.cobar.parser.ast.expression.primary.literal.LiteralString) IndexHint(com.alibaba.cobar.parser.ast.fragment.tableref.IndexHint) Identifier(com.alibaba.cobar.parser.ast.expression.primary.Identifier) BetweenAndExpression(com.alibaba.cobar.parser.ast.expression.comparison.BetweenAndExpression) ComparisionEqualsExpression(com.alibaba.cobar.parser.ast.expression.comparison.ComparisionEqualsExpression) QueryExpression(com.alibaba.cobar.parser.ast.expression.misc.QueryExpression) InExpression(com.alibaba.cobar.parser.ast.expression.comparison.InExpression) FunctionExpression(com.alibaba.cobar.parser.ast.expression.primary.function.FunctionExpression) MatchExpression(com.alibaba.cobar.parser.ast.expression.primary.MatchExpression) ComparisionIsExpression(com.alibaba.cobar.parser.ast.expression.comparison.ComparisionIsExpression) LogicalOrExpression(com.alibaba.cobar.parser.ast.expression.logical.LogicalOrExpression) ReplacableExpression(com.alibaba.cobar.parser.ast.expression.ReplacableExpression) LogicalAndExpression(com.alibaba.cobar.parser.ast.expression.logical.LogicalAndExpression) UnaryOperatorExpression(com.alibaba.cobar.parser.ast.expression.UnaryOperatorExpression) ComparisionNullSafeEqualsExpression(com.alibaba.cobar.parser.ast.expression.comparison.ComparisionNullSafeEqualsExpression) LikeExpression(com.alibaba.cobar.parser.ast.expression.string.LikeExpression) CollateExpression(com.alibaba.cobar.parser.ast.expression.type.CollateExpression) Expression(com.alibaba.cobar.parser.ast.expression.Expression) CaseWhenOperatorExpression(com.alibaba.cobar.parser.ast.expression.primary.CaseWhenOperatorExpression) UserExpression(com.alibaba.cobar.parser.ast.expression.misc.UserExpression) PolyadicOperatorExpression(com.alibaba.cobar.parser.ast.expression.PolyadicOperatorExpression) BinaryOperatorExpression(com.alibaba.cobar.parser.ast.expression.BinaryOperatorExpression) RowExpression(com.alibaba.cobar.parser.ast.expression.primary.RowExpression) ASTNode(com.alibaba.cobar.parser.ast.ASTNode) InExpressionList(com.alibaba.cobar.parser.ast.expression.misc.InExpressionList) ArrayList(java.util.ArrayList) List(java.util.List) LinkedList(java.util.LinkedList) QueryExpression(com.alibaba.cobar.parser.ast.expression.misc.QueryExpression) Map(java.util.Map) HashMap(java.util.HashMap) Pair(com.alibaba.cobar.parser.util.Pair)

Example 13 with QueryExpression

use of com.alibaba.cobar.parser.ast.expression.misc.QueryExpression in project cobar by alibaba.

the class MySQLOutputASTVisitor method visit.

@Override
public void visit(SubqueryFactor node) {
    appendable.append('(');
    QueryExpression query = node.getSubquery();
    query.accept(this);
    appendable.append(") AS ").append(node.getAlias());
}
Also used : QueryExpression(com.alibaba.cobar.parser.ast.expression.misc.QueryExpression)

Aggregations

QueryExpression (com.alibaba.cobar.parser.ast.expression.misc.QueryExpression)13 RowExpression (com.alibaba.cobar.parser.ast.expression.primary.RowExpression)7 Expression (com.alibaba.cobar.parser.ast.expression.Expression)6 Identifier (com.alibaba.cobar.parser.ast.expression.primary.Identifier)6 BetweenAndExpression (com.alibaba.cobar.parser.ast.expression.comparison.BetweenAndExpression)4 ComparisionEqualsExpression (com.alibaba.cobar.parser.ast.expression.comparison.ComparisionEqualsExpression)4 ComparisionIsExpression (com.alibaba.cobar.parser.ast.expression.comparison.ComparisionIsExpression)4 ComparisionNullSafeEqualsExpression (com.alibaba.cobar.parser.ast.expression.comparison.ComparisionNullSafeEqualsExpression)4 InExpression (com.alibaba.cobar.parser.ast.expression.comparison.InExpression)4 LogicalAndExpression (com.alibaba.cobar.parser.ast.expression.logical.LogicalAndExpression)4 LogicalOrExpression (com.alibaba.cobar.parser.ast.expression.logical.LogicalOrExpression)4 UserExpression (com.alibaba.cobar.parser.ast.expression.misc.UserExpression)4 CaseWhenOperatorExpression (com.alibaba.cobar.parser.ast.expression.primary.CaseWhenOperatorExpression)4 MatchExpression (com.alibaba.cobar.parser.ast.expression.primary.MatchExpression)4 FunctionExpression (com.alibaba.cobar.parser.ast.expression.primary.function.FunctionExpression)4 LikeExpression (com.alibaba.cobar.parser.ast.expression.string.LikeExpression)4 CollateExpression (com.alibaba.cobar.parser.ast.expression.type.CollateExpression)4 BinaryOperatorExpression (com.alibaba.cobar.parser.ast.expression.BinaryOperatorExpression)2 PolyadicOperatorExpression (com.alibaba.cobar.parser.ast.expression.PolyadicOperatorExpression)2 UnaryOperatorExpression (com.alibaba.cobar.parser.ast.expression.UnaryOperatorExpression)2