use of com.actiontech.dble.plan.node.PlanNode 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.PlanNode 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;
}
use of com.actiontech.dble.plan.node.PlanNode in project dble by actiontech.
the class JoinNodeHandlerBuilder method buildPre.
@Override
public List<DMLResponseHandler> buildPre() {
List<DMLResponseHandler> pres = new ArrayList<>();
PlanNode left = node.getLeftNode();
PlanNode right = node.getRightNode();
if (node.getStrategy() == JoinNode.Strategy.NESTLOOP) {
final boolean isLeftSmall = left.getNestLoopFilters() == null;
final PlanNode tnSmall = isLeftSmall ? left : right;
final PlanNode tnBig = isLeftSmall ? right : left;
// prepare the column for sending
List<Item> keySources = isLeftSmall ? node.getLeftKeys() : node.getRightKeys();
List<Item> keyToPasses = isLeftSmall ? node.getRightKeys() : node.getLeftKeys();
// just find one key as filter later, try to choose a simple column(FIELD_ITEM) from toPasses
int columnIndex = 0;
for (int index = 0; index < keyToPasses.size(); index++) {
Item keyToPass = keyToPasses.get(index);
if (keyToPass.type().equals(ItemType.FIELD_ITEM)) {
columnIndex = index;
break;
}
}
final Item keySource = keySources.get(columnIndex);
final Item keyToPass = keyToPasses.get(columnIndex);
DMLResponseHandler endHandler = buildJoinChild(tnSmall, isLeftSmall);
final TempTableHandler tempHandler = new TempTableHandler(getSequenceId(), session, keySource);
endHandler.setNextHandler(tempHandler);
tempHandler.setLeft(isLeftSmall);
pres.add(tempHandler);
CallBackHandler tempDone = new CallBackHandler() {
@Override
public void call() throws Exception {
Set<String> valueSet = tempHandler.getValueSet();
buildNestFilters(tnBig, keyToPass, valueSet, tempHandler.getMaxPartSize());
DMLResponseHandler bigLh = buildJoinChild(tnBig, !isLeftSmall);
synchronized (tempHandler) {
bigLh.setNextHandler(tempHandler.getNextHandler());
}
tempHandler.setCreatedHandler(bigLh);
HandlerBuilder.startHandler(bigLh);
}
};
if (isExplain) {
buildNestFiltersForExplain(tnBig, keyToPass);
DMLResponseHandler bigLh = buildJoinChild(tnBig, !isLeftSmall);
tempHandler.setCreatedHandler(bigLh);
}
tempHandler.setTempDoneCallBack(tempDone);
} else if (node.getStrategy() == JoinNode.Strategy.SORTMERGE) {
DMLResponseHandler lh = buildJoinChild(left, true);
pres.add(lh);
DMLResponseHandler rh = buildJoinChild(right, false);
pres.add(rh);
} else {
throw new MySQLOutPutException(ErrorCode.ER_QUERYHANDLER, "", "strategy [" + node.getStrategy() + "] not implement yet!");
}
return pres;
}
use of com.actiontech.dble.plan.node.PlanNode in project dble by actiontech.
the class MergeNodeHandlerBuilder method buildPre.
@Override
protected List<DMLResponseHandler> buildPre() {
List<DMLResponseHandler> pres = new ArrayList<>();
for (PlanNode child : node.getChildren()) {
BaseHandlerBuilder builder = hBuilder.getBuilder(session, child, isExplain);
if (builder.getSubQueryBuilderList().size() > 0) {
this.getSubQueryBuilderList().addAll(builder.getSubQueryBuilderList());
}
DMLResponseHandler ch = builder.getEndHandler();
pres.add(ch);
}
return pres;
}
use of com.actiontech.dble.plan.node.PlanNode in project dble by actiontech.
the class PushDownVisitor method visit.
protected void visit(JoinNode join) {
if (!isTopQuery) {
sqlBuilder.append(" ( ");
}
if (join.isSubQuery() || isTopQuery) {
buildSelect(join);
sqlBuilder.append(" from ");
}
PlanNode left = join.getLeftNode();
MysqlVisitor leftVisitor = new GlobalVisitor(left, false);
leftVisitor.visit();
replaceableSqlBuilder.append(leftVisitor.getSql());
sqlBuilder = replaceableSqlBuilder.getCurrentElement().getSb();
if (join.getLeftOuter() && join.getRightOuter()) {
throw new RuntimeException("not supported for full outer join");
} else if (join.getLeftOuter() && !join.getRightOuter()) {
sqlBuilder.append(" left");
} else if (join.getRightOuter() && !join.getLeftOuter()) {
sqlBuilder.append(" right");
}
sqlBuilder.append(" join ");
PlanNode right = join.getRightNode();
MysqlVisitor rightVisitor = new GlobalVisitor(right, false);
rightVisitor.visit();
replaceableSqlBuilder.append(rightVisitor.getSql());
sqlBuilder = replaceableSqlBuilder.getCurrentElement().getSb();
StringBuilder joinOnFilterStr = getJoinOn(join, leftVisitor, rightVisitor);
sqlBuilder.append(joinOnFilterStr.toString());
if (join.isSubQuery() || isTopQuery) {
buildWhere(join, leftVisitor.getWhereFilter(), rightVisitor.getWhereFilter());
buildGroupBy(join);
// having may contains aggregate function, so it need to calc by middle-ware
buildOrderBy(join);
buildLimit(join, sqlBuilder);
}
if (!isTopQuery) {
sqlBuilder.append(" ) ");
if (join.getAlias() != null)
sqlBuilder.append(" ").append(join.getAlias()).append(" ");
}
}
Aggregations