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


Java SqlParser类代码示例

本文整理汇总了Java中org.nlpcn.es4sql.parse.SqlParser的典型用法代码示例。如果您正苦于以下问题:Java SqlParser类的具体用法?Java SqlParser怎么用?Java SqlParser使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: create

import org.nlpcn.es4sql.parse.SqlParser; //导入依赖的package包/类
/**
 * Create the compatible Query object
 * based on the SQL query.
 *
 * @param sql The SQL query.
 * @return Query object.
 */
public static QueryAction create(Client client, String sql) throws SqlParseException, SQLFeatureNotSupportedException {
	String firstWord = sql.substring(0, sql.indexOf(' '));
	switch (firstWord.toUpperCase()) {
		case "SELECT":
			SQLQueryExpr sqlExpr = (SQLQueryExpr) SQLUtils.toMySqlExpr(sql);
			Select select = new SqlParser().parseSelect(sqlExpr);

			if (select.isAgg) {
				return new AggregationQueryAction(client, select);
			} else {
				return new DefaultQueryAction(client, select);
			}
		case "DELETE":
			SQLStatementParser parser = SQLParserUtils.createSQLStatementParser(sql, JdbcUtils.MYSQL);
			SQLDeleteStatement deleteStatement = parser.parseDeleteStatement();
			Delete delete = new SqlParser().parseDelete(deleteStatement);
			return new DeleteQueryAction(client, delete);

		default:
			throw new SQLFeatureNotSupportedException(String.format("Unsupported query: %s", sql));
	}
}
 
开发者ID:lane-cn,项目名称:elasticsql,代码行数:30,代码来源:ESActionFactory.java

示例2: create

import org.nlpcn.es4sql.parse.SqlParser; //导入依赖的package包/类
/**
 * Create the compatible Query object
 * based on the SQL query.
 *
 * @param sql The SQL query.
 * @return Query object.
 */
public static QueryAction create(Client client, String sql) throws SqlParseException, SQLFeatureNotSupportedException {
	sql = sql.replaceAll("\n"," ");
       String firstWord = sql.substring(0, sql.indexOf(' '));
       switch (firstWord.toUpperCase()) {
		case "SELECT":
			SQLQueryExpr sqlExpr = (SQLQueryExpr) toSqlExpr(sql);
               if(isMulti(sqlExpr)){
                   MultiQuerySelect multiSelect = new SqlParser().parseMultiSelect((SQLUnionQuery) sqlExpr.getSubQuery().getQuery());
                   handleSubQueries(client,multiSelect.getFirstSelect());
                   handleSubQueries(client,multiSelect.getSecondSelect());
                   return new MultiQueryAction(client, multiSelect);
               }
               else if(isJoin(sqlExpr,sql)){
                   JoinSelect joinSelect = new SqlParser().parseJoinSelect(sqlExpr);
                   handleSubQueries(client, joinSelect.getFirstTable());
                   handleSubQueries(client, joinSelect.getSecondTable());
                   return ESJoinQueryActionFactory.createJoinAction(client, joinSelect);
               }
               else {
                   Select select = new SqlParser().parseSelect(sqlExpr);
                   handleSubQueries(client, select);
                   return handleSelect(client, select);
               }
		case "DELETE":
               SQLStatementParser parser = createSqlStatementParser(sql);
			SQLDeleteStatement deleteStatement = parser.parseDeleteStatement();
			Delete delete = new SqlParser().parseDelete(deleteStatement);
			return new DeleteQueryAction(client, delete);
           case "SHOW":
               return new ShowQueryAction(client,sql);
		default:
			throw new SQLFeatureNotSupportedException(String.format("Unsupported query: %s", sql));
	}
}
 
开发者ID:mazhou,项目名称:es-sql,代码行数:42,代码来源:ESActionFactory.java

示例3: init

import org.nlpcn.es4sql.parse.SqlParser; //导入依赖的package包/类
@BeforeClass
public static void init() {
    parser = new SqlParser();
}
 
开发者ID:mazhou,项目名称:es-sql,代码行数:5,代码来源:SQLFunctionsTest.java


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