<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>OpenText Analytics Database 26.2.x – Arguments and return values</title>
    <link>/en/extending/developing-udxs/arguments-and-return-values/</link>
    <description>Recent content in Arguments and return values on OpenText Analytics Database 26.2.x</description>
    <generator>Hugo -- gohugo.io</generator>
    
	  <atom:link href="/en/extending/developing-udxs/arguments-and-return-values/index.xml" rel="self" type="application/rss+xml" />
    
    
      
        
      
    
    
    <item>
      <title>Extending: Overloading your UDx</title>
      <link>/en/extending/developing-udxs/arguments-and-return-values/overloading-your-udx/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      
      <guid>/en/extending/developing-udxs/arguments-and-return-values/overloading-your-udx/</guid>
      <description>
        
        
        &lt;p&gt;You may want your UDx to accept several different signatures (sets of arguments). For example, you might want your UDx to accept:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;One or more optional arguments.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;One or more arguments that can be one of several data types.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Completely distinct signatures (either all INTEGER or all VARCHAR, for example).&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;You can create a function with this behavior by creating several factory classes, each of which accepts a different signature (the number and data types of arguments). You can then associate a single SQL function name with all of them. You can use the same SQL function name to refer to multiple factory classes as long as the signature defined by each factory is unique. When a user calls your UDx, OpenText™ Analytics Database matches the number and types of arguments supplied by the user to the arguments accepted by each of your function&#39;s factory classes. If one matches, the database uses it to instantiate a function class to process the data.&lt;/p&gt;
&lt;p&gt;Multiple factory classes can instantiate the same function class, so you can re-use one function class that is able to process multiple sets of arguments and then create factory classes for each of the function signatures. You can also create multiple function classes if you want.&lt;/p&gt;
&lt;p&gt;See the &lt;a href=&#34;../../../../en/extending/developing-udxs/arguments-and-return-values/overloading-your-udx/cpp-example-overloading-your-udx/#&#34;&gt;C&amp;#43;&amp;#43; example: overloading your UDx&lt;/a&gt; and &lt;a href=&#34;../../../../en/extending/developing-udxs/arguments-and-return-values/overloading-your-udx/java-example-overloading-your-udx/#&#34;&gt;Java example: overloading your UDx&lt;/a&gt; examples.&lt;/p&gt;

      </description>
    </item>
    
    <item>
      <title>Extending: Creating a polymorphic UDx</title>
      <link>/en/extending/developing-udxs/arguments-and-return-values/creating-polymorphic-udx/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      
      <guid>/en/extending/developing-udxs/arguments-and-return-values/creating-polymorphic-udx/</guid>
      <description>
        
        
        &lt;p&gt;Polymorphic UDxs accept any number and type of argument that the user supplies. Transform functions (UDTFs), analytic functions (UDAnFs), and aggregate functions (UDAFs) can define their output return types at runtime, usually based on the input arguments. For example, a UDTF that adds two numbers could return an integer or a float, depending on the input types.&lt;/p&gt;
&lt;p&gt;OpenText™ Analytics Database does not check the number or types of argument that the user passes to the UDx—it just passes the UDx all of the arguments supplied by the user. It is up to your polymorphic UDx&#39;s main processing function (for example, &lt;code&gt;processBlock()&lt;/code&gt; in user-defined scalar functions) to examine the number and types of arguments it received and determine if it can handle them. UDxs support up to 9800 arguments.&lt;/p&gt;
&lt;p&gt;Polymorphic UDxs are more flexible than using multiple factory classes for your function (see &lt;a href=&#34;../../../../en/extending/developing-udxs/arguments-and-return-values/overloading-your-udx/#&#34;&gt;Overloading your UDx&lt;/a&gt;). They also allow you to write more concise code, instead of writing versions for each data type. The tradeoff is that your polymorphic function needs to perform more work to determine whether it can process its arguments.&lt;/p&gt;
&lt;p&gt;Your polymorphic UDx declares that it accepts any number of arguments in its factory&#39;s &lt;code&gt;getPrototype()&lt;/code&gt; function by calling the &lt;code&gt;addAny()&lt;/code&gt; function on the &lt;code&gt;ColumnTypes&lt;/code&gt; object that defines its arguments, as follows:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-cpp&#34; data-lang=&#34;cpp&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;    &lt;span class=&#34;c1&#34;&gt;// C++ example
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;c1&#34;&gt;&lt;/span&gt;    &lt;span class=&#34;kt&#34;&gt;void&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;getPrototype&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;ServerInterface&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;srvInterface&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;                      &lt;span class=&#34;n&#34;&gt;ColumnTypes&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;argTypes&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;                      &lt;span class=&#34;n&#34;&gt;ColumnTypes&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;returnType&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;    &lt;span class=&#34;p&#34;&gt;{&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;        &lt;span class=&#34;n&#34;&gt;argTypes&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;addAny&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;();&lt;/span&gt; &lt;span class=&#34;c1&#34;&gt;// Must be only argument type.
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;c1&#34;&gt;&lt;/span&gt;        &lt;span class=&#34;n&#34;&gt;returnType&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;addInt&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;();&lt;/span&gt; &lt;span class=&#34;c1&#34;&gt;// or whatever the function returns
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;c1&#34;&gt;&lt;/span&gt;    &lt;span class=&#34;p&#34;&gt;}&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;This &amp;quot;any parameter&amp;quot; argument type is the only one that your function can declare. You cannot define required arguments and then call &lt;code&gt;addAny()&lt;/code&gt; to declare the rest of the signature as optional. If your function has requirements for the arguments it accepts, your &lt;code&gt;process()&lt;/code&gt; function must enforce them.&lt;/p&gt;
&lt;p&gt;The &lt;code&gt;getPrototype()&lt;/code&gt; example shown previously accepts any type and declares that it returns an integer. The following example shows a version of the method that defers resolving the return type until runtime. You can only use the &amp;quot;any&amp;quot; return type for transform and analytic functions.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-cpp&#34; data-lang=&#34;cpp&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;    &lt;span class=&#34;kt&#34;&gt;void&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;getPrototype&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;ServerInterface&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;srvInterface&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;                      &lt;span class=&#34;n&#34;&gt;ColumnTypes&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;argTypes&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;                      &lt;span class=&#34;n&#34;&gt;ColumnTypes&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;returnType&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;    &lt;span class=&#34;p&#34;&gt;{&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;        &lt;span class=&#34;n&#34;&gt;argTypes&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;addAny&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;();&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;        &lt;span class=&#34;n&#34;&gt;returnType&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;addAny&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;();&lt;/span&gt; &lt;span class=&#34;c1&#34;&gt;// type determined at runtime
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;c1&#34;&gt;&lt;/span&gt;    &lt;span class=&#34;p&#34;&gt;}&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;If you use polymorphic return types, you must also define &lt;code&gt;getReturnType()&lt;/code&gt; in your factory. This function is called at runtime to determine the actual return type. See &lt;a href=&#34;../../../../en/extending/developing-udxs/arguments-and-return-values/creating-polymorphic-udx/cpp-example-polynthvalue/#&#34;&gt;C&amp;#43;&amp;#43; example: PolyNthValue&lt;/a&gt; for an example.&lt;/p&gt;
&lt;h2 id=&#34;polymorphic-udxs-and-schema-search-paths&#34;&gt;Polymorphic UDxs and schema search paths&lt;/h2&gt;
&lt;p&gt;If a user does not supply a schema name as part of a UDx call, the database searches each schema in the schema search path for a function whose name and signature match the function call. See &lt;a href=&#34;../../../../en/admin/configuring-db/designing-logical-schema/using-multiple-schemas/setting-search-paths/#&#34;&gt;Setting search paths&lt;/a&gt; for more information about schema search paths.&lt;/p&gt;
&lt;p&gt;Because polymorphic UDxs do not have specific signatures associated with them, the database initially skips them when searching for a function to handle the function call. If none of the schemas in the search path contain a UDx whose name and signature match the function call, the database searches the schema search path again for a polymorphic UDx whose name matches the function name in the function call.&lt;/p&gt;
&lt;p&gt;This behavior gives precedence to a UDx whose signature exactly matches the function call. It allows you to create a &amp;quot;catch-all&amp;quot; polymorphic UDx that the database calls only when none of the non-polymorphic UDxs with the same name have matching signatures.&lt;/p&gt;
&lt;p&gt;This behavior may cause confusion if your users expect the first polymorphic function in the schema search path to handle a function call. To avoid confusion, you should:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Avoid using the same name for different UDxs. You should always uniquely name UDxs unless you intend to create an overloaded UDx with multiple signatures.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;When you cannot avoid having UDxs with the same name in different schemas, always supply the schema name as part of the function call. Using the schema name prevents ambiguity and ensures that the database uses the correct UDx to process your function calls.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;

      </description>
    </item>
    
  </channel>
</rss>
