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;
}
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();
}
}
}
}
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;
}
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;
}
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;
}
Aggregations