use of com.actiontech.dble.plan.common.exception.MySQLOutPutException in project dble by actiontech.
the class HandlerTool method createFieldItem.
protected static ItemField createFieldItem(Item col, List<Field> fields, int startIndex) {
int index = findField(col, fields, startIndex);
if (index < 0)
throw new MySQLOutPutException(ErrorCode.ER_QUERYHANDLER, "", "field not found:" + col);
ItemField ret = new ItemField(fields.get(index));
ret.setItemName(col.getPushDownName() == null ? col.getItemName() : col.getPushDownName());
return ret;
}
use of com.actiontech.dble.plan.common.exception.MySQLOutPutException in project dble by actiontech.
the class ItemCreate method createFuncCast.
public ItemFunc createFuncCast(Item a, CastType type) {
CastTarget castType = type.getTarget();
ItemFunc res = null;
if (castType == CastTarget.ITEM_CAST_BINARY) {
res = new ItemFuncBinary(a, type.getLength());
} else if (castType == CastTarget.ITEM_CAST_SIGNED_INT) {
res = new ItemFuncSigned(a);
} else if (castType == CastTarget.ITEM_CAST_UNSIGNED_INT) {
res = new ItemFuncUnsigned(a);
} else if (castType == CastTarget.ITEM_CAST_DATE) {
res = new ItemDateTypecast(a);
} else if (castType == CastTarget.ITEM_CAST_TIME || castType == CastTarget.ITEM_CAST_DATETIME) {
if (type.getLength() > MyTime.DATETIME_MAX_DECIMALS) {
throw new MySQLOutPutException(ErrorCode.ER_OPTIMIZER, "", "too big precision in cast time/datetime,max 6,current:" + type.getLength());
}
if (type.getLength() == -1) {
res = (castType == CastTarget.ITEM_CAST_TIME) ? new ItemTimeTypecast(a) : new ItemDatetimeTypecast(a);
} else {
res = (castType == CastTarget.ITEM_CAST_TIME) ? new ItemTimeTypecast(a, type.getLength()) : new ItemDatetimeTypecast(a, type.getLength());
}
} else if (castType == CastTarget.ITEM_CAST_DECIMAL) {
if (type.getLength() < type.getDec()) {
throw new MySQLOutPutException(ErrorCode.ER_OPTIMIZER, "", "For float(m,d), double(m,d) or decimal(m,d), M must be >= d");
}
if (type.getLength() > MySQLcom.DECIMAL_MAX_PRECISION) {
throw new MySQLOutPutException(ErrorCode.ER_OPTIMIZER, "", "Too big precision " + type.getLength() + " max is " + MySQLcom.DECIMAL_MAX_PRECISION);
}
if (type.getDec() > MySQLcom.DECIMAL_MAX_SCALE) {
throw new MySQLOutPutException(ErrorCode.ER_OPTIMIZER, "", "Too big scale " + type.getDec() + " max is " + MySQLcom.DECIMAL_MAX_SCALE);
}
res = new ItemDecimalTypecast(a, type.getLength(), type.getDec());
} else if (castType == CastTarget.ITEM_CAST_NCHAR) {
int len = -1;
if (type.getLength() > 0)
len = type.getLength();
res = new ItemNCharTypecast(a, len);
} else {
assert (false);
}
return res;
}
use of com.actiontech.dble.plan.common.exception.MySQLOutPutException 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.common.exception.MySQLOutPutException in project dble by actiontech.
the class TableNodeHandlerBuilder method nestLoopBuild.
@Override
protected void nestLoopBuild() {
try {
List<Item> filters = node.getNestLoopFilters();
PushDownVisitor pdVisitor = new PushDownVisitor(node, true);
if (filters == null || filters.isEmpty())
throw new MySQLOutPutException(ErrorCode.ER_QUERYHANDLER, "", "unexpected exception!");
List<RouteResultsetNode> rrssList = new ArrayList<>();
MergeBuilder mergeBuilder = new MergeBuilder(session, node, needCommon, pdVisitor);
if (tableConfig == null || tableConfig.getTableType() == TableTypeEnum.TYPE_GLOBAL_TABLE) {
for (Item filter : filters) {
node.setWhereFilter(filter);
RouteResultsetNode[] rrssArray = mergeBuilder.construct().getNodes();
rrssList.addAll(Arrays.asList(rrssArray));
}
if (filters.size() == 1) {
this.needCommon = false;
}
} else {
boolean tryGlobal = filters.size() == 1;
for (Item filter : filters) {
node.setWhereFilter(filter);
pdVisitor.visit();
RouteResultsetNode[] rrssArray = mergeBuilder.construct().getNodes();
rrssList.addAll(Arrays.asList(rrssArray));
}
if (tryGlobal) {
this.needCommon = mergeBuilder.getNeedCommonFlag();
}
}
RouteResultsetNode[] rrssArray = new RouteResultsetNode[rrssList.size()];
rrssArray = rrssList.toArray(rrssArray);
buildMergeHandler(node, rrssArray);
} catch (Exception e) {
throw new MySQLOutPutException(ErrorCode.ER_QUERYHANDLER, "", "", e);
}
}
use of com.actiontech.dble.plan.common.exception.MySQLOutPutException in project dble by actiontech.
the class TableNodeHandlerBuilder method buildOwn.
@Override
public void buildOwn() {
try {
PushDownVisitor pdVisitor = new PushDownVisitor(node, true);
MergeBuilder mergeBuilder = new MergeBuilder(session, node, needCommon, pdVisitor);
String sql = null;
if (node.getAst() != null && node.getParent() == null) {
// it's root
pdVisitor.visit();
sql = pdVisitor.getSql().toString();
}
RouteResultsetNode[] rrssArray;
// maybe some node is view
if (sql == null) {
rrssArray = mergeBuilder.construct().getNodes();
} else {
rrssArray = mergeBuilder.constructByStatement(sql, node.getAst()).getNodes();
}
this.needCommon = mergeBuilder.getNeedCommonFlag();
buildMergeHandler(node, rrssArray);
} catch (Exception e) {
throw new MySQLOutPutException(ErrorCode.ER_QUERYHANDLER, "", "table node buildOwn exception!", e);
}
}
Aggregations