use of com.actiontech.dble.plan.common.item.function.strfunc.ItemFuncTrim in project dble by actiontech.
the class MySQLItemVisitor method endVisit.
@Override
public void endVisit(SQLMethodInvokeExpr x) {
List<Item> args = visitExprList(x.getParameters());
String funcName = x.getMethodName().toUpperCase();
Map<String, Object> attributes = x.getAttributes();
switch(funcName) {
case "TRIM":
if (attributes == null) {
item = new ItemFuncTrim(args.get(0), TrimTypeEnum.DEFAULT);
} else {
TrimTypeEnum trimType = TrimTypeEnum.DEFAULT;
String type = (String) attributes.get(ItemFuncKeyWord.TRIM_TYPE);
if (type != null) {
trimType = TrimTypeEnum.valueOf(type);
}
if (attributes.get(ItemFuncKeyWord.FROM) == null) {
item = new ItemFuncTrim(args.get(0), trimType);
} else {
SQLCharExpr from = (SQLCharExpr) attributes.get(ItemFuncKeyWord.FROM);
item = new ItemFuncTrim(args.get(0), getItem(from), trimType);
}
}
break;
case "CONVERT":
if (args.size() >= 2) {
throw new MySQLOutPutException(ErrorCode.ER_OPTIMIZER, "", "not supported CONVERT(expr, type) ,please use CAST(expr AS type)");
}
if (attributes == null || attributes.get(ItemFuncKeyWord.USING) == null) {
throw new MySQLOutPutException(ErrorCode.ER_OPTIMIZER, "", "CONVERT(... USING ...) is standard SQL syntax");
}
item = new ItemFuncConvCharset(args.get(0), (String) attributes.get(ItemFuncKeyWord.USING));
break;
case "CHAR":
if (attributes == null || attributes.get(ItemFuncKeyWord.USING) == null) {
attributes = x.getParameters().get(0).getAttributes();
}
if (attributes == null || attributes.get(ItemFuncKeyWord.USING) == null) {
item = new ItemFuncChar(args, this.charsetIndex);
} else {
item = new ItemFuncChar(args, (String) attributes.get(ItemFuncKeyWord.USING));
}
break;
case "ORD":
item = new ItemFuncOrd(args, this.charsetIndex);
break;
case "ADDDATE":
if (x.getParameters().get(1) instanceof SQLIntegerExpr) {
item = new ItemDateAddInterval(args.get(0), args.get(1), MySqlIntervalUnit.DAY, false);
break;
}
// fallthrough
case "DATE_ADD":
MySqlIntervalExpr intervalExpr = (MySqlIntervalExpr) (x.getParameters().get(1));
item = new ItemDateAddInterval(args.get(0), getItem(intervalExpr.getValue()), getIntervalUnit(x.getParameters().get(1)), false);
break;
case "SUBDATE":
if (x.getParameters().get(1) instanceof SQLIntegerExpr) {
item = new ItemDateAddInterval(args.get(0), args.get(1), MySqlIntervalUnit.DAY, true);
break;
}
// fallthrough
case "DATE_SUB":
MySqlIntervalExpr valueExpr = (MySqlIntervalExpr) (x.getParameters().get(1));
item = new ItemDateAddInterval(args.get(0), getItem(valueExpr.getValue()), getIntervalUnit(x.getParameters().get(1)), true);
break;
case "TIMESTAMPADD":
SQLIdentifierExpr addUnit = (SQLIdentifierExpr) x.getParameters().get(0);
item = new ItemDateAddInterval(args.get(2), args.get(1), MySqlIntervalUnit.valueOf(addUnit.getSimpleName()), false);
break;
case "TIMESTAMPDIFF":
SQLIdentifierExpr diffUnit = (SQLIdentifierExpr) x.getParameters().get(0);
item = new ItemFuncTimestampDiff(args.get(1), args.get(2), MySqlIntervalUnit.valueOf(diffUnit.getSimpleName()));
break;
case "VAR_SAMP":
item = new ItemSumVariance(args, 1, false, null);
break;
case "VAR_POP":
case "VARIANCE":
item = new ItemSumVariance(args, 0, false, null);
break;
case "STD":
case "STDDEV":
case "STDDEV_POP":
item = new ItemSumStd(args, 0, false, null);
break;
case "STDDEV_SAMP":
item = new ItemSumStd(args, 1, false, null);
break;
case "BIT_AND":
item = new ItemSumAnd(args, false, null);
break;
case "BIT_OR":
item = new ItemSumOr(args, false, null);
break;
case "BIT_XOR":
item = new ItemSumXor(args, false, null);
break;
case "IF":
item = new ItemFuncIf(args);
break;
case "GET_FORMAT":
SQLExpr expr = x.getParameters().get(0);
if (expr instanceof SQLIdentifierExpr) {
Item arg0 = new ItemString(((SQLIdentifierExpr) expr).getName());
args.set(0, arg0);
} else {
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 '" + expr.toString() + "'");
}
item = ItemCreate.getInstance().createNativeFunc(funcName, args);
break;
default:
if (ItemCreate.getInstance().isNativeFunc(funcName)) {
item = ItemCreate.getInstance().createNativeFunc(funcName, args);
} else {
// unKnownFunction
item = new ItemFuncUnknown(funcName, args);
}
initName(x);
}
item.setWithSubQuery(getArgsSubQueryStatus(args));
item.setCorrelatedSubQuery(getArgsCorrelatedSubQueryStatus(args));
}
Aggregations