use of com.actiontech.dble.plan.common.exception.MySQLOutPutException in project dble by actiontech.
the class MySQLItemVisitor method endVisit.
@Override
public void endVisit(SQLBinaryExpr x) {
String binary = x.getValue();
if (StringUtil.equals(binary, "")) {
item = new ItemString(binary);
} else {
try {
item = new ItemInt(Long.parseLong(binary, 2));
} catch (NumberFormatException e) {
throw new MySQLOutPutException(ErrorCode.ER_PARSE_ERROR, "", "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 " + x.toString());
}
}
initName(x);
}
use of com.actiontech.dble.plan.common.exception.MySQLOutPutException in project dble by actiontech.
the class MySQLItemVisitor method endVisit.
@Override
public void endVisit(SQLUnaryExpr x) {
Item a = getItem(x.getExpr());
switch(x.getOperator()) {
case Negative:
item = new ItemFuncNeg(a);
break;
case Not:
case NOT:
item = new ItemFuncNot(a);
break;
case Compl:
item = new ItemFuncBitInversion(a);
break;
case Plus:
item = a;
break;
case BINARY:
item = new ItemFuncBinary(a, -1);
break;
default:
throw new MySQLOutPutException(ErrorCode.ER_OPTIMIZER, "", "not supported kind expression:" + x.getOperator());
}
item.setWithSubQuery(a.isWithSubQuery());
item.setCorrelatedSubQuery(a.isCorrelatedSubQuery());
initName(x);
}
use of com.actiontech.dble.plan.common.exception.MySQLOutPutException in project dble by actiontech.
the class MySQLItemVisitor method endVisit.
@Override
public void endVisit(SQLCastExpr x) {
Item a = getItem(x.getExpr());
SQLDataType dataType = x.getDataType();
if (dataType instanceof SQLCharacterDataType) {
SQLCharacterDataType charType = (SQLCharacterDataType) dataType;
String upType = charType.getName().toUpperCase();
List<Integer> args = changeExprListToInt(charType.getArguments());
String charSetName = charType.getCharSetName();
if (upType.equals("CHAR")) {
int len = -1;
if (args.size() > 0) {
len = args.get(0);
}
item = new ItemCharTypecast(a, len, charSetName);
} else if (charSetName == null) {
int len = -1;
if (args.size() > 0) {
len = args.get(0);
}
item = new ItemNCharTypecast(a, len);
} else {
throw new MySQLOutPutException(ErrorCode.ER_PARSE_ERROR, "", "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 'character set " + charSetName + ")'");
}
} else {
CastType castType = getCastType((SQLDataTypeImpl) dataType);
item = ItemCreate.getInstance().createFuncCast(a, castType);
}
initName(x);
}
use of com.actiontech.dble.plan.common.exception.MySQLOutPutException 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");
}
}
use of com.actiontech.dble.plan.common.exception.MySQLOutPutException in project dble by actiontech.
the class MySQLItemVisitor method endVisit.
@Override
public void endVisit(SQLAggregateExpr x) {
List<Item> args = visitExprList(x.getArguments());
String funcName = x.getMethodName().toUpperCase();
SQLAggregateOption option = x.getOption();
boolean isDistinct = option != null;
switch(funcName) {
case "MAX":
item = new ItemSumMax(args, false, null);
break;
case "MIN":
item = new ItemSumMin(args, false, null);
break;
case "SUM":
item = new ItemSumSum(args, isDistinct, false, null);
break;
case "AVG":
item = new ItemSumAvg(args, isDistinct, false, null);
break;
case "GROUP_CONCAT":
SQLOrderBy orderExpr = (SQLOrderBy) x.getAttribute(ItemFuncKeyWord.ORDER_BY);
List<Order> orderList = null;
if (orderExpr != null) {
orderList = new ArrayList<>();
for (SQLSelectOrderByItem orderItem : orderExpr.getItems()) {
Order order = new Order(getItem(orderItem.getExpr()), orderItem.getType());
orderList.add(order);
}
}
SQLCharExpr charExpr = (SQLCharExpr) x.getAttribute(ItemFuncKeyWord.SEPARATOR);
String separator = ",";
if (charExpr != null) {
separator = charExpr.getText();
}
item = new ItemFuncGroupConcat(args, isDistinct, orderList, separator, false, null);
break;
case "COUNT":
item = new ItemSumCount(args, isDistinct, false, null);
break;
case "STDDEV":
item = new ItemSumStd(args, 0, false, null);
break;
default:
throw new MySQLOutPutException(ErrorCode.ER_OPTIMIZER, "", "not supported " + funcName);
}
}
Aggregations