Java Code Examples for com.alibaba.fastsql.sql.dialect.mysql.ast.statement.MySqlSelectQueryBlock#getFrom()
The following examples show how to use
com.alibaba.fastsql.sql.dialect.mysql.ast.statement.MySqlSelectQueryBlock#getFrom() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SqlParser.java From canal-1.1.3 with Apache License 2.0 | 5 votes |
/** * 解析sql * * @param sql sql * @return 视图对象 */ public static SchemaItem parse(String sql) { try { SQLStatementParser parser = new MySqlStatementParser(sql); SQLSelectStatement statement = (SQLSelectStatement) parser.parseStatement(); MySqlSelectQueryBlock sqlSelectQueryBlock = (MySqlSelectQueryBlock) statement.getSelect().getQuery(); SchemaItem schemaItem = new SchemaItem(); schemaItem.setSql(SQLUtils.toMySqlString(sqlSelectQueryBlock)); SQLTableSource sqlTableSource = sqlSelectQueryBlock.getFrom(); List<TableItem> tableItems = new ArrayList<>(); SqlParser.visitSelectTable(schemaItem, sqlTableSource, tableItems, null); tableItems.forEach(tableItem -> schemaItem.getAliasTableItems().put(tableItem.getAlias(), tableItem)); List<FieldItem> fieldItems = collectSelectQueryFields(sqlSelectQueryBlock); fieldItems.forEach(fieldItem -> schemaItem.getSelectFields().put(fieldItem.getFieldName(), fieldItem)); schemaItem.init(); if (schemaItem.getAliasTableItems().isEmpty() || schemaItem.getSelectFields().isEmpty()) { throw new ParserException("Parse sql error"); } return schemaItem; } catch (Exception e) { throw new ParserException(); } }
Example 2
Source File: SqlParser.java From canal with Apache License 2.0 | 5 votes |
/** * 解析sql * * @param sql sql * @return 视图对象 */ public static SchemaItem parse(String sql) { try { SQLStatementParser parser = new MySqlStatementParser(sql); SQLSelectStatement statement = (SQLSelectStatement) parser.parseStatement(); MySqlSelectQueryBlock sqlSelectQueryBlock = (MySqlSelectQueryBlock) statement.getSelect().getQuery(); SchemaItem schemaItem = new SchemaItem(); schemaItem.setSql(SQLUtils.toMySqlString(sqlSelectQueryBlock)); SQLTableSource sqlTableSource = sqlSelectQueryBlock.getFrom(); List<TableItem> tableItems = new ArrayList<>(); SqlParser.visitSelectTable(schemaItem, sqlTableSource, tableItems, null); tableItems.forEach(tableItem -> schemaItem.getAliasTableItems().put(tableItem.getAlias(), tableItem)); List<FieldItem> fieldItems = collectSelectQueryFields(sqlSelectQueryBlock); fieldItems.forEach(fieldItem -> schemaItem.getSelectFields().put(fieldItem.getFieldName(), fieldItem)); schemaItem.init(); if (schemaItem.getAliasTableItems().isEmpty() || schemaItem.getSelectFields().isEmpty()) { throw new ParserException("Parse sql error"); } return schemaItem; } catch (Exception e) { throw new ParserException(); } }
Example 3
Source File: PreProcesssor.java From Mycat2 with GNU General Public License v3.0 | 4 votes |
@Override public boolean visit(MySqlSelectQueryBlock x) { List<SQLSelectItem> selectList = x.getSelectList(); SQLTableSource from = x.getFrom(); SQLExprTableSource into = x.getInto(); SQLExpr where = x.getWhere(); SQLExpr startWith = x.getStartWith(); SQLExpr connectBy = x.getConnectBy(); SQLSelectGroupByClause groupBy = x.getGroupBy(); SQLOrderBy orderBy = x.getOrderBy(); List<SQLWindow> windows = x.getWindows(); List<SQLSelectOrderByItem> distributeBy = x.getDistributeBy(); SQLLimit limit = x.getLimit(); if (from != null) { from.accept(this); } for (int i = 0; i < selectList.size(); i++) { SQLSelectItem item = selectList.get(i); if (item != null) { item.accept(this); } } if (into != null) { throw new UnsupportedOperationException(); } if (where != null) { where.accept(this); } if (groupBy != null) { groupBy.accept(this); } if (orderBy != null) { orderBy.accept(this); } if (limit != null) { limit.accept(this); } if (from != null) { stack.pop(); } return false; }
Example 4
Source File: SqlParser.java From canal with Apache License 2.0 | 4 votes |
public static String parse4FromTableSource(MySqlSelectQueryBlock sqlSelectQueryBlock) { SQLTableSource sqlTableSource = sqlSelectQueryBlock.getFrom(); return SQLUtils.toMySqlString(sqlTableSource); }