use of com.actiontech.dble.plan.common.item.subquery.ItemAllAnySubQuery in project dble by actiontech.
the class BaseHandlerBuilder method handleBlockingSubQuery.
protected void handleBlockingSubQuery() {
if (node.getSubQueries().size() == 0) {
return;
}
final ReentrantLock lock = new ReentrantLock();
final Condition finishSubQuery = lock.newCondition();
final AtomicBoolean finished = new AtomicBoolean(false);
final AtomicInteger subNodes = new AtomicInteger(node.getSubQueries().size());
final CopyOnWriteArrayList<ErrorPacket> errorPackets = new CopyOnWriteArrayList<>();
for (ItemSubQuery itemSubQuery : node.getSubQueries()) {
if (itemSubQuery instanceof ItemSingleRowSubQuery) {
final SubQueryHandler tempHandler = new SingleRowSubQueryHandler(getSequenceId(), session, (ItemSingleRowSubQuery) itemSubQuery);
if (isExplain) {
handleSubQueryForExplain(lock, finishSubQuery, finished, subNodes, itemSubQuery.getPlanNode(), tempHandler);
} else {
handleSubQuery(lock, finishSubQuery, finished, subNodes, errorPackets, itemSubQuery.getPlanNode(), tempHandler);
}
} else if (itemSubQuery instanceof ItemInSubQuery) {
final SubQueryHandler tempHandler = new InSubQueryHandler(getSequenceId(), session, (ItemInSubQuery) itemSubQuery);
if (isExplain) {
handleSubQueryForExplain(lock, finishSubQuery, finished, subNodes, itemSubQuery.getPlanNode(), tempHandler);
} else {
handleSubQuery(lock, finishSubQuery, finished, subNodes, errorPackets, itemSubQuery.getPlanNode(), tempHandler);
}
} else if (itemSubQuery instanceof ItemAllAnySubQuery) {
final SubQueryHandler tempHandler = new AllAnySubQueryHandler(getSequenceId(), session, (ItemAllAnySubQuery) itemSubQuery);
if (isExplain) {
handleSubQueryForExplain(lock, finishSubQuery, finished, subNodes, itemSubQuery.getPlanNode(), tempHandler);
} else {
handleSubQuery(lock, finishSubQuery, finished, subNodes, errorPackets, itemSubQuery.getPlanNode(), tempHandler);
}
}
}
lock.lock();
try {
while (!finished.get()) {
finishSubQuery.await();
}
} catch (InterruptedException e) {
LOGGER.info("execute ScalarSubQuery " + e);
ErrorPacket errorPackage = new ErrorPacket();
errorPackage.setErrNo(ErrorCode.ER_UNKNOWN_ERROR);
String errorMsg = e.getMessage() == null ? e.toString() : e.getMessage();
errorPackage.setMessage(errorMsg.getBytes(StandardCharsets.UTF_8));
errorPackets.add(errorPackage);
} finally {
lock.unlock();
}
if (errorPackets.size() > 0) {
throw new MySQLOutPutException(errorPackets.get(0).getErrNo(), "", new String(errorPackets.get(0).getMessage(), StandardCharsets.UTF_8));
}
}
use of com.actiontech.dble.plan.common.item.subquery.ItemAllAnySubQuery in project dble by actiontech.
the class MySQLItemVisitor method handleAnySubQuery.
private void handleAnySubQuery(SQLBinaryOpExpr parent, SQLSelectQuery sqlSelect, boolean isAll) {
SQLBinaryOperator operator = parent.getOperator();
switch(operator) {
case Equality:
if (isAll) {
item = new ItemAllAnySubQuery(currentDb, sqlSelect, operator, true, metaManager);
} else {
Item left = getItem(parent.getLeft());
item = new ItemInSubQuery(currentDb, sqlSelect, left, false, metaManager);
}
break;
case NotEqual:
case LessThanOrGreater:
if (isAll) {
Item left = getItem(parent.getLeft());
item = new ItemInSubQuery(currentDb, sqlSelect, left, true, metaManager);
} else {
item = new ItemAllAnySubQuery(currentDb, sqlSelect, operator, false, metaManager);
}
break;
case LessThan:
case LessThanOrEqual:
case GreaterThan:
case GreaterThanOrEqual:
item = new ItemAllAnySubQuery(currentDb, sqlSelect, operator, isAll, metaManager);
break;
default:
throw new MySQLOutPutException(ErrorCode.ER_OPTIMIZER, "", "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near all");
}
}
Aggregations