Search in sources :

Example 6 with QueryNode

use of com.actiontech.dble.plan.node.QueryNode in project dble by actiontech.

the class SubQueryProcessor method tryTransformerQuery.

/**
 * find query node in qtn ,change to other 3 type node
 */
private static PlanNode tryTransformerQuery(PlanNode qtn, BoolPtr boolptr) {
    boolean childMerged = false;
    for (int index = 0; index < qtn.getChildren().size(); index++) {
        PlanNode child = qtn.getChildren().get(index);
        BoolPtr boolPtr = new BoolPtr(false);
        PlanNode newChild = tryTransformerQuery(child, boolPtr);
        if (boolPtr.get())
            childMerged = true;
        qtn.getChildren().set(index, newChild);
    }
    if (childMerged)
        qtn.setUpFields();
    if (qtn.type() == PlanNodeType.QUERY) {
        qtn = transformerQuery((QueryNode) qtn, boolptr);
    }
    return qtn;
}
Also used : PlanNode(com.actiontech.dble.plan.node.PlanNode) QueryNode(com.actiontech.dble.plan.node.QueryNode) BoolPtr(com.actiontech.dble.plan.common.ptr.BoolPtr)

Example 7 with QueryNode

use of com.actiontech.dble.plan.node.QueryNode in project dble by actiontech.

the class ProxyMetaManager method getSyncView.

public QueryNode getSyncView(String schema, String vName) {
    while (true) {
        int oldVersion = version.get();
        if (metaCount.get() == 0) {
            QueryNode viewNode = catalogs.get(schema).getView(vName);
            if (version.get() == oldVersion) {
                return viewNode;
            }
        } else {
            metaLock.lock();
            try {
                if (lockTables.contains(genLockKey(schema, vName))) {
                    LOGGER.info("schema:" + schema + ", view:" + vName + " is doing ddl,Waiting for table metadata lock");
                    condRelease.await();
                } else {
                    return catalogs.get(schema).getView(vName);
                }
            } catch (InterruptedException e) {
                return null;
            } finally {
                metaLock.unlock();
            }
        }
    }
}
Also used : QueryNode(com.actiontech.dble.plan.node.QueryNode)

Example 8 with QueryNode

use of com.actiontech.dble.plan.node.QueryNode in project dble by actiontech.

the class SchemaMeta method getView.

/**
 * try to get a view meta of querynode
 *
 * @param name
 * @return
 */
public QueryNode getView(String name) {
    ViewMeta view = viewMetas.get(name);
    QueryNode queryNode = null;
    if (view != null) {
        if (view.getViewQuery() != null) {
            queryNode = view.getViewQuery().copy();
        } else {
            ErrorPacket error = view.initAndSet(true);
            if (error != null) {
                throw new RuntimeException(" View '" + view.getViewName() + "' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them");
            } else {
                queryNode = view.getViewQuery().copy();
            }
        }
    }
    return queryNode;
}
Also used : ErrorPacket(com.actiontech.dble.net.mysql.ErrorPacket) QueryNode(com.actiontech.dble.plan.node.QueryNode)

Example 9 with QueryNode

use of com.actiontech.dble.plan.node.QueryNode in project dble by actiontech.

the class ViewMeta method init.

public ErrorPacket init(boolean isReplace) {
    ViewMetaParser viewParser = new ViewMetaParser(createSql);
    try {
        viewParser.parseCreateView(this);
        // check if the select part has
        this.checkDuplicate(viewParser, isReplace);
        SQLSelectStatement selectStatement = (SQLSelectStatement) RouteStrategyFactory.getRouteStrategy().parserSQL(selectSql);
        MySQLPlanNodeVisitor msv = new MySQLPlanNodeVisitor(this.schema, 63, tmManager, true);
        msv.visit(selectStatement.getSelect().getQuery());
        PlanNode selNode = msv.getTableNode();
        selNode.setUpFields();
        // set the view column name into
        this.setFieldsAlias(selNode);
        viewQuery = new QueryNode(selNode);
    } catch (Exception e) {
        // the select part sql is wrong & report the error
        ErrorPacket error = new ErrorPacket();
        error.setMessage(e.getMessage() == null ? "unknow error".getBytes(StandardCharsets.UTF_8) : e.getMessage().getBytes(StandardCharsets.UTF_8));
        error.setErrNo(CREATE_VIEW_ERROR);
        return error;
    }
    return null;
}
Also used : PlanNode(com.actiontech.dble.plan.node.PlanNode) ErrorPacket(com.actiontech.dble.net.mysql.ErrorPacket) QueryNode(com.actiontech.dble.plan.node.QueryNode) SQLSelectStatement(com.alibaba.druid.sql.ast.statement.SQLSelectStatement) MySQLPlanNodeVisitor(com.actiontech.dble.plan.visitor.MySQLPlanNodeVisitor)

Example 10 with QueryNode

use of com.actiontech.dble.plan.node.QueryNode in project dble by actiontech.

the class ViewMeta method initAndSet.

public ErrorPacket initAndSet(boolean isReplace) {
    // check the create sql is legal
    // parse sql into three parts
    ViewMetaParser viewParser = new ViewMetaParser(createSql);
    viewParser.parseCreateView(this);
    try {
        if ("".equals(viewName)) {
            throw new Exception("sql not supported ");
        }
        tmManager.addMetaLock(schema, viewName);
        // check if the select part has
        this.checkDuplicate(viewParser, isReplace);
        SQLSelectStatement selectStatement = (SQLSelectStatement) RouteStrategyFactory.getRouteStrategy().parserSQL(selectSql);
        MySQLPlanNodeVisitor msv = new MySQLPlanNodeVisitor(this.schema, 63, tmManager, true);
        msv.visit(selectStatement.getSelect().getQuery());
        PlanNode selNode = msv.getTableNode();
        selNode.setUpFields();
        // set the view column name into
        this.setFieldsAlias(selNode);
        viewQuery = new QueryNode(selNode);
        tmManager.getCatalogs().get(schema).getViewMetas().put(viewName, this);
    } catch (Exception e) {
        // the select part sql is wrong & report the error
        ErrorPacket error = new ErrorPacket();
        error.setMessage(e.getMessage() == null ? "unknown error".getBytes(StandardCharsets.UTF_8) : e.getMessage().getBytes(StandardCharsets.UTF_8));
        error.setErrNo(CREATE_VIEW_ERROR);
        return error;
    } finally {
        tmManager.removeMetaLock(schema, viewName);
    }
    return null;
}
Also used : PlanNode(com.actiontech.dble.plan.node.PlanNode) ErrorPacket(com.actiontech.dble.net.mysql.ErrorPacket) QueryNode(com.actiontech.dble.plan.node.QueryNode) SQLSelectStatement(com.alibaba.druid.sql.ast.statement.SQLSelectStatement) MySQLPlanNodeVisitor(com.actiontech.dble.plan.visitor.MySQLPlanNodeVisitor)

Aggregations

QueryNode (com.actiontech.dble.plan.node.QueryNode)10 PlanNode (com.actiontech.dble.plan.node.PlanNode)8 ErrorPacket (com.actiontech.dble.net.mysql.ErrorPacket)3 JoinNode (com.actiontech.dble.plan.node.JoinNode)3 Item (com.actiontech.dble.plan.common.item.Item)2 MySQLPlanNodeVisitor (com.actiontech.dble.plan.visitor.MySQLPlanNodeVisitor)2 SQLSelectStatement (com.alibaba.druid.sql.ast.statement.SQLSelectStatement)2 ArrayList (java.util.ArrayList)2 Order (com.actiontech.dble.plan.Order)1 MySQLOutPutException (com.actiontech.dble.plan.common.exception.MySQLOutPutException)1 ItemField (com.actiontech.dble.plan.common.item.ItemField)1 ItemFuncEqual (com.actiontech.dble.plan.common.item.function.operator.cmpfunc.ItemFuncEqual)1 BoolPtr (com.actiontech.dble.plan.common.ptr.BoolPtr)1 MergeNode (com.actiontech.dble.plan.node.MergeNode)1 List (java.util.List)1