org.apache.calcite.sql.SqlOrderBy Java Examples

The following examples show how to use org.apache.calcite.sql.SqlOrderBy. 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: DrillSqlWorker.java    From Bats with Apache License 2.0 5 votes vote down vote up
private static SqlNode wrapWithAutoLimit(SqlNode sqlNode, int queryMaxRows) {
  SqlNumericLiteral autoLimitLiteral = SqlLiteral.createExactNumeric(String.valueOf(queryMaxRows), SqlParserPos.ZERO);
  if (sqlNode.getKind() == SqlKind.ORDER_BY) {
    SqlOrderBy orderBy = (SqlOrderBy) sqlNode;
    return new SqlOrderBy(orderBy.getParserPosition(), orderBy.query, orderBy.orderList, orderBy.offset, autoLimitLiteral);
  }
  return new SqlOrderBy(SqlParserPos.ZERO, sqlNode, SqlNodeList.EMPTY, null, autoLimitLiteral);
}
 
Example #2
Source File: SqlValidatorImpl.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
private SqlSelect getInnerSelect(SqlNode node) {
	for (;;) {
		if (node instanceof SqlSelect) {
			return (SqlSelect) node;
		} else if (node instanceof SqlOrderBy) {
			node = ((SqlOrderBy) node).query;
		} else if (node instanceof SqlWith) {
			node = ((SqlWith) node).body;
		} else {
			return null;
		}
	}
}
 
Example #3
Source File: SqlValidatorImpl.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
private List<String> getFieldOrigin(SqlNode sqlQuery, int i) {
	if (sqlQuery instanceof SqlSelect) {
		SqlSelect sqlSelect = (SqlSelect) sqlQuery;
		final SelectScope scope = getRawSelectScope(sqlSelect);
		final List<SqlNode> selectList = scope.getExpandedSelectList();
		final SqlNode selectItem = stripAs(selectList.get(i));
		if (selectItem instanceof SqlIdentifier) {
			final SqlQualified qualified =
				scope.fullyQualify((SqlIdentifier) selectItem);
			SqlValidatorNamespace namespace = qualified.namespace;
			final SqlValidatorTable table = namespace.getTable();
			if (table == null) {
				return null;
			}
			final List<String> origin =
				new ArrayList<>(table.getQualifiedName());
			for (String name : qualified.suffix()) {
				namespace = namespace.lookupChild(name);
				if (namespace == null) {
					return null;
				}
				origin.add(name);
			}
			return origin;
		}
		return null;
	} else if (sqlQuery instanceof SqlOrderBy) {
		return getFieldOrigin(((SqlOrderBy) sqlQuery).query, i);
	} else {
		return null;
	}
}
 
Example #4
Source File: SqlValidatorImpl.java    From flink with Apache License 2.0 5 votes vote down vote up
private SqlSelect getInnerSelect(SqlNode node) {
	for (;;) {
		if (node instanceof SqlSelect) {
			return (SqlSelect) node;
		} else if (node instanceof SqlOrderBy) {
			node = ((SqlOrderBy) node).query;
		} else if (node instanceof SqlWith) {
			node = ((SqlWith) node).body;
		} else {
			return null;
		}
	}
}
 
Example #5
Source File: SqlValidatorImpl.java    From flink with Apache License 2.0 5 votes vote down vote up
private List<String> getFieldOrigin(SqlNode sqlQuery, int i) {
	if (sqlQuery instanceof SqlSelect) {
		SqlSelect sqlSelect = (SqlSelect) sqlQuery;
		final SelectScope scope = getRawSelectScope(sqlSelect);
		final List<SqlNode> selectList = scope.getExpandedSelectList();
		final SqlNode selectItem = stripAs(selectList.get(i));
		if (selectItem instanceof SqlIdentifier) {
			final SqlQualified qualified =
				scope.fullyQualify((SqlIdentifier) selectItem);
			SqlValidatorNamespace namespace = qualified.namespace;
			final SqlValidatorTable table = namespace.getTable();
			if (table == null) {
				return null;
			}
			final List<String> origin =
				new ArrayList<>(table.getQualifiedName());
			for (String name : qualified.suffix()) {
				namespace = namespace.lookupChild(name);
				if (namespace == null) {
					return null;
				}
				origin.add(name);
			}
			return origin;
		}
		return null;
	} else if (sqlQuery instanceof SqlOrderBy) {
		return getFieldOrigin(((SqlOrderBy) sqlQuery).query, i);
	} else {
		return null;
	}
}
 
Example #6
Source File: DrillSqlWorker.java    From Bats with Apache License 2.0 4 votes vote down vote up
private static boolean isAutoLimitShouldBeApplied(SqlNode sqlNode, int queryMaxRows) {
  return (queryMaxRows > 0) && sqlNode.getKind().belongsTo(SqlKind.QUERY)
      && (sqlNode.getKind() != SqlKind.ORDER_BY || isAutoLimitLessThanOrderByFetch((SqlOrderBy) sqlNode, queryMaxRows));
}
 
Example #7
Source File: DrillSqlWorker.java    From Bats with Apache License 2.0 4 votes vote down vote up
private static boolean isAutoLimitLessThanOrderByFetch(SqlOrderBy orderBy, int queryMaxRows) {
  return orderBy.fetch == null || Integer.parseInt(orderBy.fetch.toString()) > queryMaxRows;
}
 
Example #8
Source File: QuerySemantics.java    From dremio-oss with Apache License 2.0 4 votes vote down vote up
private static VirtualDatasetState.Builder extractOrderBy(String sql, SqlNode node, final RelDataType relDataType) {
  SqlOrderBy orderBy = (SqlOrderBy)node;
  return extract(sql, orderBy.query, relDataType);
}