/** Returns whether the prefix is sorted. */ private boolean hasSortedPrefix(SelectScope scope, SqlNodeList orderList) { return isSortCompatible(scope, orderList.get(0), false); }
SqlNode selectItem = selectItems.get(i); if (selectItem instanceof SqlSelect) { handleScalarSubQuery(
SqlNodeList list = (SqlNodeList) node; for (int i = 0, count = list.size(); i < count; i++) { SqlNode operand = list.get(i); newOperand = performUnconditionalRewrites( SqlNode sqlNode = orderList.get(i); SqlNodeList selectList2 = getInnerSelect(node).getSelectList(); for (Ord<SqlNode> sel : Ord.zip(selectList2)) {
public static SqlNode getOnlySelectNode(String sql) { SqlNodeList selectList = null; try { selectList = ((SqlSelect) CalciteParser.parse(sql)).getSelectList(); } catch (SqlParseException e) { throw new RuntimeException( "Failed to parse expression \'" + sql + "\', please make sure the expression is valid", e); } Preconditions.checkArgument(selectList.size() == 1, "Expression is invalid because size of select list exceeds one"); return selectList.get(0); }
@Override public SqlNode visit(SqlNodeList nodeList) { for (int i = 0; i < nodeList.size(); i++) { SqlNode node = nodeList.get(i); if (node instanceof SqlWithItem) { SqlWithItem item = (SqlWithItem) node; item.query.accept(this); } } return null; }
SqlInsert insert = (SqlInsert) query; if (insert.getTargetColumnList() != null) { return insert.getTargetColumnList().get(ordinal); } else { return getNthExpr( SqlUpdate update = (SqlUpdate) query; if (update.getTargetColumnList() != null) { return update.getTargetColumnList().get(ordinal); } else if (update.getSourceExpressionList() != null) { return update.getSourceExpressionList().get(ordinal); } else { return getNthExpr( SqlSelect select = (SqlSelect) query; if (select.getSelectList().size() == sourceCount) { return select.getSelectList().get(ordinal); } else { return query; // give up
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().createSet(), types, includeSystemVars); } getRawSelectScope(select).setExpandedSelectList(list); return new SqlNodeList(list, SqlParserPos.ZERO); }
/** * Returns the <code>ordinal</code>th item in the select list. */ private SqlNode nthSelectItem(int ordinal, final SqlParserPos pos) { // TODO: Don't expand the list every time. Maybe keep an expanded // version of each expression -- select lists and identifiers -- in // the validator. SqlNodeList expandedSelectList = expandStar( select.getSelectList(), select, false); SqlNode expr = expandedSelectList.get(ordinal); expr = stripAs(expr); if (expr instanceof SqlIdentifier) { expr = getScope().fullyQualify((SqlIdentifier) expr).identifier; } // Create a copy of the expression with the position of the order // item. return expr.clone(pos); }
return SqlUtil.stripAs(select.getSelectList().get(ordinal));
e = ExpressionCommaList(s, ExprContext.ACCEPT_SUB_QUERY); if (((SqlNodeList) e).size() == 1) { e = ((SqlNodeList) e).get(0);
SqlNodeList list = (SqlNodeList) node; for (int i = 0, count = list.size(); i < count; i++) { SqlNode listNode = list.get(i); if (listNode.getKind().belongsTo(SqlKind.QUERY)) { listNode =
if (!hasSortedPrefix(scope, orderList)) { if (fail) { throw newValidationError(orderList.get(0), Static.RESOURCE.streamMustOrderByMonotonic()); } else {
RelDataType fromType = unknownType; if (selectItems.size() == 1) { final SqlNode selectItem = selectItems.get(0); if (selectItem instanceof SqlIdentifier) { SqlIdentifier id = (SqlIdentifier) selectItem;
SqlNode item = nodeList.get(0); if (item.isA(SqlKind.QUERY)) { list.add(item);
e = ExpressionCommaList(s, ExprContext.ACCEPT_SUB_QUERY); if (((SqlNodeList) e).size() == 1) { e = ((SqlNodeList) e).get(0);
SqlNode item = nodeList.get(0); if (item.isA(SqlKind.QUERY)) { list.add(item);