use of org.apache.derby.iapi.sql.compile.IgnoreFilter in project derby by apache.
the class MergeNode method bindLeftJoin.
// /////////////////////////
//
// BINDING THE LEFT JOIN
//
// /////////////////////////
/**
* Bind the driving left join select.
* Stuffs the left join SelectNode into the resultSet variable.
*/
private void bindLeftJoin(DataDictionary dd) throws StandardException {
CompilerContext cc = getCompilerContext();
final int previousReliability = cc.getReliability();
try {
cc.setReliability(previousReliability | CompilerContext.SQL_IN_ROUTINES_ILLEGAL);
//
// Don't add any privileges until we bind the matching refinement clauses.
//
IgnoreFilter ignorePermissions = new IgnoreFilter();
getCompilerContext().addPrivilegeFilter(ignorePermissions);
_hojn = new HalfOuterJoinNode(_sourceTable, _targetTable, _searchCondition, null, false, null, getContextManager());
_leftJoinFromList = _hojn.makeFromList(true, true);
_leftJoinFromList.bindTables(dd, new FromList(getOptimizerFactory().doJoinOrderOptimization(), getContextManager()));
if (!sourceIsBase_or_VTI()) {
throw StandardException.newException(SQLState.LANG_SOURCE_NOT_BASE_OR_VTI);
}
FromList topFromList = new FromList(getOptimizerFactory().doJoinOrderOptimization(), getContextManager());
topFromList.addFromTable(_hojn);
// ready to add permissions
getCompilerContext().removePrivilegeFilter(ignorePermissions);
// code generation.
for (MatchingClauseNode mcn : _matchingClauses) {
mcn.bindRefinement(this, _leftJoinFromList);
}
ResultColumnList selectList = buildSelectList();
// save a copy so that we can remap column references when generating the temporary rows
_selectList = selectList.copyListAndObjects();
resultSet = new SelectNode(selectList, topFromList, // where clause
null, // group by list
null, // having clause
null, // window list
null, // optimizer plan override
null, getContextManager());
// Wrap the SELECT in a CursorNode in order to finish binding it.
_leftJoinCursor = new CursorNode("SELECT", resultSet, null, null, null, null, false, CursorNode.READ_ONLY, null, true, getContextManager());
//
// We're only interested in privileges related to the ON clause.
// Otherwise, the driving left join should not contribute any
// privilege requirements.
//
getCompilerContext().addPrivilegeFilter(ignorePermissions);
_leftJoinCursor.bindStatement();
// ready to add permissions again
getCompilerContext().removePrivilegeFilter(ignorePermissions);
// now figure out what privileges are needed for the ON clause
addOnClausePrivileges();
} finally {
// Restore previous compiler state
cc.setReliability(previousReliability);
}
}
use of org.apache.derby.iapi.sql.compile.IgnoreFilter in project derby by apache.
the class MergeNode method cloneFromList.
// //////////////////////////
//
// CLONING THE FROM LIST
//
// //////////////////////////
/**
* Create a FromList for binding a WHEN [ NOT ] MATCHED clause
*/
private FromList cloneFromList(DataDictionary dd, FromBaseTable targetTable) throws StandardException {
FromList dummyFromList = new FromList(getContextManager());
FromBaseTable dummyTargetTable = new FromBaseTable(targetTable.getTableNameField(), targetTable.correlationName, null, null, getContextManager());
FromTable dummySourceTable = cloneFromTable(_sourceTable);
dummyTargetTable.setMergeTableID(ColumnReference.MERGE_TARGET);
dummySourceTable.setMergeTableID(ColumnReference.MERGE_SOURCE);
dummyFromList.addFromTable(dummySourceTable);
dummyFromList.addFromTable(dummyTargetTable);
//
// Don't add any privileges while binding the tables.
//
IgnoreFilter ignorePermissions = new IgnoreFilter();
getCompilerContext().addPrivilegeFilter(ignorePermissions);
dummyFromList.bindTables(dd, new FromList(getOptimizerFactory().doJoinOrderOptimization(), getContextManager()));
// ready to add permissions
getCompilerContext().removePrivilegeFilter(ignorePermissions);
return dummyFromList;
}
use of org.apache.derby.iapi.sql.compile.IgnoreFilter in project derby by apache.
the class MergeNode method bindStatement.
// /////////////////////////////////////////////////////////////////////////////////
//
// bind() BEHAVIOR
//
// /////////////////////////////////////////////////////////////////////////////////
@Override
public void bindStatement() throws StandardException {
DataDictionary dd = getDataDictionary();
// source table must be a vti or base table
if (!(_sourceTable instanceof FromVTI) && !(_sourceTable instanceof FromBaseTable)) {
throw StandardException.newException(SQLState.LANG_SOURCE_NOT_BASE_OR_VTI);
}
// source and target may not have the same correlation names
if (getExposedName(_targetTable).equals(getExposedName(_sourceTable))) {
throw StandardException.newException(SQLState.LANG_SAME_EXPOSED_NAME);
}
// don't allow derived column lists right now
forbidDerivedColumnLists();
// synonyms not allowed
forbidSynonyms();
//
// Don't add any privileges until we bind the matching clauses.
//
IgnoreFilter ignorePermissions = new IgnoreFilter();
getCompilerContext().addPrivilegeFilter(ignorePermissions);
FromList dfl = new FromList(getContextManager());
FromTable dflSource = cloneFromTable(_sourceTable);
FromBaseTable dflTarget = (FromBaseTable) cloneFromTable(_targetTable);
dfl.addFromTable(dflSource);
dfl.addFromTable(dflTarget);
dfl.bindTables(dd, new FromList(getOptimizerFactory().doJoinOrderOptimization(), getContextManager()));
// target table must be a base table
if (!targetIsBaseTable(dflTarget)) {
notBaseTable();
}
// ready to add permissions
getCompilerContext().removePrivilegeFilter(ignorePermissions);
for (MatchingClauseNode mcn : _matchingClauses) {
FromList dummyFromList = cloneFromList(dd, dflTarget);
FromBaseTable dummyTargetTable = (FromBaseTable) dummyFromList.elementAt(TARGET_TABLE_INDEX);
mcn.bind(dd, this, dummyFromList, dummyTargetTable);
// window function not allowed
SelectNode.checkNoWindowFunctions(mcn, "matching clause");
// aggregates not allowed
checkNoAggregates(mcn);
}
bindLeftJoin(dd);
}
Aggregations