Custom Functions
The custom function functionality in Astera Data Stack allows users to integrate new functions, which may not already exist in Astera's library of available functions, to match their uses cases.
Employing this functionality requires a basic understanding of .NET and programming in general.
Example
For our use case, we will be creating a custom function that allows us to calculate the total price after applying taxes and discounts.
First, we will create a new .NET project in Visual Studio or any compiler which supports the .NET framework. We will name our project CustomFunctionCalculator_plugin.
![](https://documentation.astera.com/~gitbook/image?url=https%3A%2F%2Fgithub.com%2Fastera-software%2FAstera_Data_Stack_v9%2Fblob%2Fmain%2F.gitbook%2Fassets%2F0%2520%282%29%2520%281%29%2520%281%29%2520%281%29%2520%281%29%2520%281%29.png&width=768&dpr=4&quality=100&sign=abce6847&sv=1)
Note: Astera Data Stack will only load assemblies with output assemblies suffixed plugin.
Next, we will create a new class in our project. We will name it TotalPriceCalculator. Here, we will be writing our code for the custom function that we want to create and deploy.
![](https://documentation.astera.com/~gitbook/image?url=https%3A%2F%2Fgithub.com%2Fastera-software%2FAstera_Data_Stack_v9%2Fblob%2Fmain%2F.gitbook%2Fassets%2F1%2520%282%29%2520%281%29%2520%281%29%2520%281%29%2520%281%29%2520%281%29.png&width=768&dpr=4&quality=100&sign=e8f3c456&sv=1)
Next, we will add assembly references to our project. To do this, we will right-click on our project and select Add > Project Reference.
![](https://documentation.astera.com/~gitbook/image?url=https%3A%2F%2Fgithub.com%2Fastera-software%2FAstera_Data_Stack_v9%2Fblob%2Fmain%2F.gitbook%2Fassets%2F2%2520%282%29%2520%281%29%2520%281%29%2520%281%29%2520%281%29%2520%281%29.png&width=768&dpr=4&quality=100&sign=947fa635&sv=1)
The only .dll file which we need to reference here is the Astera.DataContracts.dll. This can be found in Astera Data Stack’s Server installation folder.
![](https://documentation.astera.com/~gitbook/image?url=https%3A%2F%2Fgithub.com%2Fastera-software%2FAstera_Data_Stack_v9%2Fblob%2Fmain%2F.gitbook%2Fassets%2F3%2520%282%29%2520%281%29.png&width=768&dpr=4&quality=100&sign=645f9a6c&sv=1)
![](https://documentation.astera.com/~gitbook/image?url=https%3A%2F%2Fgithub.com%2Fastera-software%2FAstera_Data_Stack_v9%2Fblob%2Fmain%2F.gitbook%2Fassets%2F4%2520%282%29%2520%281%29.png&width=768&dpr=4&quality=100&sign=df0c380b&sv=1)
Next, we will make sure that our class consists of the following custom attributes and Astera Data Stack references for a successful deployment of our custom function:
Astera Data Stack Reference: Make sure that the using Astera.Core; statement is added at the top of the file.
![](https://documentation.astera.com/~gitbook/image?url=https%3A%2F%2Fgithub.com%2Fastera-software%2FAstera_Data_Stack_v9%2Fblob%2Fmain%2F.gitbook%2Fassets%2F5%2520%282%29%2520%281%29.png&width=768&dpr=4&quality=100&sign=b7eabafa&sv=1)
Custom Attributes:
![](https://documentation.astera.com/~gitbook/image?url=https%3A%2F%2Fgithub.com%2Fastera-software%2FAstera_Data_Stack_v9%2Fblob%2Fmain%2F.gitbook%2Fassets%2F6%2520%281%29%2520%281%29.png&width=768&dpr=4&quality=100&sign=33607d8c&sv=1)
Next, we will write our custom function which we would like to deploy. The following is a sample code for a function which calculates the total price after applying discounts and tax to a specified value.
![](https://documentation.astera.com/~gitbook/image?url=https%3A%2F%2Fgithub.com%2Fastera-software%2FAstera_Data_Stack_v9%2Fblob%2Fmain%2F.gitbook%2Fassets%2F7%2520%281%29%2520%281%29.png&width=768&dpr=4&quality=100&sign=1b77c8d&sv=1)
Now, we will compile our custom function. To do this we will right-click on our project and select Build from the drop-down menu.
![](https://documentation.astera.com/~gitbook/image?url=https%3A%2F%2Fgithub.com%2Fastera-software%2FAstera_Data_Stack_v9%2Fblob%2Fmain%2F.gitbook%2Fassets%2F8%2520%281%29%2520%281%29.png&width=768&dpr=4&quality=100&sign=c639e126&sv=1)
A .dll file with the same name as our project will be created in the bin > debug folder of the file location specified.
![](https://documentation.astera.com/~gitbook/image?url=https%3A%2F%2Fgithub.com%2Fastera-software%2FAstera_Data_Stack_v9%2Fblob%2Fmain%2F.gitbook%2Fassets%2F9%2520%281%29%2520%281%29.png&width=768&dpr=4&quality=100&sign=78105117&sv=1)
Next, we will copy this .dll file and paste it in the Server, as well as the Client directories.
Note: This is a crucial step in making sure the deployment of the new custom function is successful.
Now, if we open Astera's data integration tool, in the Function Transformations section of the Toolbox, a new Custom Function tab will appear. Upon expanding this tab, you can see that our custom function has been successfully created and deployed.
This concludes creating and deploying a Custom Function in Astera Data Stack.