Search in sources :

Example 26 with SQLSelectOrderByItem

use of com.alibaba.druid.sql.ast.statement.SQLSelectOrderByItem in project Mycat-Server by MyCATApache.

the class DruidSelectParser method parseOrderAggGroupMysql.

protected void parseOrderAggGroupMysql(SchemaConfig schema, SQLStatement stmt, RouteResultset rrs, MySqlSelectQueryBlock mysqlSelectQuery) {
    MySqlSchemaStatVisitor visitor = new MySqlSchemaStatVisitor();
    stmt.accept(visitor);
    // rrs.setGroupByCols((String[])visitor.getGroupByColumns().toArray());
    if (!isNeedParseOrderAgg) {
        return;
    }
    Map<String, String> aliaColumns = parseAggGroupCommon(schema, stmt, rrs, mysqlSelectQuery);
    // setOrderByCols
    if (mysqlSelectQuery.getOrderBy() != null) {
        List<SQLSelectOrderByItem> orderByItems = mysqlSelectQuery.getOrderBy().getItems();
        rrs.setOrderByCols(buildOrderByCols(orderByItems, aliaColumns));
    }
    isNeedParseOrderAgg = false;
}
Also used : MySqlSchemaStatVisitor(com.alibaba.druid.sql.dialect.mysql.visitor.MySqlSchemaStatVisitor) SQLSelectOrderByItem(com.alibaba.druid.sql.ast.statement.SQLSelectOrderByItem)

Example 27 with SQLSelectOrderByItem

use of com.alibaba.druid.sql.ast.statement.SQLSelectOrderByItem in project Mycat-Server by MyCATApache.

the class DruidSelectOracleParser method parseOrderAggGroupOracle.

protected void parseOrderAggGroupOracle(SQLStatement stmt, RouteResultset rrs, OracleSelectQueryBlock mysqlSelectQuery, SchemaConfig schema) {
    Map<String, String> aliaColumns = parseAggGroupCommon(schema, stmt, rrs, mysqlSelectQuery);
    OracleSelect oracleSelect = (OracleSelect) mysqlSelectQuery.getParent();
    if (oracleSelect.getOrderBy() != null) {
        List<SQLSelectOrderByItem> orderByItems = oracleSelect.getOrderBy().getItems();
        rrs.setOrderByCols(buildOrderByCols(orderByItems, aliaColumns));
    }
    isNeedParseOrderAgg = false;
}
Also used : OracleSelect(com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleSelect) SQLSelectOrderByItem(com.alibaba.druid.sql.ast.statement.SQLSelectOrderByItem)

Example 28 with SQLSelectOrderByItem

use of com.alibaba.druid.sql.ast.statement.SQLSelectOrderByItem in project canal by alibaba.

the class MemoryTableMeta method processTableElement.

private void processTableElement(SQLTableElement element, TableMeta tableMeta) {
    if (element instanceof SQLColumnDefinition) {
        FieldMeta fieldMeta = new FieldMeta();
        SQLColumnDefinition column = (SQLColumnDefinition) element;
        String name = getSqlName(column.getName());
        // String charset = getSqlName(column.getCharsetExpr());
        SQLDataType dataType = column.getDataType();
        String dataTypStr = dataType.getName();
        if (StringUtils.equalsIgnoreCase(dataTypStr, "float")) {
            if (dataType.getArguments().size() == 1) {
                int num = Integer.valueOf(dataType.getArguments().get(0).toString());
                if (num > 24) {
                    dataTypStr = "double";
                }
            }
        }
        if (dataType.getArguments().size() > 0) {
            dataTypStr += "(";
            for (int i = 0; i < column.getDataType().getArguments().size(); i++) {
                if (i != 0) {
                    dataTypStr += ",";
                }
                SQLExpr arg = column.getDataType().getArguments().get(i);
                dataTypStr += arg.toString();
            }
            dataTypStr += ")";
        }
        if (dataType instanceof SQLDataTypeImpl) {
            SQLDataTypeImpl dataTypeImpl = (SQLDataTypeImpl) dataType;
            if (dataTypeImpl.isUnsigned()) {
                dataTypStr += " unsigned";
            }
            if (dataTypeImpl.isZerofill()) {
                // 如果设置了zerofill,自动给列添加unsigned属性
                if (!dataTypeImpl.isUnsigned()) {
                    dataTypStr += " unsigned";
                }
                dataTypStr += " zerofill";
            }
        }
        if (column.getDefaultExpr() == null || column.getDefaultExpr() instanceof SQLNullExpr) {
            fieldMeta.setDefaultValue(null);
        } else {
            fieldMeta.setDefaultValue(DruidDdlParser.unescapeQuotaName(getSqlName(column.getDefaultExpr())));
        }
        fieldMeta.setColumnName(name);
        fieldMeta.setColumnType(dataTypStr);
        fieldMeta.setNullable(true);
        List<SQLColumnConstraint> constraints = column.getConstraints();
        for (SQLColumnConstraint constraint : constraints) {
            if (constraint instanceof SQLNotNullConstraint) {
                fieldMeta.setNullable(false);
            } else if (constraint instanceof SQLNullConstraint) {
                fieldMeta.setNullable(true);
            } else if (constraint instanceof SQLColumnPrimaryKey) {
                fieldMeta.setKey(true);
                fieldMeta.setNullable(false);
            } else if (constraint instanceof SQLColumnUniqueKey) {
                fieldMeta.setUnique(true);
            }
        }
        tableMeta.addFieldMeta(fieldMeta);
    } else if (element instanceof MySqlPrimaryKey) {
        MySqlPrimaryKey column = (MySqlPrimaryKey) element;
        List<SQLSelectOrderByItem> pks = column.getColumns();
        for (SQLSelectOrderByItem pk : pks) {
            String name = getSqlName(pk.getExpr());
            FieldMeta field = tableMeta.getFieldMetaByName(name);
            field.setKey(true);
            field.setNullable(false);
        }
    } else if (element instanceof MySqlUnique) {
        MySqlUnique column = (MySqlUnique) element;
        List<SQLSelectOrderByItem> uks = column.getColumns();
        for (SQLSelectOrderByItem uk : uks) {
            String name = getSqlName(uk.getExpr());
            FieldMeta field = tableMeta.getFieldMetaByName(name);
            field.setUnique(true);
        }
    }
}
Also used : SQLDataType(com.alibaba.druid.sql.ast.SQLDataType) FieldMeta(com.alibaba.otter.canal.parse.inbound.TableMeta.FieldMeta) SQLNullConstraint(com.alibaba.druid.sql.ast.statement.SQLNullConstraint) SQLNullExpr(com.alibaba.druid.sql.ast.expr.SQLNullExpr) SQLColumnDefinition(com.alibaba.druid.sql.ast.statement.SQLColumnDefinition) SQLNotNullConstraint(com.alibaba.druid.sql.ast.statement.SQLNotNullConstraint) SQLColumnConstraint(com.alibaba.druid.sql.ast.statement.SQLColumnConstraint) SQLNullConstraint(com.alibaba.druid.sql.ast.statement.SQLNullConstraint) SQLExpr(com.alibaba.druid.sql.ast.SQLExpr) SQLNotNullConstraint(com.alibaba.druid.sql.ast.statement.SQLNotNullConstraint) SQLColumnPrimaryKey(com.alibaba.druid.sql.ast.statement.SQLColumnPrimaryKey) MySqlUnique(com.alibaba.druid.sql.dialect.mysql.ast.MySqlUnique) SQLColumnUniqueKey(com.alibaba.druid.sql.ast.statement.SQLColumnUniqueKey) MySqlPrimaryKey(com.alibaba.druid.sql.dialect.mysql.ast.MySqlPrimaryKey) SQLColumnConstraint(com.alibaba.druid.sql.ast.statement.SQLColumnConstraint) SQLSelectOrderByItem(com.alibaba.druid.sql.ast.statement.SQLSelectOrderByItem) SQLDataTypeImpl(com.alibaba.druid.sql.ast.SQLDataTypeImpl) List(java.util.List)

Example 29 with SQLSelectOrderByItem

use of com.alibaba.druid.sql.ast.statement.SQLSelectOrderByItem in project druid by alibaba.

the class SQLOrderBy method clone.

public SQLOrderBy clone() {
    SQLOrderBy x = new SQLOrderBy();
    for (SQLSelectOrderByItem item : items) {
        SQLSelectOrderByItem item1 = item.clone();
        item1.setParent(x);
        x.items.add(item1);
    }
    x.sibings = sibings;
    return x;
}
Also used : SQLSelectOrderByItem(com.alibaba.druid.sql.ast.statement.SQLSelectOrderByItem)

Example 30 with SQLSelectOrderByItem

use of com.alibaba.druid.sql.ast.statement.SQLSelectOrderByItem in project druid by alibaba.

the class SQLZOrderBy method clone.

public SQLZOrderBy clone() {
    SQLZOrderBy x = new SQLZOrderBy();
    for (SQLSelectOrderByItem item : items) {
        SQLSelectOrderByItem item1 = item.clone();
        item1.setParent(x);
        x.items.add(item1);
    }
    x.sibings = sibings;
    return x;
}
Also used : SQLSelectOrderByItem(com.alibaba.druid.sql.ast.statement.SQLSelectOrderByItem)

Aggregations

SQLSelectOrderByItem (com.alibaba.druid.sql.ast.statement.SQLSelectOrderByItem)34 SQLExpr (com.alibaba.druid.sql.ast.SQLExpr)11 SQLOrderBy (com.alibaba.druid.sql.ast.SQLOrderBy)5 SQLSelectItem (com.alibaba.druid.sql.ast.statement.SQLSelectItem)4 SQLStatement (com.alibaba.druid.sql.ast.SQLStatement)3 SQLListExpr (com.alibaba.druid.sql.ast.expr.SQLListExpr)3 SQLNullExpr (com.alibaba.druid.sql.ast.expr.SQLNullExpr)3 SQLColumnDefinition (com.alibaba.druid.sql.ast.statement.SQLColumnDefinition)3 SQLConstraint (com.alibaba.druid.sql.ast.statement.SQLConstraint)3 SQLSelectGroupByClause (com.alibaba.druid.sql.ast.statement.SQLSelectGroupByClause)3 Order (com.actiontech.dble.plan.Order)2 SQLExprImpl (com.alibaba.druid.sql.ast.SQLExprImpl)2 SQLName (com.alibaba.druid.sql.ast.SQLName)2 SQLObject (com.alibaba.druid.sql.ast.SQLObject)2 SQLOrderingSpecification (com.alibaba.druid.sql.ast.SQLOrderingSpecification)2 SQLBinaryOpExpr (com.alibaba.druid.sql.ast.expr.SQLBinaryOpExpr)2 SQLInSubQueryExpr (com.alibaba.druid.sql.ast.expr.SQLInSubQueryExpr)2 SQLQueryExpr (com.alibaba.druid.sql.ast.expr.SQLQueryExpr)2 SQLSelect (com.alibaba.druid.sql.ast.statement.SQLSelect)2 SQLTableElement (com.alibaba.druid.sql.ast.statement.SQLTableElement)2