本文整理汇总了Java中org.apache.calcite.sql.SqlSelect类的典型用法代码示例。如果您正苦于以下问题:Java SqlSelect类的具体用法?Java SqlSelect怎么用?Java SqlSelect使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SqlSelect类属于org.apache.calcite.sql包,在下文中一共展示了SqlSelect类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: rewrite
import org.apache.calcite.sql.SqlSelect; //导入依赖的package包/类
/** Rewrite the parse tree as SELECT ... FROM INFORMATION_SCHEMA.SCHEMATA ... */
@Override
public SqlNode rewrite(SqlNode sqlNode) throws RelConversionException, ForemanSetupException {
SqlShowSchemas node = unwrap(sqlNode, SqlShowSchemas.class);
List<SqlNode> selectList =
ImmutableList.of((SqlNode) new SqlIdentifier(SCHS_COL_SCHEMA_NAME, SqlParserPos.ZERO));
SqlNode fromClause = new SqlIdentifier(
ImmutableList.of(IS_SCHEMA_NAME, TAB_SCHEMATA), null, SqlParserPos.ZERO, null);
SqlNode where = null;
final SqlNode likePattern = node.getLikePattern();
if (likePattern != null) {
where = DrillParserUtil.createCondition(new SqlIdentifier(SCHS_COL_SCHEMA_NAME, SqlParserPos.ZERO),
SqlStdOperatorTable.LIKE, likePattern);
} else if (node.getWhereClause() != null) {
where = node.getWhereClause();
}
return new SqlSelect(SqlParserPos.ZERO, null, new SqlNodeList(selectList, SqlParserPos.ZERO),
fromClause, where, null, null, null, null, null, null);
}
示例2: validateQuery
import org.apache.calcite.sql.SqlSelect; //导入依赖的package包/类
private void validateQuery() {
SqlNode sqlNode;
try {
sqlNode = delegate.beamSqlEnv.getPlanner().parseQuery(delegate.sqlQuery);
delegate.beamSqlEnv.getPlanner().getPlanner().close();
} catch (SqlParseException e) {
throw new IllegalStateException(e);
}
if (sqlNode instanceof SqlSelect) {
SqlSelect select = (SqlSelect) sqlNode;
String tableName = select.getFrom().toString();
if (!tableName.equalsIgnoreCase(PCOLLECTION_TABLE_NAME)) {
throw new IllegalStateException("Use fixed table name " + PCOLLECTION_TABLE_NAME);
}
} else {
throw new UnsupportedOperationException(
"Sql operation: " + sqlNode.toString() + " is not supported!");
}
}
示例3: convertAgg
import org.apache.calcite.sql.SqlSelect; //导入依赖的package包/类
/**
* Converts the SELECT, GROUP BY and HAVING clauses of an aggregate query.
*
* <p>This method extracts SELECT, GROUP BY and HAVING clauses, and creates
* an {@link AggConverter}, then delegates to {@link #createAggImpl}.
* Derived class may override this method to change any of those clauses or
* specify a different {@link AggConverter}.
*
* @param bb Scope within which to resolve identifiers
* @param select Query
* @param orderExprList Additional expressions needed to implement ORDER BY
*/
protected void convertAgg(
Blackboard bb,
SqlSelect select,
List<SqlNode> orderExprList) {
assert bb.root != null : "precondition: child != null";
SqlNodeList groupList = select.getGroup();
SqlNodeList selectList = select.getSelectList();
SqlNode having = select.getHaving();
final AggConverter aggConverter = new AggConverter(bb, select);
createAggImpl(
bb,
aggConverter,
selectList,
groupList,
having,
orderExprList);
}
示例4: gatherOrderExprs
import org.apache.calcite.sql.SqlSelect; //导入依赖的package包/类
/**
* Creates a list of collations required to implement the ORDER BY clause,
* if there is one. Populates <code>extraOrderExprs</code> with any sort
* expressions which are not in the select clause.
*
* @param bb Scope within which to resolve identifiers
* @param select Select clause. Never null, because we invent a
* dummy SELECT if ORDER BY is applied to a set
* operation (UNION etc.)
* @param orderList Order by clause, may be null
* @param extraOrderExprs Sort expressions which are not in the select
* clause (output)
* @param collationList List of collations (output)
*/
protected void gatherOrderExprs(
Blackboard bb,
SqlSelect select,
SqlNodeList orderList,
List<SqlNode> extraOrderExprs,
List<RelFieldCollation> collationList) {
// TODO: add validation rules to SqlValidator also
assert bb.root != null : "precondition: child != null";
assert select != null;
if (orderList == null) {
return;
}
for (SqlNode orderItem : orderList) {
collationList.add(
convertOrderItem(
select,
orderItem,
extraOrderExprs,
RelFieldCollation.Direction.ASCENDING,
RelFieldCollation.NullDirection.UNSPECIFIED));
}
}
示例5: AggConverter
import org.apache.calcite.sql.SqlSelect; //导入依赖的package包/类
/**
* Creates an AggConverter.
*
* <p>The <code>select</code> parameter provides enough context to name
* aggregate calls which are top-level select list items.
*
* @param bb Blackboard
* @param select Query being translated; provides context to give
*/
public AggConverter(Blackboard bb, SqlSelect select) {
this.bb = bb;
this.aggregatingSelectScope =
(AggregatingSelectScope) bb.getValidator().getSelectScope(select);
// Collect all expressions used in the select list so that aggregate
// calls can be named correctly.
final SqlNodeList selectList = select.getSelectList();
for (int i = 0; i < selectList.size(); i++) {
SqlNode selectItem = selectList.get(i);
String name = null;
if (SqlUtil.isCallTo(
selectItem,
SqlStdOperatorTable.AS)) {
final SqlCall call = (SqlCall) selectItem;
selectItem = call.operand(0);
name = call.operand(1).toString();
}
if (name == null) {
name = validator.deriveAlias(selectItem, i);
}
nameMap.put(selectItem.toString(), name);
}
}
示例6: visit
import org.apache.calcite.sql.SqlSelect; //导入依赖的package包/类
@Override public Void visit(SqlCall call) {
// ignore window aggregates and ranking functions (associated with OVER operator)
if (call.getOperator().getKind() == SqlKind.OVER) {
return null;
}
if (call.getOperator().isAggregator()) {
list.add(call);
return null;
}
// Don't traverse into sub-queries, even if they contain aggregate
// functions.
if (call instanceof SqlSelect) {
return null;
}
return call.getOperator().acceptCall(this, call);
}
示例7: parse
import org.apache.calcite.sql.SqlSelect; //导入依赖的package包/类
public void parse() {
try {
SchemaPlus schema = Frameworks.createRootSchema(true);
FrameworkConfig config = Frameworks.newConfigBuilder().defaultSchema(schema).build();
Planner planner = Frameworks.getPlanner(config);
SqlSelect sqlSelect = (SqlSelect) planner.parse(sql);
// FROM
streams = parseStreams(sqlSelect);
// SELECT
projection = parseProjection(sqlSelect);
// WHERE
condition = parseCondition(sqlSelect);
// GROUP BY
groupBy = parseGroupBy(sqlSelect);
// HAVING
having = parseHaving(sqlSelect);
} catch (Exception ex) {
LOG.error("Got Exception while parsing rule {}", sql);
throw new RuntimeException(ex);
}
}
示例8: convertAgg
import org.apache.calcite.sql.SqlSelect; //导入依赖的package包/类
/**
* Converts the SELECT, GROUP BY and HAVING clauses of an aggregate query.
*
* <p>This method extracts SELECT, GROUP BY and HAVING clauses, and creates
* an {@link AggConverter}, then delegates to {@link #createAggImpl}.
* Derived class may override this method to change any of those clauses or
* specify a different {@link AggConverter}.
*
* @param bb Scope within which to resolve identifiers
* @param select Query
* @param orderExprList Additional expressions needed to implement ORDER BY
*/
protected void convertAgg(
Blackboard bb,
SqlSelect select,
List<SqlNode> orderExprList) {
assert bb.root != null : "precondition: child != null";
SqlNodeList groupList = select.getGroup();
SqlNodeList selectList = select.getSelectList();
SqlNode having = select.getHaving();
final AggConverter aggConverter = new AggConverter(bb, select);
createAggImpl(
bb,
aggConverter,
selectList,
groupList,
having,
orderExprList);
}
示例9: gatherOrderExprs
import org.apache.calcite.sql.SqlSelect; //导入依赖的package包/类
/**
* Creates a list of collations required to implement the ORDER BY clause,
* if there is one. Populates <code>extraOrderExprs</code> with any sort
* expressions which are not in the select clause.
*
* @param bb Scope within which to resolve identifiers
* @param select Select clause. Never null, because we invent a
* dummy SELECT if ORDER BY is applied to a set
* operation (UNION etc.)
* @param orderList Order by clause, may be null
* @param extraOrderExprs Sort expressions which are not in the select
* clause (output)
* @param collationList List of collations (output)
*/
protected void gatherOrderExprs(
Blackboard bb,
SqlSelect select,
SqlNodeList orderList,
List<SqlNode> extraOrderExprs,
List<RelFieldCollation> collationList) {
// TODO: add validation rules to SqlValidator also
assert bb.root != null : "precondition: child != null";
assert select != null;
if (orderList == null) {
return;
}
for (SqlNode orderItem : orderList) {
collationList.add(
convertOrderItem(
select,
orderItem,
extraOrderExprs,
RelFieldCollation.Direction.ASCENDING,
RelFieldCollation.NullDirection.UNSPECIFIED));
}
}
示例10: AggConverter
import org.apache.calcite.sql.SqlSelect; //导入依赖的package包/类
/**
* Creates an AggConverter.
*
* <p>The <code>select</code> parameter provides enough context to name
* aggregate calls which are top-level select list items.
*
* @param bb Blackboard
* @param select Query being translated; provides context to give
*/
public AggConverter(Blackboard bb, SqlSelect select) {
this.bb = bb;
this.aggregatingSelectScope =
(AggregatingSelectScope) bb.getValidator().getSelectScope(select);
// Collect all expressions used in the select list so that aggregate
// calls can be named correctly.
final SqlNodeList selectList = select.getSelectList();
for (int i = 0; i < selectList.size(); i++) {
SqlNode selectItem = selectList.get(i);
String name = null;
if (SqlUtil.isCallTo(
selectItem,
SqlStdOperatorTable.AS)) {
final SqlCall call = (SqlCall) selectItem;
selectItem = call.operand(0);
name = call.operand(1).toString();
}
if (name == null) {
name = validator.deriveAlias(selectItem, i);
}
nameMap.put(selectItem.toString(), name);
}
}
示例11: visit
import org.apache.calcite.sql.SqlSelect; //导入依赖的package包/类
@Override public Void visit(SqlCall call) {
// ignore window aggregates and ranking functions (associated with OVER operator)
if (call.getOperator().getKind() == SqlKind.OVER) {
return null;
}
if (call.getOperator().isAggregator()) {
list.add(call);
return null;
}
// Don't traverse into sub-queries, even if they contain aggregate
// functions.
if (call instanceof SqlSelect) {
return null;
}
return call.getOperator().acceptCall(this, call);
}
示例12: renameColumns
import org.apache.calcite.sql.SqlSelect; //导入依赖的package包/类
/** Wraps a query to rename its columns. Used by CREATE VIEW and CREATE
* MATERIALIZED VIEW. */
static SqlNode renameColumns(SqlNodeList columnList, SqlNode query) {
if (columnList == null) {
return query;
}
final SqlParserPos p = query.getParserPosition();
final SqlNodeList selectList =
new SqlNodeList(ImmutableList.<SqlNode>of(SqlIdentifier.star(p)), p);
final SqlCall from =
SqlStdOperatorTable.AS.createCall(p,
ImmutableList.<SqlNode>builder()
.add(query)
.add(new SqlIdentifier("_", p))
.addAll(columnList)
.build());
return new SqlSelect(p, null, selectList, from, null, null, null, null,
null, null, null);
}
示例13: hasNestedAggregations
import org.apache.calcite.sql.SqlSelect; //导入依赖的package包/类
private boolean hasNestedAggregations(LogicalAggregate rel) {
List<AggregateCall> aggCallList = rel.getAggCallList();
HashSet<Integer> aggregatesArgs = new HashSet<>();
for (AggregateCall aggregateCall: aggCallList) {
aggregatesArgs.addAll(aggregateCall.getArgList());
}
for (Integer aggregatesArg : aggregatesArgs) {
SqlNode selectNode = ((SqlSelect) node).getSelectList().get(aggregatesArg);
if (!(selectNode instanceof SqlBasicCall)) {
continue;
}
for (SqlNode operand : ((SqlBasicCall) selectNode).getOperands()) {
if (operand instanceof SqlCall) {
final SqlOperator operator = ((SqlCall) operand).getOperator();
if (operator instanceof SqlAggFunction) {
return true;
}
}
}
}
return false;
}
示例14: gatherOrderExprs
import org.apache.calcite.sql.SqlSelect; //导入依赖的package包/类
/**
* Creates a list of collations required to implement the ORDER BY clause,
* if there is one. Populates <code>extraOrderExprs</code> with any sort
* expressions which are not in the select clause.
*
* @param bb Scope within which to resolve identifiers
* @param select Select clause. Never null, because we invent a
* dummy SELECT if ORDER BY is applied to a set
* operation (UNION etc.)
* @param orderList Order by clause, may be null
* @param extraOrderExprs Sort expressions which are not in the select
* clause (output)
* @param collationList List of collations (output)
*/
protected void gatherOrderExprs(
Blackboard bb,
SqlSelect select,
SqlNodeList orderList,
List<SqlNode> extraOrderExprs,
List<RelFieldCollation> collationList) {
// TODO: add validation rules to SqlValidator also
assert bb.root != null : "precondition: child != null";
assert select != null;
if (orderList == null) {
return;
}
for (SqlNode orderItem : orderList) {
collationList.add(
convertOrderItem(select, orderItem, extraOrderExprs,
RelFieldCollation.Direction.ASCENDING,
RelFieldCollation.NullDirection.UNSPECIFIED));
}
}
示例15: expandStar
import org.apache.calcite.sql.SqlSelect; //导入依赖的package包/类
public SqlNodeList expandStar(
SqlNodeList selectList,
SqlSelect select,
boolean includeSystemVars) {
final List<SqlNode> list = new ArrayList<>();
final List<Map.Entry<String, RelDataType>> types = new ArrayList<>();
for (int i = 0; i < selectList.size(); i++) {
final SqlNode selectItem = selectList.get(i);
final RelDataType originalType = getValidatedNodeTypeIfKnown(selectItem);
expandSelectItem(
selectItem,
select,
Util.first(originalType, unknownType),
list,
catalogReader.nameMatcher().isCaseSensitive()
? new LinkedHashSet<String>()
: new TreeSet<>(String.CASE_INSENSITIVE_ORDER),
types,
includeSystemVars);
}
getRawSelectScope(select).setExpandedSelectList(list);
return new SqlNodeList(list, SqlParserPos.ZERO);
}