How to develop a Virtual DataPort Custom Function
Developing a Virtual DataPort Custom Function
As a next step, let's move on to developing a Virtual DataPort Custom function in which you can extend the set of functions available in Denodo Virtual DataPort.
Virtual DataPort Functions
In order to see the list of existing functions, you can open the dialog Help > Functions list
in your Virtual DataPort
Administration Tool:
Implementing new Virtual DataPort Functions
Custom functions are implemented as Java classes included in a Jar file that is added to Virtual DataPort as extension. There are some general rules to keep in mind before developing these functions, you can refer the section Developing Custom Functions for more details on it.
You could create a Custom function by using "annotations" or following some "name conventions". We will use the first approach as it is the recommended one!.
Now let’s learn how to develop a StringConcatenate
function which would join two or more strings together!
- Launch Eclipse, create a new project by navigating to
File> New > Project
:
- Create a new Denodo Extension project by choosing
Denodo4E > Denodo Extension project
and click on
Next >.
- Specify the project name as
my_denodo_extensions
and click Next >:
- Select the path to your
local Denodo Platform
installation. - Choose
Denodo VDP/ITP Server
as Denodo application andDenodo VDP Custom Function
as Extension configuration. - Enter the package, e.g.
com.denodo.vdp.custom.functions
, and the Java class name, e.g.StringConcatenate
and Click Finish.
- Now you could see that
StringConcatenate.java
file gets created in the Package Explorer and the needed dependencies get imported to the project classpath:
- When you double-click on the
StringConcatenate.java
file, you will see a template to implement the Virtual DataPort Custom Function (it is automatically created). This template consists of a simple function returning the length of an input String.
As you can see the java class contains several annotations to indicate Virtual DataPort the following:@CustomElement(type=CustomElementType.VDPFUNCTION, name="STRINGCONCATENATE")
: the Java class contains the code of a Virtual DataPort custom function called STRINGCONCATENATE.@CustomExecutor
: method containing the code that Virtual DataPort will have to run when the custom function is invoked.@CustomParam(name = "s") String s
: input parameters definition (Note: See the equivalency table between Java and Virtual DataPort data types).@CustomExecutorReturnType
: method invoked by Virtual DataPort to obtain the return type of the custom function.
- For implementing the new function you only have to modify the Java code of this function:
Deploy our Custom Function into Virtual DataPort
Ok, once the function is ready it's time to deploy it into Virtual DataPort (it has to be launched before you deploy the extension!). The Denodo4e plugin allows to deploy the extensions created in the Eclipse project. You only have to follow these steps:
- Right click on the project
my_denodo_extensions
and selectDeploy Extensions
:
- Provide the connection details to the Virtual DataPort server in the
Denodo VDP/ITP server configuration
section and the metadata information of the extension you are going to deploy: JAR name, description, version, target Denodo version and update and click Finish.
- From your Virtual DataPort Administration tool, first click on
File > Refresh
to load the changes. Then navigate toFile > Extension Management
, you will find a new extension!
- You could see the jar extension
denodo-tutorial-extensions
was added. Also you can check the dialogHelp > Functions list
to see the new function (with the syntax defined in the @CustomExecutor annotation!).
- Finally, you can test the new function, for example, from the
VQL Shell
:
I want to know more advanced techniques!
Is it possible to have different signatures for the same custom function?
Yes, you only have to add more methods having the @CustomExecutor
annotation, for example:
@CustomExecutor public Integer method1(Integer i) { ... } @CustomExecutor public Integer method2(Integer i, String s) { ... }
Could my custom function be delegated to a JDBC data source?
Yes, you only have to configure the @CustomExecutor
annotation adding the delegation pattern, for example:
@CustomExecutor(implementation = true, delegationPatterns = { @DelegationPattern(databaseName = "sqlserver", pattern = "CONCAT($0[, $i]{1, n})") })In that example Virtual DataPort will delegate the execution of the function to SQL Server (using the
CONCAT()
function of SQL Server), whenever it is possible. If a different data
source in envolved in the query then Virtual DataPort will execute the code implemented in the custom function instead of
delegating it. Find more examples here.
That's all! You have created your first custom fucntion. You can now click on the NEXT> button to continue with this tutorial.