use of org.hsqldb_voltpatches.lib.OrderedHashSet in project voltdb by VoltDB.
the class Constraint method getReferences.
@Override
public OrderedHashSet getReferences() {
switch(constType) {
case Constraint.CHECK:
return schemaObjectNames;
case Constraint.FOREIGN_KEY:
OrderedHashSet set = new OrderedHashSet();
set.add(core.uniqueName);
return set;
}
return null;
}
use of org.hsqldb_voltpatches.lib.OrderedHashSet in project voltdb by VoltDB.
the class RangeVariable method getUniqueColumnNameSet.
public OrderedHashSet getUniqueColumnNameSet() {
OrderedHashSet set = new OrderedHashSet();
if (columnAliases != null) {
set.addAll(columnAliases);
return set;
}
for (int i = 0; i < rangeTable.columnList.size(); i++) {
String name = rangeTable.getColumn(i).getName().name;
boolean added = set.add(name);
if (!added) {
throw Error.error(ErrorCode.X_42578, name);
}
}
return set;
}
use of org.hsqldb_voltpatches.lib.OrderedHashSet in project voltdb by VoltDB.
the class QuerySpecification method getEquiJoinExpressions.
public Expression getEquiJoinExpressions(OrderedHashSet nameSet, RangeVariable rightRange, boolean fullList) {
HashSet set = new HashSet();
Expression result = null;
OrderedHashSet joinColumnNames = new OrderedHashSet();
for (int i = 0; i < rangeVariableList.size(); i++) {
RangeVariable range = (RangeVariable) rangeVariableList.get(i);
HashMappedList columnList = range.rangeTable.columnList;
for (int j = 0; j < columnList.size(); j++) {
ColumnSchema column = (ColumnSchema) columnList.get(j);
String name = range.getColumnAlias(j);
boolean columnInList = nameSet.contains(name);
boolean namedJoin = range.namedJoinColumns != null && range.namedJoinColumns.contains(name);
boolean repeated = !namedJoin && !set.add(name);
if (repeated && (!fullList || columnInList)) {
throw Error.error(ErrorCode.X_42578, name);
}
if (!columnInList) {
continue;
}
joinColumnNames.add(name);
int position = rightRange.rangeTable.getColumnIndex(name);
ColumnSchema rightColumn = rightRange.rangeTable.getColumn(position);
Expression e = new ExpressionLogical(range, column, rightRange, rightColumn);
result = ExpressionLogical.andExpressions(result, e);
ExpressionColumn col = range.getColumnExpression(name);
if (col == null) {
col = new ExpressionColumn(new Expression[] { e.getLeftNode(), e.getRightNode() }, name);
range.addNamedJoinColumnExpression(name, col);
} else {
col.nodes = (Expression[]) ArrayUtil.resizeArray(col.nodes, col.nodes.length + 1);
col.nodes[col.nodes.length - 1] = e.getRightNode();
}
rightRange.addNamedJoinColumnExpression(name, col);
}
}
if (fullList && !joinColumnNames.containsAll(nameSet)) {
throw Error.error(ErrorCode.X_42501);
}
rightRange.addNamedJoinColumns(joinColumnNames);
return result;
}
use of org.hsqldb_voltpatches.lib.OrderedHashSet in project voltdb by VoltDB.
the class QuerySpecification method resolveForGroupBy.
boolean resolveForGroupBy(HsqlList unresolvedSet) {
for (int i = indexLimitVisible; i < indexLimitVisible + groupByColumnCount; i++) {
Expression e = exprColumns[i];
if (e.getType() == OpTypes.COLUMN) {
RangeVariable range = e.getRangeVariable();
int colIndex = e.getColumnIndex();
range.columnsInGroupBy[colIndex] = true;
}
}
for (int i = 0; i < rangeVariables.length; i++) {
RangeVariable range = rangeVariables[i];
range.hasKeyedColumnInGroupBy = range.rangeTable.getUniqueNotNullColumnGroup(range.columnsInGroupBy) != null;
}
OrderedHashSet set = null;
for (int i = 0; i < unresolvedSet.size(); i++) {
Expression e = (Expression) unresolvedSet.get(i);
set = e.getUnkeyedColumns(set);
}
return set == null;
}
use of org.hsqldb_voltpatches.lib.OrderedHashSet in project voltdb by VoltDB.
the class QuerySpecification method resolveGroups.
private void resolveGroups() {
// - 1.9.0 is standard compliant but has more extended support for
// referencing columns
// - check there is no direct aggregate expression in group by
// - check each expression in select list can be
// decomposed into the expressions in group by or any aggregates
// this allows direct function of group by expressions, but
// doesn't allow indirect functions. e.g.
// select 2*abs(cola) , sum(colb) from t group by abs(cola) // ok
// select 2*(cola + 10) , sum(colb) from t group by cola + 10 // ok
// select abs(cola) , sum(colb) from t group by cola // ok
// select 2*cola + 20 , sum(colb) from t group by cola + 10 // not allowed although correct
// select cola , sum(colb) from t group by abs(cola) // not allowed because incorrect
// - group by can introduce invisible, derived columns into the query table
// - check the having expression can be decomposed into
// select list expresions plus group by expressions
// - having cannot introduce additional, derived columns
// - having cannot reference columns not in the select or group by list
// - if there is any aggregate in select list but no group by, no
// non-aggregates is allowed
// - check order by columns
// - if distinct select, order by must be composed of the select list columns
// - if grouped by, then order by should be decomposed into the
// select list plus group by list
// - references to column aliases are allowed only in order by (Standard
// compliance) and take precendence over references to non-alias
// column names.
// - references to table / correlation and column list in correlation
// names are handled according to the Standard
// fredt@users
tempSet.clear();
if (isGrouped) {
for (int i = indexLimitVisible; i < indexLimitVisible + groupByColumnCount; i++) {
Expression.collectAllExpressions(tempSet, exprColumns[i], Expression.aggregateFunctionSet, Expression.subqueryExpressionSet);
if (!tempSet.isEmpty()) {
// The sql is an aggregate function name, extracted
// from the SQL text of the query. But the function
// getSQL is intended to call in a context which
// parameters to the string and then adds a trailing
// parenthesis. So, we add the trailing parenthesis
// here if it's necessary.
String sql = ((Expression) tempSet.get(0)).getSQL();
if (sql.endsWith("(")) {
sql += ")";
}
throw Error.error(ErrorCode.X_42572, sql);
}
}
for (int i = 0; i < indexLimitVisible; i++) {
if (!exprColumns[i].isComposedOf(exprColumns, indexLimitVisible, indexLimitVisible + groupByColumnCount, Expression.subqueryAggregateExpressionSet)) {
tempSet.add(exprColumns[i]);
}
}
for (int i = indexStartOrderBy; i < indexStartAggregates; i++) {
if (!exprColumns[i].isComposedOf(exprColumns, indexLimitVisible, indexLimitVisible + groupByColumnCount, Expression.subqueryAggregateExpressionSet)) {
tempSet.add(exprColumns[i]);
}
}
if (!tempSet.isEmpty() && !resolveForGroupBy(tempSet)) {
throw Error.error(ErrorCode.X_42574, ((Expression) tempSet.get(0)).getSQL());
}
} else if (isAggregated) {
for (int i = 0; i < indexLimitVisible; i++) {
Expression.collectAllExpressions(tempSet, exprColumns[i], Expression.columnExpressionSet, Expression.aggregateFunctionSet);
if (!tempSet.isEmpty()) {
throw Error.error(ErrorCode.X_42574, ((Expression) tempSet.get(0)).getSQL());
}
}
}
tempSet.clear();
if (havingCondition != null) {
if (unresolvedExpressions != null) {
tempSet.addAll(unresolvedExpressions);
}
for (int i = indexLimitVisible; i < indexLimitVisible + groupByColumnCount; i++) {
tempSet.add(exprColumns[i]);
}
if (!havingCondition.isComposedOf(tempSet, Expression.subqueryAggregateExpressionSet)) {
throw Error.error(ErrorCode.X_42573);
}
tempSet.clear();
}
if (isDistinctSelect) {
int orderCount = sortAndSlice.getOrderLength();
for (int i = 0; i < orderCount; i++) {
Expression e = (Expression) sortAndSlice.exprList.get(i);
if (e.queryTableColumnIndex != -1) {
continue;
}
if (!e.isComposedOf(exprColumns, 0, indexLimitVisible, Expression.emptyExpressionSet)) {
throw Error.error(ErrorCode.X_42576);
}
}
}
if (isGrouped) {
int orderCount = sortAndSlice.getOrderLength();
for (int i = 0; i < orderCount; i++) {
Expression e = (Expression) sortAndSlice.exprList.get(i);
if (e.queryTableColumnIndex != -1) {
continue;
}
if (!e.isComposedOf(exprColumns, 0, indexLimitVisible + groupByColumnCount, Expression.emptyExpressionSet)) {
throw Error.error(ErrorCode.X_42576);
}
}
}
simpleLimit = (!isDistinctSelect && !isGrouped && !sortAndSlice.hasOrder());
if (!isAggregated) {
return;
}
OrderedHashSet expressions = new OrderedHashSet();
OrderedHashSet columnExpressions = new OrderedHashSet();
for (int i = indexStartAggregates; i < indexLimitExpressions; i++) {
Expression e = exprColumns[i];
Expression c = new ExpressionColumn(e, i, resultRangePosition);
expressions.add(e);
columnExpressions.add(c);
}
for (int i = 0; i < indexStartOrderBy; i++) {
if (exprColumns[i].isAggregate) {
continue;
}
Expression e = exprColumns[i];
if (expressions.add(e)) {
Expression c = new ExpressionColumn(e, i, resultRangePosition);
columnExpressions.add(c);
}
}
// order by with aggregate
int orderCount = sortAndSlice.getOrderLength();
for (int i = 0; i < orderCount; i++) {
Expression e = (Expression) sortAndSlice.exprList.get(i);
if (e.getLeftNode().isAggregate) {
e.isAggregate = true;
}
}
for (int i = indexStartOrderBy; i < indexStartAggregates; i++) {
if (exprColumns[i].getLeftNode().isAggregate) {
exprColumns[i].isAggregate = true;
}
}
for (int i = 0; i < indexStartAggregates; i++) {
Expression e = exprColumns[i];
if (!e.isAggregate) {
continue;
}
aggregateCheck[i] = true;
e.convertToSimpleColumn(expressions, columnExpressions);
}
for (int i = 0; i < aggregateSet.size(); i++) {
Expression e = (Expression) aggregateSet.get(i);
e.convertToSimpleColumn(expressions, columnExpressions);
}
if (resolvedSubqueryExpressions != null) {
for (int i = 0; i < resolvedSubqueryExpressions.size(); i++) {
Expression e = (Expression) resolvedSubqueryExpressions.get(i);
e.convertToSimpleColumn(expressions, columnExpressions);
}
}
}
Aggregations