当前位置: 首页>>代码示例>>Java>>正文


Java MySqlSelectQueryBlock.getFrom方法代码示例

本文整理汇总了Java中com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlSelectQueryBlock.getFrom方法的典型用法代码示例。如果您正苦于以下问题:Java MySqlSelectQueryBlock.getFrom方法的具体用法?Java MySqlSelectQueryBlock.getFrom怎么用?Java MySqlSelectQueryBlock.getFrom使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlSelectQueryBlock的用法示例。


在下文中一共展示了MySqlSelectQueryBlock.getFrom方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: visit

import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlSelectQueryBlock; //导入方法依赖的package包/类
@Override
public boolean visit(MySqlSelectQueryBlock x) {
    SQLOrderBy orderBy = x.getOrderBy();
    SQLLimit limit = x.getLimit();

    if (limit != null && (orderBy == null || orderBy.getItems().size() == 0)) {
        boolean subQueryHasOrderBy = false;
        SQLTableSource from = x.getFrom();
        if (from instanceof SQLSubqueryTableSource) {
            SQLSubqueryTableSource subqueryTabSrc = (SQLSubqueryTableSource) from;
            SQLSelect select = subqueryTabSrc.getSelect();
            if (select.getQuery() instanceof SQLSelectQueryBlock) {
                SQLSelectQueryBlock subquery = (SQLSelectQueryBlock) select.getQuery();
                if (subquery.getOrderBy() != null && subquery.getOrderBy().getItems().size() > 0) {
                    subQueryHasOrderBy = true;
                }
            }
        }

        if (!subQueryHasOrderBy) {
            unorderedLimitCount++;
        }
    }
    return true;
}
 
开发者ID:zuonima,项目名称:sql-utils,代码行数:26,代码来源:PagerUtils.java

示例2: isSupportSelect

import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlSelectQueryBlock; //导入方法依赖的package包/类
private static boolean isSupportSelect(String stmt) {
    SQLStatementParser parser = new MySqlStatementParser(stmt);
    SQLStatement statement = parser.parseStatement();
    if (!(statement instanceof SQLSelectStatement)) {
        return false;
    }

    SQLSelectQuery sqlSelectQuery = ((SQLSelectStatement) statement).getSelect().getQuery();
    if (!(sqlSelectQuery instanceof MySqlSelectQueryBlock)) {
        return false;
    }
    MySqlSelectQueryBlock selectQueryBlock = (MySqlSelectQueryBlock) sqlSelectQuery;
    SQLTableSource mysqlFrom = selectQueryBlock.getFrom();
    if (mysqlFrom != null) {
        return false;
    }
    for (SQLSelectItem item : selectQueryBlock.getSelectList()) {
        SQLExpr selectItem = item.getExpr();
        if (!isVariantRef(selectItem)) {
            return false;
        }
    }
    return true;
}
 
开发者ID:actiontech,项目名称:dble,代码行数:25,代码来源:SelectHandler.java

示例3: findGroupBy

import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlSelectQueryBlock; //导入方法依赖的package包/类
private void findGroupBy(MySqlSelectQueryBlock query, Select select) throws SqlParseException {
    SQLSelectGroupByClause groupBy = query.getGroupBy();
    SQLTableSource sqlTableSource = query.getFrom();
    if (groupBy == null) {
        return;
    }
    List<SQLExpr> items = groupBy.getItems();

    List<SQLExpr> standardGroupBys = new ArrayList<>();
    for (SQLExpr sqlExpr : items) {
        //todo: mysql expr patch
        if (sqlExpr instanceof MySqlSelectGroupByExpr) {
            MySqlSelectGroupByExpr sqlSelectGroupByExpr = (MySqlSelectGroupByExpr) sqlExpr;
            sqlExpr = sqlSelectGroupByExpr.getExpr();
        }

        if ((sqlExpr instanceof SQLParensIdentifierExpr || !(sqlExpr instanceof SQLIdentifierExpr || sqlExpr instanceof SQLMethodInvokeExpr)) && !standardGroupBys.isEmpty()) {
            // flush the standard group bys
            select.addGroupBy(convertExprsToFields(standardGroupBys, sqlTableSource));
            standardGroupBys = new ArrayList<>();
        }

        if (sqlExpr instanceof SQLParensIdentifierExpr) {
            // single item with parens (should get its own aggregation)
            select.addGroupBy(FieldMaker.makeField(sqlExpr, null, sqlTableSource.getAlias()));
        } else if (sqlExpr instanceof SQLListExpr) {
            // multiple items in their own list
            SQLListExpr listExpr = (SQLListExpr) sqlExpr;
            select.addGroupBy(convertExprsToFields(listExpr.getItems(), sqlTableSource));
        } else {
            // everything else gets added to the running list of standard group bys
            standardGroupBys.add(sqlExpr);
        }
    }
    if (!standardGroupBys.isEmpty()) {
        select.addGroupBy(convertExprsToFields(standardGroupBys, sqlTableSource));
    }
}
 
开发者ID:mazhou,项目名称:es-sql,代码行数:39,代码来源:SqlParser.java

示例4: getOwnerTableName

import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlSelectQueryBlock; //导入方法依赖的package包/类
/**
 * get table name of field in between expr
 *
 * @param betweenExpr
 * @param column
 * @return
 */
private String getOwnerTableName(SQLBetweenExpr betweenExpr, String column) {
    if (tableStats.size() == 1) { //only has 1 table
        return tableStats.keySet().iterator().next().getName();
    } else if (tableStats.size() == 0) { //no table
        return "";
    } else { // multi tables
        for (Column col : columns.keySet()) {
            if (col.getName().equals(column)) {
                return col.getTable();
            }
        }

        //parser from parent
        SQLObject parent = betweenExpr.getParent();
        if (parent instanceof SQLBinaryOpExpr) {
            parent = parent.getParent();
        }

        if (parent instanceof MySqlSelectQueryBlock) {
            MySqlSelectQueryBlock select = (MySqlSelectQueryBlock) parent;
            if (select.getFrom() instanceof SQLJoinTableSource) {
                SQLJoinTableSource joinTableSource = (SQLJoinTableSource) select.getFrom();
                //FIXME :left as driven table
                return joinTableSource.getLeft().toString();
            } else if (select.getFrom() instanceof SQLExprTableSource) {
                return select.getFrom().toString();
            }
        } else if (parent instanceof SQLUpdateStatement) {
            SQLUpdateStatement update = (SQLUpdateStatement) parent;
            return update.getTableName().getSimpleName();
        } else if (parent instanceof SQLDeleteStatement) {
            SQLDeleteStatement delete = (SQLDeleteStatement) parent;
            return delete.getTableName().getSimpleName();
        }
    }
    return "";
}
 
开发者ID:actiontech,项目名称:dble,代码行数:45,代码来源:ServerSchemaStatVisitor.java

示例5: testJoinCondition

import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlSelectQueryBlock; //导入方法依赖的package包/类
@Test
public void testJoinCondition() {
    MySqlSelectQueryBlock query = getQuery("select a.col1,b.col2  from table1 a inner join table2 b on a.id =b.id");
    SQLJoinTableSource from = (SQLJoinTableSource) query.getFrom();

    MySQLItemVisitor v = new MySQLItemVisitor(this.currentDb, utf8Charset,null);
    from.getCondition().accept(v);
    Item item = v.getItem();
    Assert.assertEquals(true, "a.id = b.id".equals(item.getItemName()));
}
 
开发者ID:actiontech,项目名称:dble,代码行数:11,代码来源:TestMySQLItemVisitor.java

示例6: visit

import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlSelectQueryBlock; //导入方法依赖的package包/类
public boolean visit(MySqlSelectQueryBlock x) {
    if (x.getOrderBy() != null) {
        x.getOrderBy().setParent(x);
    }

    print0(ucase ? "SELECT COUNT(*) " : "select count(*) ");

    if (x.getFrom() != null) {
        println();
        print0(ucase ? "FROM " : "from ");
        x.getFrom().accept(this);
    }

    if (x.getWhere() != null) {
        println();
        print0(ucase ? "WHERE " : "where ");
        x.getWhere().setParent(x);
        x.getWhere().accept(this);
    }

    if (x.getGroupBy() != null) {
        println();
        x.getGroupBy().accept(this);
    }

    if (x.getOrderBy() != null) {
        println();
        x.getOrderBy().accept(this);
    }

    return false;
}
 
开发者ID:dianping,项目名称:zebra,代码行数:33,代码来源:MysqlCountOutputVisitor.java

示例7: visit

import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlSelectQueryBlock; //导入方法依赖的package包/类
@Override
public boolean visit(final MySqlSelectQueryBlock x) {
	selectLayer++;
    if (x.getFrom() instanceof SQLExprTableSource) {
        SQLExprTableSource tableExpr = (SQLExprTableSource) x.getFrom();
        setCurrentTable(tableExpr.getExpr().toString(), Optional.fromNullable(tableExpr.getAlias()));
    }
    //处理distinct
    if(isEnableCollectMetadata()){
    	if(SQLSetQuantifier.DISTINCT==x.getDistionOption()){
    		parseResult.markDistinct();
    	}
    }
    return super.visit(x);
}
 
开发者ID:balancebeam,项目名称:sherlock,代码行数:16,代码来源:MySQLSelectVisitor.java

示例8: getOwnerTableName

import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlSelectQueryBlock; //导入方法依赖的package包/类
/**
     * 从between语句中获取字段所属的表名。
     * 对于容易出现ambiguous的(字段不知道到底属于哪个表),实际应用中必须使用别名来避免歧义
     * @param betweenExpr
     * @param column
     * @return
     */
    private String getOwnerTableName(SQLBetweenExpr betweenExpr,String column) {
        if(tableStats.size() == 1) {//只有一个表,直接返回这一个表名
            return tableStats.keySet().iterator().next().getName();
        } else if(tableStats.size() == 0) {//一个表都没有,返回空串
            return "";
        } else {//多个表名
            for (Column col : columns.keySet())
            {
                if(col.getName().equals(column)) {
                    return col.getTable();
                }
            }
//            for(Column col : columns) {//从columns中找表名
//                if(col.getName().equals(column)) {
//                    return col.getTable();
//                }
//            }

            //前面没找到表名的,自己从parent中解析

            SQLObject parent = betweenExpr.getParent();
            if(parent instanceof SQLBinaryOpExpr)
            {
                parent=parent.getParent();
            }

            if(parent instanceof MySqlSelectQueryBlock) {
                MySqlSelectQueryBlock select = (MySqlSelectQueryBlock) parent;
                if(select.getFrom() instanceof SQLJoinTableSource) {//多表连接
                    SQLJoinTableSource joinTableSource = (SQLJoinTableSource)select.getFrom();
                    return joinTableSource.getLeft().toString();//将left作为主表,此处有不严谨处,但也是实在没有办法,如果要准确,字段前带表名或者表的别名即可
                } else if(select.getFrom() instanceof SQLExprTableSource) {//单表
                    return select.getFrom().toString();
                }
            }
            else if(parent instanceof SQLUpdateStatement) {
                SQLUpdateStatement update = (SQLUpdateStatement) parent;
                return update.getTableName().getSimpleName();
            } else if(parent instanceof SQLDeleteStatement) {
                SQLDeleteStatement delete = (SQLDeleteStatement) parent;
                return delete.getTableName().getSimpleName();
            } else {
                
            }
        }
        return "";
    }
 
开发者ID:huang-up,项目名称:mycat-src-1.6.1-RELEASE,代码行数:55,代码来源:MycatSchemaStatVisitor.java

示例9: isJoin

import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlSelectQueryBlock; //导入方法依赖的package包/类
private static boolean isJoin(SQLQueryExpr sqlExpr,String sql) {
    MySqlSelectQueryBlock query = (MySqlSelectQueryBlock) sqlExpr.getSubQuery().getQuery();
    return query.getFrom() instanceof  SQLJoinTableSource && sql.toLowerCase().contains("join");
}
 
开发者ID:mazhou,项目名称:es-sql,代码行数:5,代码来源:ESActionFactory.java

示例10: visit

import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlSelectQueryBlock; //导入方法依赖的package包/类
public boolean visit(MySqlSelectQueryBlock sqlSelectQuery) {
    SQLTableSource from = sqlSelectQuery.getFrom();
    if (from != null) {
        visit(from);
        if (this.tableNode instanceof NoNameNode) {
            this.tableNode.setSql(SQLUtils.toMySqlString(sqlSelectQuery));
        }
    } else {
        this.tableNode = new NoNameNode(currentDb, SQLUtils.toMySqlString(sqlSelectQuery));
    }

    if (tableNode != null && (sqlSelectQuery.getDistionOption() == SQLSetQuantifier.DISTINCT || sqlSelectQuery.getDistionOption() == SQLSetQuantifier.DISTINCTROW)) {
        this.tableNode.setDistinct(true);
    }

    List<SQLSelectItem> items = sqlSelectQuery.getSelectList();
    if (items != null) {
        List<Item> selectItems = handleSelectItems(items);
        if (selectItems != null) {
            this.tableNode.select(selectItems);
        }
    }

    SQLExpr whereExpr = sqlSelectQuery.getWhere();
    if (whereExpr != null) {
        handleWhereCondition(whereExpr);
    }

    SQLOrderBy orderBy = sqlSelectQuery.getOrderBy();
    if (orderBy != null) {
        handleOrderBy(orderBy);
    }

    SQLSelectGroupByClause groupBy = sqlSelectQuery.getGroupBy();
    if (groupBy != null) {
        handleGroupBy(groupBy);
    }

    SQLLimit limit = sqlSelectQuery.getLimit();
    if (limit != null) {
        handleLimit(limit);
    }
    return true;
}
 
开发者ID:actiontech,项目名称:dble,代码行数:45,代码来源:MySQLPlanNodeVisitor.java


注:本文中的com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlSelectQueryBlock.getFrom方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。