use of com.alibaba.druid.support.calcite.CalciteSqlBasicCall in project Mycat2 by MyCATApache.
the class MycatCalciteMySqlNodeVisitor method visit.
public boolean visit(SQLCastExpr x) {
SqlLiteral functionQualifier = null;
SqlNode sqlNode = convertToSqlNode(x.getExpr());
SQLDataType dataType = x.getDataType();
String typeName = dataType.getName().toUpperCase();
if (dataType.nameHashCode64() == FnvHash.Constants.INT) {
typeName = "INTEGER";
} else if (dataType.nameHashCode64() == FnvHash.Constants.NUMERIC) {
typeName = "DECIMAL";
}
SqlIdentifier dataTypeNode = (SqlIdentifier) convertToSqlNode(new SQLIdentifierExpr(typeName));
int scale = -1;
int precision = -1;
List<SQLExpr> arguments = dataType.getArguments();
if (arguments != null && !arguments.isEmpty()) {
scale = ((SQLNumericLiteralExpr) arguments.get(0)).getNumber().intValue();
if (arguments.size() > 1) {
precision = ((SQLNumericLiteralExpr) arguments.get(1)).getNumber().intValue();
}
}
SqlNode sqlDataTypeSpec;
if (typeName.equalsIgnoreCase("SIGNED")) {
sqlDataTypeSpec = new SqlDataTypeSpec(new SqlBasicTypeNameSpec(SqlTypeName.BIGINT, precision, scale, null, SqlParserPos.ZERO), SqlParserPos.ZERO);
} else {
if ("datetime".equalsIgnoreCase(typeName)) {
typeName = "TIMESTAMP";
} else if ("BINARY".equalsIgnoreCase(typeName)) {
typeName = "VARCHAR";
} else if ("UNSIGNED".equalsIgnoreCase(typeName)) {
typeName = "DECIMAL";
}
SqlTypeName sqlTypeName = SqlTypeName.valueOf(typeName);
SqlBasicTypeNameSpec sqlBasicTypeNameSpec = new SqlBasicTypeNameSpec(sqlTypeName, precision, scale, null, SqlParserPos.ZERO);
sqlDataTypeSpec = new SqlDataTypeSpec(sqlBasicTypeNameSpec, SqlParserPos.ZERO);
}
SqlOperator sqlOperator = new SqlCastFunction();
this.sqlNode = new CalciteSqlBasicCall(sqlOperator, new SqlNode[] { sqlNode, sqlDataTypeSpec }, SqlParserPos.ZERO, false, functionQualifier);
return false;
}
Aggregations