Java Code Examples for com.alibaba.fastsql.sql.SQLUtils#parseSingleMysqlStatement()
The following examples show how to use
com.alibaba.fastsql.sql.SQLUtils#parseSingleMysqlStatement() .
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: HBTQueryConvertor.java From Mycat2 with GNU General Public License v3.0 | 5 votes |
private RelDataType tryGetRelDataTypeByParse(String targetName, String sql) { try { RelDataType relDataType; MycatCalcitePlanner planner = MycatCalciteSupport.INSTANCE.createPlanner(context); SQLStatement sqlStatement = SQLUtils.parseSingleMysqlStatement(sql); SqlNode parse = planner.parse(MycatSqlUtil.getCalciteSQL(sqlStatement)); parse = parse.accept(new SqlShuttle() { @Override public SqlNode visit(SqlIdentifier id) { if (id.names.size() == 2) { String schema = id.names.get(0); String table = id.names.get(1); MycatLogicTable logicTable = context.getLogicTable(targetName, schema, table); if (logicTable!=null) { TableHandler table1 = logicTable.getTable(); return new SqlIdentifier(Arrays.asList(table1.getSchemaName(), table1.getTableName()), SqlParserPos.ZERO); } } return super.visit(id); } }); parse = planner.validate(parse); relDataType = planner.convert(parse).getRowType(); return relDataType; } catch (Throwable e) { log.warn("", e); } return null; }
Example 2
Source File: GlobalTable.java From Mycat2 with GNU General Public License v3.0 | 5 votes |
@Override public Function<ParseContext, Iterator<TextUpdateInfo>> insertHandler() { return new Function<ParseContext, Iterator<TextUpdateInfo>>() { @Override public Iterator<TextUpdateInfo> apply(ParseContext s) { SQLStatement sqlStatement = SQLUtils.parseSingleMysqlStatement(s.getSql()); MySqlInsertStatement sqlStatement1 = (MySqlInsertStatement) sqlStatement; SQLExprTableSource tableSource = sqlStatement1.getTableSource(); return updateHandler(tableSource, sqlStatement1); } }; }
Example 3
Source File: GlobalTable.java From Mycat2 with GNU General Public License v3.0 | 5 votes |
@Override public Function<ParseContext, Iterator<TextUpdateInfo>> updateHandler() { return new Function<ParseContext, Iterator<TextUpdateInfo>>() { @Override public Iterator<TextUpdateInfo> apply(ParseContext s) { SQLStatement sqlStatement = SQLUtils.parseSingleMysqlStatement(s.getSql()); MySqlUpdateStatement sqlStatement1 = (MySqlUpdateStatement) sqlStatement; SQLExprTableSource tableSource = (SQLExprTableSource)sqlStatement1.getTableSource(); return updateHandler(tableSource, sqlStatement1); } }; }
Example 4
Source File: GlobalTable.java From Mycat2 with GNU General Public License v3.0 | 5 votes |
@Override public Function<ParseContext, Iterator<TextUpdateInfo>> deleteHandler() { return new Function<ParseContext, Iterator<TextUpdateInfo>>() { @Override public Iterator<TextUpdateInfo> apply(ParseContext parseContext) { SQLStatement sqlStatement = SQLUtils.parseSingleMysqlStatement(parseContext.getSql()); MySqlDeleteStatement sqlStatement1 = (MySqlDeleteStatement) sqlStatement; SQLExprTableSource tableSource = (SQLExprTableSource)sqlStatement1.getTableSource(); return updateHandler(tableSource, sqlStatement1); } }; }
Example 5
Source File: ValuesPlanTest.java From Mycat2 with GNU General Public License v3.0 | 5 votes |
@Test public void test4(){ MyRelBuilder builder = new MyRelBuilder(); SqlToExprTranslator sqlToExprTranslator = new SqlToExprTranslator(builder); SQLSelectStatement sqlSelectStatement = (SQLSelectStatement)SQLUtils.parseSingleMysqlStatement("select 1"); SQLSelectQuery query = sqlSelectStatement.getSelect().getQuery(); QueryPlan queryPlan1 = sqlToExprTranslator.convertQueryRecursive(query); Scanner scan = queryPlan1.scan(dataContext, 0); RowType type = queryPlan1.getType(); String collect = scan.stream().map(i -> i.toString()).collect(Collectors.joining()); }
Example 6
Source File: PreProcesssorTest.java From Mycat2 with GNU General Public License v3.0 | 5 votes |
private String process(String defaultSchema, String sql) { SQLStatement sqlStatement = SQLUtils.parseSingleMysqlStatement(sql); Scope scope = new Scope(defaultSchema); sqlStatement.accept(scope); scope.build(); PreProcesssor preProcesssor = new PreProcesssor(defaultSchema); sqlStatement.accept(preProcesssor); return sqlStatement.toString(); }
Example 7
Source File: TableCollector.java From Mycat2 with GNU General Public License v3.0 | 5 votes |
public static Map<String, Collection<String>> collect(String defaultSchema, String sql) { Map<String, Collection<String>> collectionMap = new HashMap<>(); try { SQLStatement sqlStatement = SQLUtils.parseSingleMysqlStatement(sql); sqlStatement.accept(new MySqlASTVisitorAdapter() { @Override public boolean visit(SQLExprTableSource x) { String schema = x.getSchema(); String tableName = x.getTableName(); if (schema == null) { schema = defaultSchema; } if (schema == null) { throw new UnsupportedOperationException("please use schema"); } schema = SQLUtils.normalize(schema); tableName = SQLUtils.normalize(tableName); Collection<String> strings = collectionMap.computeIfAbsent(schema, s -> new HashSet<>()); strings.add(tableName); return super.visit(x); } }); } catch (Throwable ignored) { } return collectionMap; }
Example 8
Source File: MycatDBSharedServerImpl.java From Mycat2 with GNU General Public License v3.0 | 4 votes |
private PrepareObject prepare(String sql, Long id, MycatDBContext dbContext) { SQLStatement sqlStatement = SQLUtils.parseSingleMysqlStatement(sql);//不支持多语句的预处理 return prepare(sql, id, sqlStatement, dbContext); }
Example 9
Source File: RouteService.java From Mycat2 with GNU General Public License v3.0 | 4 votes |
public Schema route(String sql) { SQLStatement sqlStatement = SQLUtils.parseSingleMysqlStatement(sql); return null; }