Search in sources :

Example 21 with Item

use of com.actiontech.dble.plan.common.item.Item in project dble by actiontech.

the class ItemFunc method fixFields.

@Override
public final ItemFunc fixFields(NameResolutionContext context) {
    getReferTables().clear();
    if (getArgCount() > 0) {
        for (int index = 0; index < getArgCount(); index++) {
            Item arg = args.get(index);
            Item fixedArg = arg.fixFields(context);
            if (fixedArg == null)
                return null;
            args.set(index, fixedArg);
            getReferTables().addAll(fixedArg.getReferTables());
            withSumFunc = withSumFunc || fixedArg.isWithSumFunc();
            withIsNull = withIsNull || fixedArg.isWithIsNull();
            withSubQuery = withSubQuery || fixedArg.isWithSubQuery();
            withUnValAble = withUnValAble || arg.isWithUnValAble();
        }
    }
    return this;
}
Also used : Item(com.actiontech.dble.plan.common.item.Item)

Example 22 with Item

use of com.actiontech.dble.plan.common.item.Item in project dble by actiontech.

the class DruidSelectParser method isSumFuncOrSubQuery.

private boolean isSumFuncOrSubQuery(String schema, SQLExpr itemExpr) {
    MySQLItemVisitor ev = new MySQLItemVisitor(schema, CharsetUtil.getCharsetDefaultIndex("utf8"), DbleServer.getInstance().getTmManager());
    itemExpr.accept(ev);
    Item selItem = ev.getItem();
    return contaisSumFuncOrSubquery(selItem);
}
Also used : MySQLItemVisitor(com.actiontech.dble.plan.visitor.MySQLItemVisitor) Item(com.actiontech.dble.plan.common.item.Item)

Example 23 with Item

use of com.actiontech.dble.plan.common.item.Item in project dble by actiontech.

the class TestMySQLItemVisitor method testGroupbyOrder.

@Test
public void testGroupbyOrder() {
    MySqlSelectQueryBlock query = getQuery("select col1,col2 from table1 group by col1 desc,col2 asc ");
    SQLSelectGroupByClause groupBy = query.getGroupBy();
    int i = 0;
    for (SQLExpr p : groupBy.getItems()) {
        i++;
        String groupCol = "col" + i;
        MySqlOrderingExpr groupitem = (MySqlOrderingExpr) p;
        SQLExpr q = groupitem.getExpr();
        MySQLItemVisitor v = new MySQLItemVisitor(this.currentDb, utf8Charset, null);
        q.accept(v);
        Item item = v.getItem();
        Assert.assertEquals(true, groupCol.equals(item.getItemName()));
    }
}
Also used : Item(com.actiontech.dble.plan.common.item.Item) MySqlOrderingExpr(com.alibaba.druid.sql.dialect.mysql.ast.expr.MySqlOrderingExpr) MySqlSelectQueryBlock(com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlSelectQueryBlock) SQLExpr(com.alibaba.druid.sql.ast.SQLExpr) Test(org.junit.Test)

Example 24 with Item

use of com.actiontech.dble.plan.common.item.Item in project dble by actiontech.

the class TestMySQLItemVisitor method testSelectItem.

@Test
public void testSelectItem() {
    MySqlSelectQueryBlock query = getQuery("select sum(col1) from table1 where a >1 ");
    List<SQLSelectItem> items = query.getSelectList();
    MySQLItemVisitor v = new MySQLItemVisitor(this.currentDb, utf8Charset, null);
    items.get(0).accept(v);
    Item item = v.getItem();
    Assert.assertEquals(true, "SUM(col1)".equals(item.getItemName()));
}
Also used : Item(com.actiontech.dble.plan.common.item.Item) MySqlSelectQueryBlock(com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlSelectQueryBlock) Test(org.junit.Test)

Example 25 with Item

use of com.actiontech.dble.plan.common.item.Item in project dble by actiontech.

the class TestMySQLItemVisitor method testGroupby.

@Test
public void testGroupby() {
    MySqlSelectQueryBlock query = getQuery("select col1,col2 from table1 group by col1,col2");
    SQLSelectGroupByClause groupBy = query.getGroupBy();
    int i = 0;
    for (SQLExpr p : groupBy.getItems()) {
        i++;
        String groupCol = "col" + i;
        MySQLItemVisitor v = new MySQLItemVisitor(this.currentDb, utf8Charset, null);
        p.accept(v);
        Item item = v.getItem();
        Assert.assertEquals(true, groupCol.equals(item.getItemName()));
    }
}
Also used : Item(com.actiontech.dble.plan.common.item.Item) MySqlSelectQueryBlock(com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlSelectQueryBlock) SQLExpr(com.alibaba.druid.sql.ast.SQLExpr) Test(org.junit.Test)

Aggregations

Item (com.actiontech.dble.plan.common.item.Item)122 ArrayList (java.util.ArrayList)26 Order (com.actiontech.dble.plan.Order)16 PlanNode (com.actiontech.dble.plan.node.PlanNode)14 MySQLOutPutException (com.actiontech.dble.plan.common.exception.MySQLOutPutException)10 ItemField (com.actiontech.dble.plan.common.item.ItemField)10 SQLExpr (com.alibaba.druid.sql.ast.SQLExpr)7 MySqlSelectQueryBlock (com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlSelectQueryBlock)7 Test (org.junit.Test)7 FieldPacket (com.actiontech.dble.net.mysql.FieldPacket)6 ItemFuncEqual (com.actiontech.dble.plan.common.item.function.operator.cmpfunc.ItemFuncEqual)6 ItemSum (com.actiontech.dble.plan.common.item.function.sumfunc.ItemSum)6 JoinNode (com.actiontech.dble.plan.node.JoinNode)6 SQLAggregateExpr (com.alibaba.druid.sql.ast.expr.SQLAggregateExpr)6 ItemFunc (com.actiontech.dble.plan.common.item.function.ItemFunc)5 ItemInt (com.actiontech.dble.plan.common.item.ItemInt)4 ItemString (com.actiontech.dble.plan.common.item.ItemString)4 BigDecimal (java.math.BigDecimal)4 RowDataPacket (com.actiontech.dble.net.mysql.RowDataPacket)3 NamedField (com.actiontech.dble.plan.NamedField)3