Class ParameterNode

  • All Implemented Interfaces:
    Visitable

    public class ParameterNode
    extends ValueNode
    This node type represents a ? parameter.
    • Field Detail

      • parameterNumber

        private int parameterNumber
      • userParameterTypes

        private DataTypeDescriptor[] userParameterTypes
        Pointer to the array in the CompilerContext that holds array of types for all the user-visible paramerers.. When each parameter is bound, it fills in its type descriptor in this array. Note that the array is allocated in the parser, but the individual elements are not filled in until their corresponding parameters are bound. This array is not read in this class, but is read from the CompilerContext on completion of compiling the statement. In some case a parameter node may exist but is not a visble user parameter, in this case typeServices will be null so that setting its type will not modify the user's set.
      • jsqlType

        private JSQLType jsqlType
        This ParameterNode may turn up as an argument to a replicated Work Unit. If so, the remote system will have figured out the type of this node. That's what this variable is for.
      • orderableVariantType

        private int orderableVariantType
      • returnOutputParameter

        private ValueNode returnOutputParameter
        By default, we assume we are just a normal, harmless little ole parameter. But sometimes we may be a return parameter (e.g. ? = CALL myMethod()).
      • valToGenerate

        private ValueNode valToGenerate
        If this parameter node was created as part of a "probe predicate" for an InListOperatorNode then it does not actually correspond to a specific value--we just created it as a start-key place-holder for IN-list values at execution time. In order to serve that purpose we need to generate some value that can be used as the place-holder. Since this parameter node is "fake" and does not correspond to an actual parameter, we can't really generate it; so the following field holds some legitimate ValueNode--either a constant node or a "real" parameter node--that we can generate to serve as the place-holder.
    • Constructor Detail

      • ParameterNode

        ParameterNode​(int parameterNumber,
                      DataValueDescriptor defaultValue,
                      ContextManager cm)
        Constructor for a ParameterNode.
        Parameters:
        parameterNumber - The number of this parameter, (unique per query starting at 0)
        defaultValue - The default value for this parameter
        cm - The context manager
    • Method Detail

      • getParameterNumber

        int getParameterNumber()
        Get the parameter number
        Returns:
        The parameter number
      • setDescriptors

        void setDescriptors​(DataTypeDescriptor[] descriptors)
        Set the descriptor array
        Parameters:
        descriptors - The array of DataTypeServices to fill in when the parameters are bound.
      • setReturnOutputParam

        void setReturnOutputParam​(ValueNode valueNode)
        Mark this as a return output parameter (e.g. ? = CALL myMethod())
      • isReturnOutputParam

        boolean isReturnOutputParam()
        Is this as a return output parameter (e.g. ? = CALL myMethod())
        Returns:
        true if it is a return param
      • bindExpression

        ValueNode bindExpression​(FromList fromList,
                                 SubqueryList subqueryList,
                                 java.util.List<AggregateNode> aggregates)
                          throws StandardException
        Bind this expression. A parameter can't figure out what its type is without knowing where it appears, so this method does nothing. It is up to the node that points to this parameter node to figure out the type of the parameter and set it, using the setType() method above.
        Overrides:
        bindExpression in class ValueNode
        Parameters:
        fromList - The FROM list for the query this expression is in, for binding columns.
        subqueryList - The subquery list being built as we find SubqueryNodes
        aggregates - The aggregate list being built as we find AggregateNodes
        Returns:
        The new top of the expression tree.
        Throws:
        StandardException - Thrown on error
      • isConstantExpression

        boolean isConstantExpression()
        Return whether or not this expression tree represents a constant expression.
        Overrides:
        isConstantExpression in class ValueNode
        Returns:
        Whether or not this expression tree represents a constant expression.
      • getOrderableVariantType

        protected int getOrderableVariantType()
        Return the variant type for the underlying expression. The variant type can be: VARIANT - variant within a scan (method calls and non-static field access) SCAN_INVARIANT - invariant within a scan (column references from outer tables) QUERY_INVARIANT - invariant within the life of a query (constant expressions)
        Overrides:
        getOrderableVariantType in class ValueNode
        Returns:
        The variant type for the underlying expression.
      • setOrderableVariantType

        void setOrderableVariantType​(int type)
        In a special circumstance, we want to consider parameters as constants. For that situation, we allow a caller to temporarily set us to CONSTANT and then restore us.
      • setJSQLType

        public void setJSQLType​(JSQLType type)
        Set the JSQLType of this parameter. This supports the unnamed parameters that we use for replicated work units.
        Parameters:
        type - the JSQLType associated with this parameter
      • getJSQLType

        public JSQLType getJSQLType()
        Get the JSQLType associated with this parameter. Again, part of method resolution for replicated work units.
        Returns:
        the JSQLType that the remote system assigned
      • generateParameterValueSet

        static void generateParameterValueSet​(ExpressionClassBuilder acb,
                                              int numberOfParameters,
                                              java.util.List<ParameterNode> parameterList)
                                       throws StandardException
        Generate the code to create the ParameterValueSet, if necessary, when constructing the activation. Also generate the code to call a method that will throw an exception if we try to execute without all the parameters being set. This generated code goes into the Activation's constructor early on.
        Parameters:
        acb - The ExpressionClassBuilder for the class we're building
        numberOfParameters - number of parameters for this statement
        parameterList - The parameter list for the statement.
        Throws:
        StandardException - on error
      • getDefaultValue

        DataValueDescriptor getDefaultValue()
        Get the default value for the parameter. Parameters may get default values for optimization purposes.
        Returns:
        the value, may be null
      • requiresTypeFromContext

        boolean requiresTypeFromContext()
        Description copied from class: ValueNode
        Returns TRUE if the type of this node will be determined from the context in which it is getting used. If true is returned then after bindExpression() is called on the node, its type must be set (from the relevant context) using setType().
        Overrides:
        requiresTypeFromContext in class ValueNode
        Returns:
        Whether this node's type will be determined from the context
        See Also:
        ValueNode.requiresTypeFromContext()
      • isEquivalent

        boolean isEquivalent​(ValueNode o)
        Description copied from class: ValueNode
        Tests if this node is equivalent to the specified ValueNode. Two ValueNodes are considered equivalent if they will evaluate to the same value during query execution.

        This method provides basic expression matching facility for the derived class of ValueNode and it is used by the language layer to compare the node structural form of the two expressions for equivalence at bind phase.

        Note that it is not comparing the actual row values at runtime to produce a result; hence, when comparing SQL NULLs, they are considered to be equivalent and not unknown.

        One usage case of this method in this context is to compare the select column expression against the group by expression to check if they are equivalent. e.g.:

        SELECT c1+c2 FROM t1 GROUP BY c1+c2

        In general, node equivalence is determined by the derived class of ValueNode. But they generally abide to the rules below:

        • The two ValueNodes must be of the same node type to be considered equivalent. e.g.: CastNode vs. CastNode - equivalent (if their args also match), ColumnReference vs CastNode - not equivalent.
        • If node P contains other ValueNode(s) and so on, those node(s) must also be of the same node type to be considered equivalent.
        • If node P takes a parameter list, then the number of arguments and its arguments for the two nodes must also match to be considered equivalent. e.g.: CAST(c1 as INTEGER) vs CAST(c1 as SMALLINT), they are not equivalent.
        • When comparing SQL NULLs in this context, they are considered to be equivalent.
        • If this does not apply or it is determined that the two nodes are not equivalent then the derived class of this method should return false; otherwise, return true.
        Specified by:
        isEquivalent in class ValueNode
        Parameters:
        o - the node to compare this ValueNode against.
        Returns:
        true if the two nodes are equivalent, false otherwise.
      • setValueToGenerate

        protected void setValueToGenerate​(ValueNode vn)
        Save the received ValueNode locally so that we can generate it (in place of "this") at generation time. See the preprocess() method of InListOperatorNode for more on how this is used.
        Parameters:
        vn - The ValueNode to generate in place of this ParameterNode.