StatementDMQL compileDeleteStatement ( RangeVariable [ ] outerRanges ) { Expression condition = null ; boolean truncate = false ; boolean restartIdentity = false ; switch ( token . tokenType ) { case Tokens . TRUNCATE : { read ( ) ; readThis ( Tokens . TABLE ) ; truncate = true ; break ; } case Tokens . DELETE : { read ( ) ; readThis ( Tokens . FROM ) ; break ; } } RangeVariable [ ] rangeVariables = { readSimpleRangeVariable ( StatementTypes . DELETE_WHERE ) } ; Table table = rangeVariables [ 0 ] . getTable ( ) ; Table baseTable = table . getBaseTable ( ) ; /* A VoltDB Extension. * Views from Streams are now updatable. * Comment out this guard and check if it is a view * from Stream or PersistentTable in planner. if (!table.isUpdatable()) { throw Error.error(ErrorCode.X_42000); } A VoltDB Extension */ if ( truncate ) { switch ( token . tokenType ) { case Tokens . CONTINUE : { read ( ) ; readThis ( Tokens . IDENTITY ) ; break ; } case Tokens . RESTART : { read ( ) ; readThis ( Tokens . IDENTITY ) ; restartIdentity = true ; break ; } } for ( int i = 0 ; i < table . constraintList . length ; i ++ ) { if ( table . constraintList [ i ] . getConstraintType ( ) == Constraint . MAIN ) { throw Error . error ( ErrorCode . X_23501 ) ; } } } if ( truncate && table != baseTable ) { throw Error . error ( ErrorCode . X_42000 ) ; } if ( ! truncate && token . tokenType == Tokens . WHERE ) { read ( ) ; condition = XreadBooleanValueExpression ( ) ; HsqlList unresolved = condition . resolveColumnReferences ( outerRanges , null ) ; unresolved = Expression . resolveColumnSet ( rangeVariables , unresolved , null ) ; ExpressionColumn . checkColumnsResolved ( unresolved ) ; condition . resolveTypes ( session , null ) ; if ( condition . isParam ( ) ) { condition . dataType = Type . SQL_BOOLEAN ; } if ( condition . getDataType ( ) != Type . SQL_BOOLEAN ) { throw Error . error ( ErrorCode . X_42568 ) ; } } // VoltDB Extension: // baseTable could be null for stream views. if ( baseTable != null && table != baseTable ) { QuerySpecification select = ( ( TableDerived ) table ) . getQueryExpression ( ) . getMainSelect ( ) ; if ( condition != null ) { condition = condition . replaceColumnReferences ( rangeVariables [ 0 ] , select . exprColumns ) ; } rangeVariables [ 0 ] = new RangeVariable ( select . rangeVariables [ 0 ] ) ; condition = ExpressionLogical . andExpressions ( select . queryCondition , condition ) ; } if ( condition != null ) { RangeVariableResolver resolver = new RangeVariableResolver ( rangeVariables , condition , compileContext ) ; resolver . processConditions ( ) ; rangeVariables = resolver . rangeVariables ; } // VoltDB Extension: // This needs to be done before building the compiled statement // so that parameters in LIMIT or OFFSET are retrieved from // the compileContext SortAndSlice sas = voltGetSortAndSliceForDelete ( rangeVariables ) ; StatementDMQL cs = new StatementDML ( session , table , rangeVariables , compileContext , restartIdentity ) ; // VoltDB Extension: voltAppendDeleteSortAndSlice ( ( StatementDML ) cs , sas ) ; return cs ; }
Creates a DELETE - type Statement from this parse context .