use of org.hsqldb_voltpatches.lib.OrderedHashSet in project voltdb by VoltDB.
the class ParserDQL method XreadTableReference.
void XreadTableReference(QuerySpecification select) {
boolean natural = false;
RangeVariable range = readTableOrSubquery();
select.addRangeVariable(range);
while (true) {
int type = token.tokenType;
boolean left = false;
boolean right = false;
boolean end = false;
type = token.tokenType;
switch(token.tokenType) {
case Tokens.INNER:
read();
readThis(Tokens.JOIN);
break;
case Tokens.CROSS:
if (natural) {
throw unexpectedToken();
}
read();
readThis(Tokens.JOIN);
break;
case Tokens.UNION:
if (natural) {
throw unexpectedToken();
}
int position = getPosition();
read();
if (token.tokenType == Tokens.JOIN) {
read();
break;
} else {
rewind(position);
end = true;
break;
}
case Tokens.NATURAL:
if (natural) {
throw unexpectedToken();
}
read();
natural = true;
continue;
case Tokens.LEFT:
read();
readIfThis(Tokens.OUTER);
readThis(Tokens.JOIN);
left = true;
break;
case Tokens.RIGHT:
read();
readIfThis(Tokens.OUTER);
readThis(Tokens.JOIN);
right = true;
break;
case Tokens.FULL:
read();
readIfThis(Tokens.OUTER);
readThis(Tokens.JOIN);
left = true;
right = true;
break;
case Tokens.JOIN:
read();
type = Tokens.INNER;
break;
case Tokens.COMMA:
if (natural) {
throw unexpectedToken();
}
read();
type = Tokens.CROSS;
break;
default:
if (natural) {
throw unexpectedToken();
}
end = true;
break;
}
if (end) {
break;
}
range = readTableOrSubquery();
Expression condition = null;
switch(type) {
case Tokens.CROSS:
select.addRangeVariable(range);
break;
case Tokens.UNION:
select.addRangeVariable(range);
condition = Expression.EXPR_FALSE;
range.setJoinType(true, true);
break;
case Tokens.LEFT:
case Tokens.RIGHT:
case Tokens.INNER:
case Tokens.FULL:
{
if (natural) {
OrderedHashSet columns = range.getUniqueColumnNameSet();
condition = select.getEquiJoinExpressions(columns, range, false);
select.addRangeVariable(range);
} else if (token.tokenType == Tokens.USING) {
read();
OrderedHashSet columns = new OrderedHashSet();
readThis(Tokens.OPENBRACKET);
readSimpleColumnNames(columns, range);
readThis(Tokens.CLOSEBRACKET);
condition = select.getEquiJoinExpressions(columns, range, true);
select.addRangeVariable(range);
} else if (token.tokenType == Tokens.ON) {
read();
condition = XreadBooleanValueExpression();
select.addRangeVariable(range);
// must ensure references are limited to the current table
// select.finaliseRangeVariables();
// select.resolveColumnReferencesAndAllocate(condition);
} else {
throw Error.error(ErrorCode.X_42581);
}
range.setJoinType(left, right);
break;
}
}
range.addJoinCondition(condition);
natural = false;
}
}
use of org.hsqldb_voltpatches.lib.OrderedHashSet in project voltdb by VoltDB.
the class ParserDQL method readColumnNameList.
OrderedHashSet readColumnNameList(BitMap quotedFlags, boolean readAscDesc) {
int i = 0;
OrderedHashSet set = new OrderedHashSet();
while (true) {
if (session.isProcessingScript) {
// SEE: ENG-912
if (!isSimpleName(strictSQLNames)) {
/* disable 1 line ...
if (!isSimpleName()) {
... disabled 1 line */
// End of VoltDB extension
token.isDelimitedIdentifier = true;
}
} else {
// A VoltDB extension to make reserved words more consistent.
checkIsSimpleName(strictSQLNames);
/* disable 1 line ...
checkIsSimpleName();
... disabled 1 line */
// End of VoltDB extension
}
if (!set.add(token.tokenString)) {
throw Error.error(ErrorCode.X_42577, token.tokenString);
}
if (quotedFlags != null && isDelimitedIdentifier()) {
quotedFlags.set(i);
}
read();
i++;
if (readAscDesc) {
if (token.tokenType == Tokens.ASC || token.tokenType == Tokens.DESC) {
read();
}
}
if (readIfThis(Tokens.COMMA)) {
continue;
}
break;
}
return set;
}
use of org.hsqldb_voltpatches.lib.OrderedHashSet in project voltdb by VoltDB.
the class ParserDML method compileMergeStatement.
/**
* Retrieves a MERGE Statement from this parse context.
*/
StatementDMQL compileMergeStatement(RangeVariable[] outerRanges) {
boolean[] insertColumnCheckList;
int[] insertColumnMap = null;
int[] updateColumnMap = null;
int[] baseUpdateColumnMap;
Table table;
RangeVariable targetRange;
RangeVariable sourceRange;
Expression mergeCondition;
HsqlArrayList updateList = new HsqlArrayList();
Expression[] updateExpressions = null;
HsqlArrayList insertList = new HsqlArrayList();
Expression insertExpression = null;
read();
readThis(Tokens.INTO);
targetRange = readSimpleRangeVariable(StatementTypes.MERGE);
table = targetRange.rangeTable;
readThis(Tokens.USING);
sourceRange = readTableOrSubquery();
// parse ON search conditions
readThis(Tokens.ON);
mergeCondition = XreadBooleanValueExpression();
if (mergeCondition.getDataType() != Type.SQL_BOOLEAN) {
throw Error.error(ErrorCode.X_42568);
}
RangeVariable[] fullRangeVars = new RangeVariable[] { sourceRange, targetRange };
RangeVariable[] sourceRangeVars = new RangeVariable[] { sourceRange };
RangeVariable[] targetRangeVars = new RangeVariable[] { targetRange };
// parse WHEN clause(s) and convert lists to arrays
insertColumnMap = table.getColumnMap();
insertColumnCheckList = table.getNewColumnCheckList();
OrderedHashSet updateColNames = new OrderedHashSet();
OrderedHashSet insertColNames = new OrderedHashSet();
readMergeWhen(insertColNames, updateColNames, insertList, updateList, targetRangeVars, sourceRange);
if (insertList.size() > 0) {
int colCount = insertColNames.size();
if (colCount != 0) {
insertColumnMap = table.getColumnIndexes(insertColNames);
insertColumnCheckList = table.getColumnCheckList(insertColumnMap);
}
insertExpression = (Expression) insertList.get(0);
setParameterTypes(insertExpression, table, insertColumnMap);
}
if (updateList.size() > 0) {
updateExpressions = new Expression[updateList.size()];
updateList.toArray(updateExpressions);
updateColumnMap = table.getColumnIndexes(updateColNames);
}
if (updateExpressions != null) {
Table baseTable = table.getBaseTable();
baseUpdateColumnMap = updateColumnMap;
if (table != baseTable) {
baseUpdateColumnMap = new int[updateColumnMap.length];
ArrayUtil.projectRow(table.getBaseTableColumnMap(), updateColumnMap, baseUpdateColumnMap);
}
resolveUpdateExpressions(table, sourceRangeVars, updateColumnMap, updateExpressions, outerRanges);
}
HsqlList unresolved = null;
unresolved = mergeCondition.resolveColumnReferences(fullRangeVars, null);
ExpressionColumn.checkColumnsResolved(unresolved);
mergeCondition.resolveTypes(session, null);
if (mergeCondition.isParam()) {
mergeCondition.dataType = Type.SQL_BOOLEAN;
}
if (mergeCondition.getDataType() != Type.SQL_BOOLEAN) {
throw Error.error(ErrorCode.X_42568);
}
RangeVariableResolver resolver = new RangeVariableResolver(fullRangeVars, mergeCondition, compileContext);
resolver.processConditions();
fullRangeVars = resolver.rangeVariables;
if (insertExpression != null) {
unresolved = insertExpression.resolveColumnReferences(sourceRangeVars, unresolved);
ExpressionColumn.checkColumnsResolved(unresolved);
insertExpression.resolveTypes(session, null);
}
StatementDMQL cs = new StatementDML(session, fullRangeVars, insertColumnMap, updateColumnMap, insertColumnCheckList, mergeCondition, insertExpression, updateExpressions, compileContext);
return cs;
}
use of org.hsqldb_voltpatches.lib.OrderedHashSet in project voltdb by VoltDB.
the class ParserDDL method compileTriggerSetStatement.
/**
* Creates SET Statement for a trigger row from this parse context.
*/
StatementDMQL compileTriggerSetStatement(Table table, RangeVariable[] rangeVars) {
read();
Expression[] updateExpressions;
int[] columnMap;
OrderedHashSet colNames = new OrderedHashSet();
HsqlArrayList exprList = new HsqlArrayList();
RangeVariable[] targetRangeVars = new RangeVariable[] { rangeVars[TriggerDef.NEW_ROW] };
readSetClauseList(targetRangeVars, colNames, exprList);
columnMap = table.getColumnIndexes(colNames);
updateExpressions = new Expression[exprList.size()];
exprList.toArray(updateExpressions);
resolveUpdateExpressions(table, rangeVars, columnMap, updateExpressions, RangeVariable.emptyArray);
StatementDMQL cs = new StatementDML(session, table, rangeVars, columnMap, updateExpressions, compileContext);
return cs;
}
use of org.hsqldb_voltpatches.lib.OrderedHashSet in project voltdb by VoltDB.
the class ParserDDL method compileAlterTableAddUniqueConstraint.
// A VoltDB extension to support the assume unique attribute
Statement compileAlterTableAddUniqueConstraint(Table table, HsqlName name, boolean assumeUnique) {
if (name == null) {
name = database.nameManager.newAutoName("CT", table.getSchemaName(), table.getName(), SchemaObject.CONSTRAINT);
}
// A VoltDB extension to support indexed expressions.
java.util.List<Expression> indexExprs = XreadExpressions(null);
OrderedHashSet set = getSimpleColumnNames(indexExprs);
int[] cols = getColumnList(set, table);
if ((indexExprs != null) && (cols == null)) {
// Not just indexing columns.
// The meaning of cols shifts here to be
// the set of unique base columns for the indexed expressions.
set = getBaseColumnNames(indexExprs);
cols = getColumnList(set, table);
}
/* disable 1 line ...
int[] cols = this.readColumnList(table, false);
... disabled 1 line */
// End of VoltDB extension
String sql = getLastPart();
// A VoltDB extension to support the assume unique attribute and indexed expressions
Object[] args = new Object[] { cols, name, indexExprs, Boolean.valueOf(assumeUnique) };
return new StatementSchema(sql, StatementTypes.ALTER_TABLE, args, null, table.getName());
}
Aggregations