This section contains an example that creates a UDF that calculates the weighted average of 3 values.
Here is the C signature of our UDF, along with declarations of the local variables that we use:
/** * Calculates a weighted average of 3 values. * Performs (var1*wt1 + var2*wt2 + var3*wt3)/3.0 */ void weightedAverage3(C8Udf *ctx) float var1; /* first user variable */ float weight1; /* 2nd user var: weight for var1 */ float var2; /* 3rd user var */ float weight2; /* 4th user var */ float var3; /* ... */ float weight3);
You must provide an xml implementation of this signature and describe the parameters that will be passed from the CCL statement. The XML looks like:
<UserDefinedFunctions
  Name="TestingUserDefinedFunctions"
  Type="ns1:UserDefinedFunctionType"
  xmlns="http://www.sybase.com/udf/2005/04/"
  xmlns:udf="http://www.sybase.com/udf/2005/04/"
  xmlns:ns1="http://www.sybase.com/cpx/2005/04/"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>
<Description>Sybase CEP User Function Definition test cases
</Description>
<Vendor>Sybase Inc.</Vendor>
<Version>1.0</Version>
<Functions>
    <!-- Name         : Name in C code                     -->
    <!-- Library      : Library that the C func is in      -->
    <!-- CclName      : Name used in call from in CCL      -->
    <!-- IsAggregator : This function is not an aggregator -->
    <Function Name="weightedAverage3" 
              Library="user_function_lib" 
              CclName="WAvg3">
      <Description> 
       XML to describe a C function that performs a 
       weighted average of 3 values.
      </Description>
      <Input>
          <Parameter Name="var1"    Type="C8Float"/>
          <Parameter Name="weight1" Type="C8Float"/>
          <Parameter Name="var2"    Type="C8Float"/>
          <Parameter Name="weight2" Type="C8Float"/>
          <Parameter Name="var3"    Type="C8Float"/>
          <Parameter Name="weight3" Type="C8Float"/>
      </Input>
      <Output>
          <Parameter Type="C8Float"/>
      </Output>
    </Function>
   </Functions>
</UserDefinedFunctions>
            This xml file is placed in the plugins subdirectories of both the server and Studio directory. See Compiling a UDF and Putting It in the Correct Directory for more details.
Please note the following points: