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; }
List<Map.Entry<String, RelDataType>> fieldList) { if (1 != selectItem.getSelectList().size()) { throw newValidationError(selectItem, RESOURCE.onlyScalarSubQueryAllowed());
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); }
if (query instanceof SqlUpdate) { int nUpdateColumns = ((SqlUpdate) query).getTargetColumnList().size(); assert sourceFields.size() >= nUpdateColumns; iAdjusted -= sourceFields.size() - nUpdateColumns;
public void validateWithItem(SqlWithItem withItem) { if (withItem.columnList != null) { final RelDataType rowType = getValidatedNodeType(withItem.query); final int fieldCount = rowType.getFieldCount(); if (withItem.columnList.size() != fieldCount) { throw newValidationError(withItem.columnList, RESOURCE.columnCountMismatch()); } SqlValidatorUtil.checkIdentifierListForDuplicates( withItem.columnList.getList(), validationErrorFunction); } else { // Luckily, field names have not been make unique yet. final List<String> fieldNames = getValidatedNodeType(withItem.query).getFieldNames(); final int i = Util.firstDuplicate(fieldNames); if (i >= 0) { throw newValidationError(withItem.query, RESOURCE.duplicateColumnAndNoColumnList(fieldNames.get(i))); } } }
final List<Map.Entry<String, RelDataType>> fieldList = new ArrayList<>(); for (int i = 0; i < selectItems.size(); i++) { SqlNode selectItem = selectItems.get(i); if (selectItem instanceof SqlSelect) {
final int intValue = literal.intValue(false); if (intValue >= 0) { if (intValue < 1 || intValue > select.getSelectList().size()) { throw validator.newValidationError(literal, RESOURCE.orderByOrdinalOutOfRange());
&& ((SqlNodeList) groupItem).size() == 0) { continue;
whenSpan.add(this); e = ExpressionCommaList(s, ExprContext.ACCEPT_SUB_QUERY); if (((SqlNodeList) e).size() == 1) { e = ((SqlNodeList) e).get(0);
SqlNodeList nodeList = (SqlNodeList) node; if (inferredType.isStruct()) { if (inferredType.getFieldCount() != nodeList.size()) {
for (int i = 0, count = list.size(); i < count; i++) { SqlNode listNode = list.get(i); if (listNode.getKind().belongsTo(SqlKind.QUERY)) {
if (orderList != null && orderList.size() > 0) { switch (modality) { case STREAM:
if (select.getSelectList().size() == sourceCount) { return select.getSelectList().get(ordinal); } else {
if (selectItems.size() == 1) { final SqlNode selectItem = selectItems.get(0); if (selectItem instanceof SqlIdentifier) {
whenSpan.add(this); e = ExpressionCommaList(s, ExprContext.ACCEPT_SUB_QUERY); if (((SqlNodeList) e).size() == 1) { e = ((SqlNodeList) e).get(0);