Skip to content

entechlog/ksqlDB-udf

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

39 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ksqlDB UDF/UDAF

This repository has the list of custom ksqlDB UDF/UDAF created by Entechlog.com to solve various real-life use cases.

Table of Contents


Versions and Requirements

Compatible KSQL versions:

  • The examples in this repository are built against KSQL 5.4.0 for Apache Kafka and Confluent Platform 5.4.0.

Requirements to locally build, test, package the UDF/UDAF examples:

  • Java 8+
  • Maven 3.6+

See my blog on how to create UDF's at Entechlog for more details

ksqlDB UDF's

Usage Type Description Demo URL
UDF_TOTITLECASE(col1) UDF Return capitalized version of first character in each word Demo
UDF_EXTRACTNAME(col1,'lastName') UDF Returns firstName, middleName, lastName, suffix from fullName Demo
UDF_DS_CURRENTDATE() UDF Returns current date in YYYY-MM-DD format Demo
UDF_REPLACEALL(col1,'regex','replacement') UDF Calls Java String ReplaceAll Demo
UDF_TEXTTOHEX(col1) UDF Converts TEXT to HEX Demo
UDF_HEXTOTEXT(col1) UDF Converts HEX to TEXT Demo
UDF_FILTERARRAYLIST(col1,start,end) UDF Creates a subset of array based on start and end Demo
UDF_SORTARRAY(col1,'DESC') UDF Sorts list/array based on sort order [Demo]
UDF_CALCULATE_ENDDATE(col1) UDF Timeslices the array of dates and assigns an end date [Demo]

To package the UDFs/UDAFs (details):

To deploy the packaged UDFs/UDAFs to KSQL servers, refer to the KSQL documentation on UDF/UDAF. You can verify that the UDFs/UDAFs are available for use by running SHOW FUNCTIONS, and show the details of any specific function with DESCRIBE FUNCTION <name>.

To use the UDFs/UDAFs in KSQL

UDF_TOTITLECASE

SELECT C1, UDF_TOTITLECASE(C1) FROM T1;

UDF_EXTRACTNAME

SELECT C1, UDF_TOTITLECASE(C1,'firstName'), UDF_TOTITLECASE(C1,'lastName') FROM T1;

UDF_DS_CURRENTDATE

SELECT USERID, UDF_DS_CURRENTDATE() FROM STM_DATAGEN_USER_SRC_0010 EMIT CHANGES;

UDF_REPLACEALL

SELECT USERID, FULLNAME, UDF_REPLACEALL(FULLNAME, '[^A-ZA-Z0-9\\S]', '') FROM STM_DATAGEN_USER_SRC_0010 EMIT CHANGES;

UDF_TEXTTOHEX

SELECT UDF_TEXTTOHEX(DEPT_NAME), UDF_HEXTOTEXT(UDF_TEXTTOHEX(DEPT_NAME)),* FROM TBL_DEPARTMENTS_01 EMIT CHANGES;

UDF_HEXTOTEXT

SELECT UDF_TEXTTOHEX(DEPT_NAME), UDF_HEXTOTEXT(UDF_TEXTTOHEX(DEPT_NAME)),* FROM TBL_DEPARTMENTS_01 EMIT CHANGES;

UDF_FILTERARRAYLIST

SELECT CUSTOMERID, ORDERDATA, UDF_FILTERARRAYLIST(ORDERDATA, 3, 4)
FROM STM_ARRAY_DEMO_0030 EMIT CHANGES;

License

See LICENSE for licensing information.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages