use of org.hsqldb_voltpatches.HsqlNameManager.HsqlName in project voltdb by VoltDB.
the class ParserDDL method compileCreateIndex.
// A VoltDB extension to support indexed expressions and the assume unique attribute
StatementSchema compileCreateIndex(boolean unique, boolean assumeUnique) {
/* disable 1 line ...
StatementSchema compileCreateIndex(boolean unique) {
... disabled 1 line */
// End of VoltDB extension
Table table;
HsqlName indexHsqlName;
read();
indexHsqlName = readNewSchemaObjectName(SchemaObject.INDEX);
readThis(Tokens.ON);
table = readTableName();
HsqlName tableSchema = table.getSchemaName();
indexHsqlName.setSchemaIfNull(tableSchema);
indexHsqlName.parent = table.getName();
if (indexHsqlName.schema != tableSchema) {
throw Error.error(ErrorCode.X_42505);
}
indexHsqlName.schema = table.getSchemaName();
// A VoltDB extension to support indexed expressions and the assume unique attribute
java.util.List<Boolean> ascDesc = new java.util.ArrayList<Boolean>();
// A VoltDB extension to "readColumnList(table, true)" to support indexed expressions.
java.util.List<Expression> indexExprs = XreadExpressions(ascDesc);
OrderedHashSet set = getSimpleColumnNames(indexExprs);
int[] indexColumns = null;
if (set == null) {
// A VoltDB extension to support indexed expressions.
// Not just indexing columns.
// The meaning of set and indexColumns shifts here to be
// the set of unique base columns for the indexed expressions.
set = getBaseColumnNames(indexExprs);
} else {
// Just indexing columns -- by-pass extended support for generalized index expressions.
indexExprs = null;
}
// A VoltDB extension to support partial index
Expression predicate = null;
if (readIfThis(Tokens.WHERE)) {
predicate = XreadBooleanValueExpression();
}
indexColumns = getColumnList(set, table);
String sql = getLastPart();
Object[] args = new Object[] { table, indexColumns, indexHsqlName, Boolean.valueOf(unique), indexExprs, Boolean.valueOf(assumeUnique), predicate };
return new StatementSchema(sql, StatementTypes.CREATE_INDEX, args, null, table.getName());
}
use of org.hsqldb_voltpatches.HsqlNameManager.HsqlName in project voltdb by VoltDB.
the class ParserDDL method readTableAsSubqueryDefinition.
StatementSchema readTableAsSubqueryDefinition(Table table) {
HsqlName readName = null;
boolean withData = true;
HsqlName[] columnNames = null;
Statement statement = null;
if (token.tokenType == Tokens.OPENBRACKET) {
columnNames = readColumnNames(table.getName());
}
readThis(Tokens.AS);
readThis(Tokens.OPENBRACKET);
QueryExpression queryExpression = XreadQueryExpression();
queryExpression.setAsTopLevel();
queryExpression.resolve(session);
readThis(Tokens.CLOSEBRACKET);
readThis(Tokens.WITH);
if (token.tokenType == Tokens.NO) {
read();
withData = false;
} else if (table.getTableType() == TableBase.TEXT_TABLE) {
throw unexpectedTokenRequire(Tokens.T_NO);
}
readThis(Tokens.DATA);
if (token.tokenType == Tokens.ON) {
if (!table.isTemp()) {
throw unexpectedToken();
}
read();
readThis(Tokens.COMMIT);
if (token.tokenType == Tokens.DELETE) {
} else if (token.tokenType == Tokens.PRESERVE) {
table.persistenceScope = TableBase.SCOPE_SESSION;
}
read();
readThis(Tokens.ROWS);
}
TableUtil.setColumnsInSchemaTable(table, queryExpression.getResultColumnNames(), queryExpression.getColumnTypes());
if (columnNames != null) {
if (columnNames.length != queryExpression.getColumnCount()) {
throw Error.error(ErrorCode.X_42593);
}
for (int i = 0; i < columnNames.length; i++) {
table.getColumn(i).getName().rename(columnNames[i]);
}
}
table.createPrimaryKey();
if (withData) {
statement = new StatementQuery(session, queryExpression, compileContext);
}
Object[] args = new Object[] { table, null, statement };
String sql = getLastPart();
StatementSchema st = new StatementSchema(sql, StatementTypes.CREATE_TABLE, args, null, null);
st.readTableNames = statement.getTableNamesForRead();
return st;
}
use of org.hsqldb_voltpatches.HsqlNameManager.HsqlName in project voltdb by VoltDB.
the class ParserDDL method readConstraint.
/**
* Reads and adds a table constraint definition to the list
*
* @param schemaObject table or domain
* @param constraintList list of constraints
*/
private void readConstraint(SchemaObject schemaObject, HsqlArrayList constraintList) {
HsqlName constName = null;
boolean isAutogeneratedName = true;
if (token.tokenType == Tokens.CONSTRAINT) {
read();
constName = readNewDependentSchemaObjectName(schemaObject.getName(), SchemaObject.CONSTRAINT);
isAutogeneratedName = false;
}
// A VoltDB extension to support indexed expressions and the assume unique attribute
// For VoltDB
boolean assumeUnique = false;
// End of VoltDB extension
switch(token.tokenType) {
case Tokens.PRIMARY:
{
if (schemaObject.getName().type != SchemaObject.TABLE) {
throw this.unexpectedTokenRequire(Tokens.T_CHECK);
}
read();
readThis(Tokens.KEY);
Constraint mainConst;
mainConst = (Constraint) constraintList.get(0);
if (mainConst.constType == Constraint.PRIMARY_KEY) {
throw Error.error(ErrorCode.X_42532);
}
if (constName == null) {
constName = database.nameManager.newAutoName("PK", schemaObject.getSchemaName(), schemaObject.getName(), SchemaObject.CONSTRAINT);
}
OrderedHashSet set = readColumnNames(false);
Constraint c = new Constraint(constName, isAutogeneratedName, set, Constraint.PRIMARY_KEY);
constraintList.set(0, c);
break;
}
// A VoltDB extension to support indexed expressions and the assume unique attribute
case Tokens.ASSUMEUNIQUE:
assumeUnique = true;
// End of VoltDB extension
case Tokens.UNIQUE:
{
if (schemaObject.getName().type != SchemaObject.TABLE) {
throw this.unexpectedTokenRequire(Tokens.T_CHECK);
}
read();
// A VoltDB extension to "readColumnNames(false)" to support indexed expressions.
java.util.List<Expression> indexExprs = XreadExpressions(null);
OrderedHashSet set = getSimpleColumnNames(indexExprs);
if (constName == null) {
constName = database.nameManager.newAutoName("CT", schemaObject.getSchemaName(), schemaObject.getName(), SchemaObject.CONSTRAINT);
}
// A VoltDB extension to support indexed expressions.
boolean hasNonColumnExprs = false;
if (set == null) {
hasNonColumnExprs = true;
set = getBaseColumnNames(indexExprs);
}
// End of VoltDB extension
Constraint c = new Constraint(constName, isAutogeneratedName, set, Constraint.UNIQUE);
// A VoltDB extension to support indexed expressions and assume unique attribute.
c.setAssumeUnique(assumeUnique);
if (hasNonColumnExprs) {
c = c.withExpressions(indexExprs.toArray(new Expression[indexExprs.size()]));
}
// End of VoltDB extension
constraintList.add(c);
break;
}
case Tokens.FOREIGN:
{
if (schemaObject.getName().type != SchemaObject.TABLE) {
throw this.unexpectedTokenRequire(Tokens.T_CHECK);
}
read();
readThis(Tokens.KEY);
OrderedHashSet set = readColumnNames(false);
Constraint c = readFKReferences((Table) schemaObject, constName, set);
constraintList.add(c);
break;
}
case Tokens.CHECK:
{
read();
if (constName == null) {
constName = database.nameManager.newAutoName("CT", schemaObject.getSchemaName(), schemaObject.getName(), SchemaObject.CONSTRAINT);
}
Constraint c = new Constraint(constName, isAutogeneratedName, null, Constraint.CHECK);
readCheckConstraintCondition(c);
constraintList.add(c);
break;
}
// A VoltDB extension to support LIMIT PARTITION ROWS
case Tokens.LIMIT:
{
read();
for (int i = 0; i < constraintList.size(); i++) {
if (((Constraint) constraintList.get(i)).getConstraintType() == Constraint.LIMIT) {
throw Error.error(ErrorCode.X_42524, String.format("Multiple LIMIT PARTITION ROWS constraints on table %s are forbidden.", schemaObject.getName().name));
}
}
if (constName == null) {
constName = database.nameManager.newAutoName("LIMIT", schemaObject.getSchemaName(), schemaObject.getName(), SchemaObject.CONSTRAINT);
}
Constraint c = new Constraint(constName, isAutogeneratedName, null, Constraint.LIMIT);
readLimitConstraintCondition(c);
constraintList.add(c);
break;
}
// End of VoltDB extension
default:
{
if (constName != null) {
throw Error.error(ErrorCode.X_42581);
}
}
}
}
use of org.hsqldb_voltpatches.HsqlNameManager.HsqlName in project voltdb by VoltDB.
the class ParserDDL method processAlterTableRename.
/**
* Responsible for handling tail of ALTER TABLE ... RENAME ...
* @param table table
*/
void processAlterTableRename(Table table) {
HsqlName name = readNewSchemaObjectName(SchemaObject.TABLE);
name.setSchemaIfNull(table.getSchemaName());
if (table.getSchemaName() != name.schema) {
throw Error.error(ErrorCode.X_42505);
}
database.schemaManager.renameSchemaObject(table.getName(), name);
}
use of org.hsqldb_voltpatches.HsqlNameManager.HsqlName in project voltdb by VoltDB.
the class ParserDQL method readNewSchemaObjectNameNoCheck.
HsqlName readNewSchemaObjectNameNoCheck(int type) {
checkIsSchemaObjectName();
HsqlName hsqlName = database.nameManager.newHsqlName(token.tokenString, isDelimitedIdentifier(), type);
if (token.namePrefix != null) {
if (type == SchemaObject.GRANTEE) {
throw unexpectedToken();
}
HsqlName schemaName = session.database.schemaManager.findSchemaHsqlName(token.namePrefix);
if (schemaName == null) {
schemaName = database.nameManager.newHsqlName(token.namePrefix, isDelimitedIdentifier(), SchemaObject.SCHEMA);
}
hsqlName.setSchemaIfNull(schemaName);
}
read();
return hsqlName;
}
Aggregations