Search in sources :

Example 21 with FastsqlException

use of com.alibaba.druid.FastsqlException in project druid by alibaba.

the class CalciteMySqlNodeVisitor method visit.

@Override
public boolean visit(SQLExprTableSource x) {
    SqlIdentifier table;
    SQLExpr expr = x.getExpr();
    if (expr instanceof SQLIdentifierExpr) {
        table = buildIdentifier((SQLIdentifierExpr) expr);
    } else if (expr instanceof SQLPropertyExpr) {
        table = buildIdentifier((SQLPropertyExpr) expr);
    } else {
        throw new FastsqlException("not support : " + expr);
    }
    if (x.getAlias() != null) {
        SqlIdentifier alias = new SqlIdentifier(x.computeAlias(), SqlParserPos.ZERO);
        SqlBasicCall as = new SqlBasicCall(SqlStdOperatorTable.AS, new SqlNode[] { table, alias }, SqlParserPos.ZERO);
        sqlNode = as;
    } else {
        sqlNode = table;
    }
    return false;
}
Also used : FastsqlException(com.alibaba.druid.FastsqlException)

Example 22 with FastsqlException

use of com.alibaba.druid.FastsqlException in project druid by alibaba.

the class CalciteMySqlNodeVisitor method buildIdentifier.

SqlIdentifier buildIdentifier(SQLPropertyExpr x) {
    String name = SQLUtils.normalize(x.getName());
    if ("*".equals(name)) {
        name = "";
    }
    SQLExpr owner = x.getOwner();
    List<String> names;
    if (owner instanceof SQLIdentifierExpr) {
        names = Arrays.asList(((SQLIdentifierExpr) owner).normalizedName(), name);
    } else if (owner instanceof SQLPropertyExpr) {
        names = new ArrayList<String>();
        buildIdentifier((SQLPropertyExpr) owner, names);
        names.add(name);
    } else {
        throw new FastsqlException("not support : " + owner);
    }
    return new SqlIdentifier(names, SqlParserPos.ZERO);
}
Also used : FastsqlException(com.alibaba.druid.FastsqlException) DateString(org.apache.calcite.util.DateString) TimestampString(org.apache.calcite.util.TimestampString) TimeString(org.apache.calcite.util.TimeString)

Aggregations

FastsqlException (com.alibaba.druid.FastsqlException)22 IOException (java.io.IOException)16 DateString (org.apache.calcite.util.DateString)2 TimeString (org.apache.calcite.util.TimeString)2 TimestampString (org.apache.calcite.util.TimestampString)2 SQLCommentHint (com.alibaba.druid.sql.ast.SQLCommentHint)1 SQLName (com.alibaba.druid.sql.ast.SQLName)1 SQLObject (com.alibaba.druid.sql.ast.SQLObject)1 SQLStatement (com.alibaba.druid.sql.ast.SQLStatement)1 SQLColumnDefinition (com.alibaba.druid.sql.ast.statement.SQLColumnDefinition)1 SQLShowColumnsStatement (com.alibaba.druid.sql.ast.statement.SQLShowColumnsStatement)1 SQLShowCreateTableStatement (com.alibaba.druid.sql.ast.statement.SQLShowCreateTableStatement)1 MySqlCreateTableStatement (com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlCreateTableStatement)1 MySqlRenameTableStatement (com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlRenameTableStatement)1 SQLEvalVisitor (com.alibaba.druid.sql.visitor.SQLEvalVisitor)1 SqlTypeName (org.apache.calcite.sql.type.SqlTypeName)1