New in Snowflake: Java UDFs (with a Kotlin NLP example)

Snowflake now let’s you easily create Java UDFs, which is an incredibly powerful and versatile feature. Let’s check it out with by running a library written in Kotlin — to detect written languages. Out of GitHub and into your SQL code, in 3 easy steps.

Felipe Hoffa
Jun 16 · 3 min read
Detect written languages with a Java UDF

Quick example: Detect written languages

create function add(x integer, y integer)
returns integer
language java
class Test {
public static int add(int x, int y) {
return x + y;
select add(1, 3)// 4
create or replace function detect_lang(x string)
returns string
language java
imports = ('@~/lingua-1.1.0-with-dependencies.jar')
import com.github.pemistahl.lingua.api.*;
import static com.github.pemistahl.lingua.api.Language.*;
class MyClass {
static LanguageDetector detector = LanguageDetectorBuilder.fromLanguages(ENGLISH, FRENCH, GERMAN, SPANISH).build();
public static String detect(String x) {
return detector.detectLanguageOf(x).toString();
select $1, detect_lang($1)
from values('languages are awesome'),('hola mi amigo'),('hallo Freunde'),('je ne parle pas');



git clone
./gradlew jarWithDependencies
put 'file://build/libs/lingua-1.1.0-with-dependencies.jar' @~;

Read more


Want more?


Articles for engineers, by engineers.