use of org.hsqldb_voltpatches.lib.OrderedHashSet in project voltdb by VoltDB.
the class ParserRoutine method compileSetStatement.
/**
* Creates SET Statement for PSM from this parse context.
*/
StatementSimple compileSetStatement(RangeVariable[] rangeVars) {
read();
OrderedHashSet colNames = new OrderedHashSet();
HsqlArrayList exprList = new HsqlArrayList();
readSetClauseList(rangeVars, colNames, exprList);
if (exprList.size() > 1) {
throw Error.error(ErrorCode.X_42602);
}
Expression expression = (Expression) exprList.get(0);
if (expression.getDegree() != colNames.size()) {
// throw Error.error(ErrorCode.X_42546);
}
int[] indexes = new int[colNames.size()];
ColumnSchema[] variables = new ColumnSchema[colNames.size()];
setVariables(rangeVars, colNames, indexes, variables);
HsqlList unresolved = expression.resolveColumnReferences(rangeVars, rangeVars.length, null, false);
unresolved = Expression.resolveColumnSet(rangeVars, unresolved, null);
ExpressionColumn.checkColumnsResolved(unresolved);
expression.resolveTypes(session, null);
StatementSimple cs = new StatementSimple(StatementTypes.ASSIGNMENT, variables, expression, indexes);
return cs;
}
use of org.hsqldb_voltpatches.lib.OrderedHashSet in project voltdb by VoltDB.
the class ParserDQL method readColumnNames.
HsqlName[] readColumnNames(HsqlName tableName) {
BitMap quotedFlags = new BitMap(32);
OrderedHashSet set = readColumnNames(quotedFlags, false);
HsqlName[] colList = new HsqlName[set.size()];
for (int i = 0; i < colList.length; i++) {
String name = (String) set.get(i);
boolean quoted = quotedFlags.isSet(i);
colList[i] = database.nameManager.newHsqlName(tableName.schema, name, quoted, SchemaObject.COLUMN, tableName);
}
return colList;
}
use of org.hsqldb_voltpatches.lib.OrderedHashSet in project voltdb by VoltDB.
the class ParserDQL method readTableOrSubquery.
/**
* Creates a RangeVariable from the parse context. <p>
*/
protected RangeVariable readTableOrSubquery() {
Table table = null;
SimpleName alias = null;
OrderedHashSet columnList = null;
BitMap columnNameQuoted = null;
SimpleName[] columnNameList = null;
if (token.tokenType == Tokens.OPENBRACKET) {
Expression e = XreadTableSubqueryOrJoinedTable();
table = e.subQuery.getTable();
if (table instanceof TableDerived) {
((TableDerived) table).dataExpression = e;
}
} else {
table = readTableName();
if (table.isView()) {
SubQuery sq = getViewSubquery((View) table);
// sq.queryExpression = ((View) table).queryExpression;
table = sq.getTable();
}
}
boolean hasAs = false;
if (token.tokenType == Tokens.AS) {
read();
checkIsNonCoreReservedIdentifier();
hasAs = true;
}
if (isNonCoreReservedIdentifier()) {
boolean limit = token.tokenType == Tokens.LIMIT || token.tokenType == Tokens.OFFSET;
int position = getPosition();
alias = HsqlNameManager.getSimpleName(token.tokenString, isDelimitedIdentifier());
read();
if (token.tokenType == Tokens.OPENBRACKET) {
columnNameQuoted = new BitMap(32);
columnList = readColumnNames(columnNameQuoted, false);
} else if (!hasAs && limit) {
if (token.tokenType == Tokens.QUESTION || token.tokenType == Tokens.X_VALUE) {
alias = null;
rewind(position);
}
}
}
if (columnList != null) {
if (table.getColumnCount() != columnList.size()) {
throw Error.error(ErrorCode.X_42593);
}
columnNameList = new SimpleName[columnList.size()];
for (int i = 0; i < columnList.size(); i++) {
SimpleName name = HsqlNameManager.getSimpleName((String) columnList.get(i), columnNameQuoted.isSet(i));
columnNameList[i] = name;
}
}
RangeVariable range = new RangeVariable(table, alias, columnList, columnNameList, compileContext);
return range;
}
use of org.hsqldb_voltpatches.lib.OrderedHashSet in project voltdb by VoltDB.
the class QuerySpecification method resolveExpressionTypes.
/**
* Sets the types of all the expressions used in this SELECT list.
*/
public void resolveExpressionTypes(Session session) {
for (int i = 0; i < indexStartAggregates; i++) {
Expression e = exprColumns[i];
e.resolveTypes(session, null);
if (e.getType() == OpTypes.ROW) {
throw Error.error(ErrorCode.X_42564);
}
}
for (int i = 0, len = rangeVariables.length; i < len; i++) {
Expression e = rangeVariables[i].nonIndexJoinCondition;
if (e != null) {
e.resolveTypes(session, null);
if (e.getDataType() != Type.SQL_BOOLEAN) {
throw Error.error(ErrorCode.X_42568);
}
}
}
if (queryCondition != null) {
queryCondition.resolveTypes(session, null);
if (queryCondition.getDataType() != Type.SQL_BOOLEAN) {
throw Error.error(ErrorCode.X_42568);
}
if (queryCondition.opType == OpTypes.VALUE) {
if (!((boolean) queryCondition.valueData)) {
// WHERE false => LIMIT 0
SortAndSlice sortAndSlice = new SortAndSlice();
ExpressionValue limit0 = new ExpressionValue(ValuePool.INTEGER_0, Type.SQL_INTEGER);
ExpressionValue offset = new ExpressionValue(ValuePool.INTEGER_0, Type.SQL_INTEGER);
sortAndSlice.addLimitCondition(new ExpressionOp(OpTypes.LIMIT, offset, limit0));
addSortAndSlice(sortAndSlice);
}
// Leave out the original WHERE condition no matter it is WHERE true or WHERE false.
queryCondition = null;
} else {
// A VoltDB extension to guard against abuse of aggregates in subqueries.
// Make sure no aggregates in WHERE clause
tempSet.clear();
Expression.collectAllExpressions(tempSet, queryCondition, Expression.aggregateFunctionSet, Expression.subqueryExpressionSet);
if (!tempSet.isEmpty()) {
// two error messages for two different unsupported cases.
if (!isTopLevel) {
HsqlList columnSet = new OrderedHashSet();
Iterator aggIt = tempSet.iterator();
while (aggIt.hasNext()) {
Expression nextAggr = (Expression) aggIt.next();
Expression.collectAllExpressions(columnSet, nextAggr, Expression.columnExpressionSet, Expression.emptyExpressionSet);
}
Iterator columnIt = columnSet.iterator();
while (columnIt.hasNext()) {
Expression nextColumn = (Expression) columnIt.next();
assert (nextColumn instanceof ExpressionColumn);
ExpressionColumn nextColumnEx = (ExpressionColumn) nextColumn;
String tableName = nextColumnEx.rangeVariable.rangeTable.tableName.name;
String tableAlias = (nextColumnEx.rangeVariable.tableAlias != null) ? nextColumnEx.rangeVariable.tableAlias.name : null;
boolean resolved = false;
for (RangeVariable rv : rangeVariables) {
if (rv.rangeTable.tableName.name.equals(tableName)) {
if (rv.tableAlias == null && tableAlias == null) {
resolved = true;
} else if (rv.tableAlias != null && tableAlias != null) {
resolved = tableAlias.equals(rv.tableAlias.name);
}
}
}
if (!resolved) {
throw Error.error(ErrorCode.X_47001);
}
}
}
// with local columns
throw Error.error(ErrorCode.X_47000);
}
// End of VoltDB extension
}
}
if (havingCondition != null) {
havingCondition.resolveTypes(session, null);
if (havingCondition.getDataType() != Type.SQL_BOOLEAN) {
throw Error.error(ErrorCode.X_42568);
}
}
}
use of org.hsqldb_voltpatches.lib.OrderedHashSet in project voltdb by VoltDB.
the class QueryExpression method resolveReferences.
public void resolveReferences(Session session) {
leftQueryExpression.resolveReferences(session);
rightQueryExpression.resolveReferences(session);
addUnresolvedExpressions(leftQueryExpression.unresolvedExpressions);
addUnresolvedExpressions(rightQueryExpression.unresolvedExpressions);
if (!unionCorresponding) {
columnCount = leftQueryExpression.getColumnCount();
int rightCount = rightQueryExpression.getColumnCount();
if (columnCount != rightCount) {
throw Error.error(ErrorCode.X_42594);
}
unionColumnTypes = new Type[columnCount];
leftQueryExpression.unionColumnMap = rightQueryExpression.unionColumnMap = new int[columnCount];
ArrayUtil.fillSequence(leftQueryExpression.unionColumnMap);
resolveColumnRefernecesInUnionOrderBy();
return;
}
String[] leftNames = leftQueryExpression.getColumnNames();
String[] rightNames = rightQueryExpression.getColumnNames();
if (unionCorrespondingColumns == null) {
unionCorrespondingColumns = new OrderedHashSet();
OrderedIntHashSet leftColumns = new OrderedIntHashSet();
OrderedIntHashSet rightColumns = new OrderedIntHashSet();
for (int i = 0; i < leftNames.length; i++) {
String name = leftNames[i];
int index = ArrayUtil.find(rightNames, name);
if (name.length() > 0 && index != -1) {
leftColumns.add(i);
rightColumns.add(index);
unionCorrespondingColumns.add(name);
}
}
if (unionCorrespondingColumns.isEmpty()) {
throw Error.error(ErrorCode.X_42579);
}
leftQueryExpression.unionColumnMap = leftColumns.toArray();
rightQueryExpression.unionColumnMap = rightColumns.toArray();
} else {
leftQueryExpression.unionColumnMap = new int[unionCorrespondingColumns.size()];
rightQueryExpression.unionColumnMap = new int[unionCorrespondingColumns.size()];
for (int i = 0; i < unionCorrespondingColumns.size(); i++) {
String name = (String) unionCorrespondingColumns.get(i);
int index = ArrayUtil.find(leftNames, name);
if (index == -1) {
throw Error.error(ErrorCode.X_42579);
}
leftQueryExpression.unionColumnMap[i] = index;
index = ArrayUtil.find(rightNames, name);
if (index == -1) {
throw Error.error(ErrorCode.X_42579);
}
rightQueryExpression.unionColumnMap[i] = index;
}
}
columnCount = unionCorrespondingColumns.size();
unionColumnTypes = new Type[columnCount];
resolveColumnRefernecesInUnionOrderBy();
}
Aggregations