📄 resultsetnode.java
字号:
re.setType(new DataTypeDescriptor(colTypeId, true, maxWidth)); } } else if (colTypeId.isBitTypeId()) { if (colTypeId.getJDBCTypeId() == java.sql.Types.VARBINARY) { // then we're trying to cast a char literal into a // variable bit column. We can't change the base // type of the table constructor's value from char // to bit, so instead, we just change the base type // of that value from char to varchar--that way, // no padding will be added when we convert to // bits later on (Beetle 5306). TypeId tId = TypeId.getBuiltInTypeId(java.sql.Types.VARCHAR); re.setType(new DataTypeDescriptor(tId, true)); typeColumns.setElementAt(typeCol, index); } else if (colTypeId.getJDBCTypeId() == java.sql.Types.LONGVARBINARY) { TypeId tId = TypeId.getBuiltInTypeId(java.sql.Types.LONGVARCHAR); re.setType(new DataTypeDescriptor(tId, true)); typeColumns.setElementAt(typeCol, index); } } } else if (re instanceof BitConstantNode) { ResultColumn typeCol = (ResultColumn) typeColumns.elementAt(index); TypeId colTypeId = typeCol.getTypeId(); if (colTypeId.isBitTypeId()) { // NOTE: Don't bother doing this if the column type is BLOB, // as we don't allow bit literals to be inserted into BLOB // columns (they have to be explicitly casted first); beetle 5266. if ((colTypeId.getJDBCTypeId() != java.sql.Types.BINARY) && (colTypeId.getJDBCTypeId() != java.sql.Types.BLOB)) { int maxWidth = re.getTypeServices().getMaximumWidth(); re.setType(new DataTypeDescriptor(colTypeId, true, maxWidth)); } } else if (colTypeId.isStringTypeId()) { if (colTypeId.getJDBCTypeId() == java.sql.Types.VARCHAR) { // then we're trying to cast a bit literal into a // variable char column. We can't change the base // type of the table constructor's value from bit // to char, so instead, we just change the base // type of that value from bit to varbit--that way, // no padding will be added when we convert to // char later on. TypeId tId = TypeId.getBuiltInTypeId(java.sql.Types.VARBINARY); re.setType(new DataTypeDescriptor(tId, true)); typeColumns.setElementAt(typeCol, index); } else if (colTypeId.getJDBCTypeId() == java.sql.Types.LONGVARCHAR) { TypeId tId = TypeId.getBuiltInTypeId(java.sql.Types.LONGVARBINARY); re.setType(new DataTypeDescriptor(tId, true)); typeColumns.setElementAt(typeCol, index); } } } } } /** * Remember that this node is the source result set for an INSERT. */ public void setInsertSource() { insertSource = true; } /** * Verify that a SELECT * is valid for this type of subquery. * * @param outerFromList The FromList from the outer query block(s) * @param subqueryType The subquery type * * @return None * * @exception StandardException Thrown on error */ public void verifySelectStarSubquery(FromList outerFromList, int subqueryType) throws StandardException{ if (SanityManager.DEBUG) SanityManager.ASSERT(false, "verifySelectStarSubquery() is not expected to be called for " + this.getClass().toString()); } /** * Expand "*" into a ResultColumnList with all of the columns * in the table's result list. * * @param allTableName The qualifier on the "*" * * @return ResultColumnList The expanded list * * @exception StandardException Thrown on error */ public ResultColumnList getAllResultColumns(TableName allTableName) throws StandardException { if (SanityManager.DEBUG) SanityManager.THROWASSERT( "getAllResultColumns() not expected to be called for " + this.getClass().getName() + this); return null; } /** * Try to find a ResultColumn in the table represented by this FromTable * that matches the name in the given ColumnReference. * * @param columnReference The columnReference whose name we're looking * for in the given table. * * @return A ResultColumn whose expression is the ColumnNode * that matches the ColumnReference. * Returns null if there is no match. * * @exception StandardException Thrown on error */ public ResultColumn getMatchingColumn( ColumnReference columnReference) throws StandardException { if (SanityManager.DEBUG) SanityManager.THROWASSERT( "getMatchingColumn() not expected to be called for " + this); return null; } /** * Set the result column for the subquery to a boolean true, * Useful for transformations such as * changing: * where exists (select ... from ...) * to: * where (select true from ...) * * NOTE: No transformation is performed if the ResultColumn.expression is * already the correct boolean constant. * * @param onlyConvertAlls Boolean, whether or not to just convert *'s * * @return Nothing. * * @exception StandardException Thrown on error */ public void setResultToBooleanTrueNode(boolean onlyConvertAlls) throws StandardException { BooleanConstantNode booleanNode; ResultColumn resultColumn; /* We need to be able to handle both ResultColumn and AllResultColumn * since they are peers. */ if (resultColumns.elementAt(0) instanceof AllResultColumn) { resultColumn = (ResultColumn) getNodeFactory().getNode( C_NodeTypes.RESULT_COLUMN, "", null, getContextManager()); } else if (onlyConvertAlls) { return; } else { resultColumn = (ResultColumn) resultColumns.elementAt(0); /* Nothing to do if query is already select TRUE ... */ if (resultColumn.getExpression().isBooleanTrue()) { return; } } booleanNode = (BooleanConstantNode) getNodeFactory().getNode( C_NodeTypes.BOOLEAN_CONSTANT_NODE, Boolean.TRUE, getContextManager()); resultColumn.setExpression(booleanNode); resultColumn.setType(booleanNode.getTypeServices()); /* VirtualColumnIds are 1-based, RCLs are 0-based */ resultColumn.setVirtualColumnId(1); resultColumns.setElementAt(resultColumn, 0); } /** * Get the FromList. Create and return an empty FromList. (Subclasses * which actuall have FromLists will override this.) This is useful because * there is a FromList parameter to bindExpressions() which is used as * the common FromList to bind against, allowing us to support * correlation columns under unions in subqueries. * * @return FromList * @exception StandardException Thrown on error */ public FromList getFromList() throws StandardException { return (FromList) getNodeFactory().getNode( C_NodeTypes.FROM_LIST, getNodeFactory().doJoinOrderOptimization(), getContextManager()); } /** * Bind the result columns of this ResultSetNode when there is no * base table to bind them to. This is useful for SELECT statements, * where the result columns get their types from the expressions that * live under them. * * @param fromListParam FromList to use/append to. * * @return Nothing * * @exception StandardException Thrown on error */ public void bindResultColumns(FromList fromListParam) throws StandardException { resultColumns.bindResultColumnsToExpressions(); } /** * Bind the result columns for this ResultSetNode to a base table. * This is useful for INSERT and UPDATE statements, where the * result columns get their types from the table being updated or * inserted into. * If a result column list is specified, then the verification that the * result column list does not contain any duplicates will be done when * binding them by name. * * @param targetTableDescriptor The TableDescriptor for the table being * updated or inserted into * @param targetColumnList For INSERT statements, the user * does not have to supply column * names (for example, "insert into t * values (1,2,3)". When this * parameter is null, it means that * the user did not supply column * names, and so the binding should * be done based on order. When it * is not null, it means do the binding * by name, not position. * @param statement Calling DMLStatementNode (Insert or Update) * @param fromListParam FromList to use/append to. * * @return Nothing * * @exception StandardException Thrown on error */ public void bindResultColumns(TableDescriptor targetTableDescriptor, FromVTI targetVTI, ResultColumnList targetColumnList, DMLStatementNode statement, FromList fromListParam) throws StandardException { /* For insert select, we need to expand any *'s in the * select before binding the result columns */ if (this instanceof SelectNode) { resultColumns.expandAllsAndNameColumns(((SelectNode)this).fromList); } /* If specified, copy the result column names down to the * source's target list. */ if (targetColumnList != null) { resultColumns.copyResultColumnNames(targetColumnList); } if (targetColumnList != null) { if (targetTableDescriptor != null) { resultColumns.bindResultColumnsByName( targetTableDescriptor, statement); } else { resultColumns.bindResultColumnsByName( targetVTI.getResultColumns(), targetVTI, statement); } } else resultColumns.bindResultColumnsByPosition(targetTableDescriptor); } /** * Bind untyped nulls to the types in the given ResultColumnList. * This is used for binding the nulls in row constructors and * table constructors. In all other cases (as of the time of * this writing), we do nothing. * * @param rcl The ResultColumnList with the types to bind nulls to * * @exception StandardException Thrown on error */ public void bindUntypedNullsToResultColumns(ResultColumnList rcl) throws StandardException { return; } /** * Preprocess a ResultSetNode - this currently means: * o Generating a referenced table map for each ResultSetNode. * o Putting the WHERE and HAVING clauses in conjunctive normal form (CNF). * o Converting the WHERE and HAVING clauses into PredicateLists and * classifying them. * o Ensuring that a ProjectRestrictNode is generated on top of every * FromBaseTable and generated in place of every FromSubquery. * o Pushing single table predicates down to the new ProjectRestrictNodes. * * @param numTables The number of tables in the DML Statement * @param gbl The group by list, if any * @param fromList The from list, if any * * @return ResultSetNode at top of preprocessed tree. * * @exception StandardException Thrown on error */ public ResultSetNode preprocess(int numTables, GroupByList gbl, FromList fromList) throws StandardException { if (SanityManager.DEBUG) SanityManager.THROWASSERT( "preprocess() not expected to be called for " + getClass().toString()); return null; } /** * Find the unreferenced result columns and project them out. */ void projectResultColumns() throws StandardException { // It is only necessary for joins } /** * Ensure that the top of the RSN tree has a PredicateList. * * @param numTables The number of tables in the query. * @return ResultSetNode A RSN tree with a node which has a PredicateList on top. * * @exception StandardException Thrown on error */ public ResultSetNode ensurePredicateList(int numTables) throws StandardException { if (SanityManager.DEBUG) SanityManager.THROWASSERT( "ensurePredicateList() not expected to be called for " + getClass().toString()); return null; } /** * Add a new predicate to the list. This is useful when doing subquery * transformations, when we build a new predicate with the left side of * the subquery operator and the subquery's result column. * * @param predicate The predicate to add * * @return ResultSetNode The new top of the tree. * * @exception StandardException Thrown on error */ public ResultSetNode addNewPredicate(Predicate predicate) throws StandardException { if (SanityManager.DEBUG) SanityManager.THROWASSERT( "addNewPredicate() not expected to be called for " + getClass().toString()); return null; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -