string_word_count(cudf::column_view const& strs);
diff --git a/udf-examples/src/main/java/com/nvidia/spark/rapids/udf/hive/DecimalFraction.java b/udf-examples/src/main/java/com/nvidia/spark/rapids/udf/hive/DecimalFraction.java
deleted file mode 100644
index 4c9b48ccf60..00000000000
--- a/udf-examples/src/main/java/com/nvidia/spark/rapids/udf/hive/DecimalFraction.java
+++ /dev/null
@@ -1,101 +0,0 @@
-/*
- * Copyright (c) 2021, NVIDIA CORPORATION.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.nvidia.spark.rapids.udf.hive;
-
-import ai.rapids.cudf.ColumnVector;
-import ai.rapids.cudf.Scalar;
-import com.nvidia.spark.RapidsUDF;
-import org.apache.hadoop.hive.common.type.HiveDecimal;
-import org.apache.hadoop.hive.ql.exec.UDFArgumentException;
-import org.apache.hadoop.hive.ql.metadata.HiveException;
-import org.apache.hadoop.hive.ql.udf.generic.GenericUDF;
-import org.apache.hadoop.hive.serde2.io.HiveDecimalWritable;
-import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector;
-import org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector;
-import org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory;
-import org.apache.hadoop.hive.serde2.typeinfo.DecimalTypeInfo;
-
-import java.math.BigDecimal;
-
-
-/**
- * A simple HiveGenericUDF demo for DecimalType, which extracts and returns
- * the fraction part of the input Decimal data. So, the output data has the
- * same precision and scale as the input one.
- */
-public class DecimalFraction extends GenericUDF implements RapidsUDF {
- private transient PrimitiveObjectInspector inputOI;
-
- @Override
- public String getDisplayString(String[] strings) {
- return getStandardDisplayString("DecimalFraction", strings);
- }
-
- @Override
- public ObjectInspector initialize(ObjectInspector[] arguments) throws UDFArgumentException {
- if (arguments.length != 1) {
- throw new UDFArgumentException("One argument is supported, found: " + arguments.length);
- }
- if (!(arguments[0] instanceof PrimitiveObjectInspector)) {
- throw new UDFArgumentException("Unsupported argument type: " + arguments[0].getTypeName());
- }
-
- inputOI = (PrimitiveObjectInspector) arguments[0];
- if (inputOI.getPrimitiveCategory() != PrimitiveObjectInspector.PrimitiveCategory.DECIMAL) {
- throw new UDFArgumentException("Unsupported primitive type: " + inputOI.getPrimitiveCategory());
- }
-
- DecimalTypeInfo inputTypeInfo = (DecimalTypeInfo) inputOI.getTypeInfo();
-
- return PrimitiveObjectInspectorFactory.getPrimitiveWritableObjectInspector(inputTypeInfo);
- }
-
- @Override
- public Object evaluate(GenericUDF.DeferredObject[] arguments) throws HiveException {
- if (arguments[0] == null || arguments[0].get() == null) {
- return null;
- }
-
- Object input = arguments[0].get();
- HiveDecimalWritable decimalWritable = (HiveDecimalWritable) inputOI.getPrimitiveWritableObject(input);
- BigDecimal decimalInput = decimalWritable.getHiveDecimal().bigDecimalValue();
- BigDecimal decimalResult = decimalInput.subtract(new BigDecimal(decimalInput.toBigInteger()));
- HiveDecimalWritable result = new HiveDecimalWritable(decimalWritable);
- result.set(HiveDecimal.create(decimalResult));
-
- return result;
- }
-
- @Override
- public ColumnVector evaluateColumnar(ColumnVector... args) {
- if (args.length != 1) {
- throw new IllegalArgumentException("Unexpected argument count: " + args.length);
- }
- ColumnVector input = args[0];
- if (!input.getType().isDecimalType()) {
- throw new IllegalArgumentException("Argument type is not a decimal column: " +
- input.getType());
- }
-
- try (Scalar nullScalar = Scalar.fromNull(input.getType());
- ColumnVector nullPredicate = input.isNull();
- ColumnVector integral = input.floor();
- ColumnVector fraction = input.sub(integral, input.getType())) {
- return nullPredicate.ifElse(nullScalar, fraction);
- }
- }
-}
diff --git a/udf-examples/src/main/java/com/nvidia/spark/rapids/udf/hive/StringWordCount.java b/udf-examples/src/main/java/com/nvidia/spark/rapids/udf/hive/StringWordCount.java
deleted file mode 100644
index 89cbfdcaa6a..00000000000
--- a/udf-examples/src/main/java/com/nvidia/spark/rapids/udf/hive/StringWordCount.java
+++ /dev/null
@@ -1,83 +0,0 @@
-/*
- * Copyright (c) 2021, NVIDIA CORPORATION.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.nvidia.spark.rapids.udf.hive;
-
-import ai.rapids.cudf.ColumnVector;
-import ai.rapids.cudf.DType;
-import ai.rapids.cudf.NativeDepsLoader;
-import com.nvidia.spark.RapidsUDF;
-import com.nvidia.spark.rapids.udf.java.NativeUDFExamplesLoader;
-import org.apache.hadoop.hive.ql.exec.UDF;
-
-import java.io.IOException;
-
-/**
- * A user-defined function (UDF) that counts the words in a string.
- * This avoids the manifestation of intermediate results required when
- * splitting the string on whitespace and counting the split results.
- *
- * This class demonstrates how to implement a Hive UDF with a RAPIDS
- * implementation that uses custom native code.
- */
-public class StringWordCount extends UDF implements RapidsUDF {
- private volatile boolean isNativeCodeLoaded = false;
-
- /** Row-by-row implementation that executes on the CPU */
- public Integer evaluate(String str) {
- if (str == null) {
- return null;
- }
-
- int numWords = 0;
- // run of whitespace is considered a single delimiter
- boolean spaces = true;
- for (int idx = 0; idx < str.length(); idx++) {
- char ch = str.charAt(idx);
- if (spaces != (ch <= ' ')) {
- if (spaces) {
- numWords++;
- }
- spaces = !spaces;
- }
- }
- return numWords;
- }
-
- /** Columnar implementation that runs on the GPU */
- @Override
- public ColumnVector evaluateColumnar(ColumnVector... args) {
- // The CPU implementation takes a single string argument, so similarly
- // there should only be one column argument of type STRING.
- if (args.length != 1) {
- throw new IllegalArgumentException("Unexpected argument count: " + args.length);
- }
- ColumnVector strs = args[0];
- if (!strs.getType().equals(DType.STRING)) {
- throw new IllegalArgumentException("type mismatch, expected strings but found " +
- strs.getType());
- }
-
- // Load the native code if it has not been already loaded. This is done here
- // rather than in a static code block since the driver may not have the
- // required CUDA environment.
- NativeUDFExamplesLoader.ensureLoaded();
-
- return new ColumnVector(countWords(strs.getNativeView()));
- }
-
- private static native long countWords(long stringsView);
-}
diff --git a/udf-examples/src/main/java/com/nvidia/spark/rapids/udf/hive/URLDecode.java b/udf-examples/src/main/java/com/nvidia/spark/rapids/udf/hive/URLDecode.java
deleted file mode 100644
index 4aa1dae0af7..00000000000
--- a/udf-examples/src/main/java/com/nvidia/spark/rapids/udf/hive/URLDecode.java
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
- * Copyright (c) 2020-2021, NVIDIA CORPORATION.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.nvidia.spark.rapids.udf.hive;
-
-import ai.rapids.cudf.ColumnVector;
-import ai.rapids.cudf.DType;
-import ai.rapids.cudf.Scalar;
-import com.nvidia.spark.RapidsUDF;
-import org.apache.hadoop.hive.ql.exec.UDF;
-
-import java.io.UnsupportedEncodingException;
-import java.net.URLDecoder;
-
-/**
- * A Hive user-defined function (UDF) that decodes URL-encoded strings.
- * This class demonstrates how to implement a simple Hive UDF that also
- * provides a RAPIDS implementation that can run on the GPU when the query
- * is executed with the RAPIDS Accelerator for Apache Spark.
- */
-public class URLDecode extends UDF implements RapidsUDF {
-
- /** Row-by-row implementation that executes on the CPU */
- public String evaluate(String s) {
- String result = null;
- if (s != null) {
- try {
- result = URLDecoder.decode(s, "utf-8");
- } catch (IllegalArgumentException ignored) {
- result = s;
- } catch (UnsupportedEncodingException e) {
- // utf-8 is a builtin, standard encoding, so this should never happen
- throw new RuntimeException(e);
- }
- }
- return result;
- }
-
- /** Columnar implementation that runs on the GPU */
- @Override
- public ColumnVector evaluateColumnar(ColumnVector... args) {
- // The CPU implementation takes a single string argument, so similarly
- // there should only be one column argument of type STRING.
- if (args.length != 1) {
- throw new IllegalArgumentException("Unexpected argument count: " + args.length);
- }
- ColumnVector input = args[0];
- if (!input.getType().equals(DType.STRING)) {
- throw new IllegalArgumentException("Argument type is not a string column: " +
- input.getType());
- }
-
- // The cudf urlDecode does not convert '+' to a space, so do that as a pre-pass first.
- // All intermediate results are closed to avoid leaking GPU resources.
- try (Scalar plusScalar = Scalar.fromString("+");
- Scalar spaceScalar = Scalar.fromString(" ");
- ColumnVector replaced = input.stringReplace(plusScalar, spaceScalar)) {
- return replaced.urlDecode();
- }
- }
-}
diff --git a/udf-examples/src/main/java/com/nvidia/spark/rapids/udf/hive/URLEncode.java b/udf-examples/src/main/java/com/nvidia/spark/rapids/udf/hive/URLEncode.java
deleted file mode 100644
index fbf302440c6..00000000000
--- a/udf-examples/src/main/java/com/nvidia/spark/rapids/udf/hive/URLEncode.java
+++ /dev/null
@@ -1,110 +0,0 @@
-/*
- * Copyright (c) 2020-2021, NVIDIA CORPORATION.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.nvidia.spark.rapids.udf.hive;
-
-import ai.rapids.cudf.ColumnVector;
-import ai.rapids.cudf.DType;
-import com.nvidia.spark.RapidsUDF;
-import org.apache.hadoop.hive.ql.exec.UDFArgumentException;
-import org.apache.hadoop.hive.ql.metadata.HiveException;
-import org.apache.hadoop.hive.ql.udf.generic.GenericUDF;
-import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector;
-import org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector;
-import org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorConverter;
-import org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory;
-import org.apache.hadoop.io.Text;
-
-import java.io.UnsupportedEncodingException;
-import java.net.URLEncoder;
-
-/**
- * A Hive user-defined function (UDF) that URL-encodes strings.
- * This class demonstrates how to implement a Hive GenericUDF that also
- * provides a RAPIDS implementation that can run on the GPU when the query
- * is executed with the RAPIDS Accelerator for Apache Spark.
- */
-public class URLEncode extends GenericUDF implements RapidsUDF {
- private transient PrimitiveObjectInspectorConverter.TextConverter converter;
- private final Text textResult = new Text();
-
- /** Standard getDisplayString method for implementing GenericUDF */
- @Override
- public String getDisplayString(String[] children) {
- return getStandardDisplayString("urlencode", children);
- }
-
- /** Standard initialize method for implementing GenericUDF for a single string parameter */
- @Override
- public ObjectInspector initialize(ObjectInspector[] arguments) throws UDFArgumentException {
- if (arguments.length != 1) {
- throw new UDFArgumentException("One argument is supported, found: " + arguments.length);
- }
- if (!(arguments[0] instanceof PrimitiveObjectInspector)) {
- throw new UDFArgumentException("Unsupported argument type: " + arguments[0].getTypeName());
- }
- PrimitiveObjectInspector poi = (PrimitiveObjectInspector) arguments[0];
- switch (poi.getPrimitiveCategory()) {
- case STRING:
- case CHAR:
- case VARCHAR:
- break;
- default:
- throw new UDFArgumentException("Unsupported primitive type: " + poi.getPrimitiveCategory());
- }
-
- converter = new PrimitiveObjectInspectorConverter.TextConverter(poi);
- return PrimitiveObjectInspectorFactory.writableStringObjectInspector;
- }
-
- /** Row-by-row implementation that executes on the CPU */
- @Override
- public Object evaluate(GenericUDF.DeferredObject[] arguments) throws HiveException {
- Text text = converter.convert(arguments[0].get());
- if (text == null) {
- return null;
- }
- String encoded;
- try {
- encoded = URLEncoder.encode(text.toString(), "utf-8")
- .replace("+", "%20")
- .replace("*", "%2A")
- .replace("%7E", "~");
- } catch (UnsupportedEncodingException e) {
- // utf-8 is a builtin, standard encoding, so this should never happen
- throw new RuntimeException(e);
- }
- textResult.set(encoded);
- return textResult;
- }
-
- /** Columnar implementation that runs on the GPU */
- @Override
- public ColumnVector evaluateColumnar(ColumnVector... args) {
- // The CPU implementation takes a single string argument, so similarly
- // there should only be one column argument of type STRING.
- if (args.length != 1) {
- throw new IllegalArgumentException("Unexpected argument count: " + args.length);
- }
- ColumnVector input = args[0];
- if (!input.getType().equals(DType.STRING)) {
- throw new IllegalArgumentException("Argument type is not a string column: " +
- input.getType());
- }
-
- return input.urlEncode();
- }
-}
diff --git a/udf-examples/src/main/java/com/nvidia/spark/rapids/udf/java/CosineSimilarity.java b/udf-examples/src/main/java/com/nvidia/spark/rapids/udf/java/CosineSimilarity.java
deleted file mode 100644
index 1702b087d84..00000000000
--- a/udf-examples/src/main/java/com/nvidia/spark/rapids/udf/java/CosineSimilarity.java
+++ /dev/null
@@ -1,79 +0,0 @@
-/*
- * Copyright (c) 2021, NVIDIA CORPORATION.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.nvidia.spark.rapids.udf.java;
-
-import ai.rapids.cudf.ColumnVector;
-import com.nvidia.spark.RapidsUDF;
-import org.apache.spark.sql.api.java.UDF2;
-import scala.collection.mutable.WrappedArray;
-
-/**
- * A Spark Java UDF that computes the cosine similarity between two float vectors.
- * The input vectors must have matching shapes, i.e.: same number of elements.
- * A null vector is supported, but null entries within the vector are not supported.
- */
-public class CosineSimilarity
- implements UDF2, WrappedArray, Float>, RapidsUDF {
-
- /** Row-by-row implementation that executes on the CPU */
- @Override
- public Float call(WrappedArray v1, WrappedArray v2) {
- if (v1 == null || v2 == null) {
- return null;
- }
- if (v1.length() != v2.length()) {
- throw new IllegalArgumentException("Array lengths must match: " +
- v1.length() + " != " + v2.length());
- }
-
- double dotProduct = 0;
- for (int i = 0; i < v1.length(); i++) {
- float f1 = v1.apply(i);
- float f2 = v2.apply(i);
- dotProduct += f1 * f2;
- }
- double magProduct = magnitude(v1) * magnitude(v2);
- return (float) (dotProduct / magProduct);
- }
-
- private double magnitude(WrappedArray v) {
- double sum = 0;
- for (int i = 0; i < v.length(); i++) {
- float x = v.apply(i);
- sum += x * x;
- }
- return Math.sqrt(sum);
- }
-
- /** Columnar implementation that processes data on the GPU */
- @Override
- public ColumnVector evaluateColumnar(ColumnVector... args) {
- if (args.length != 2) {
- throw new IllegalArgumentException("Unexpected argument count: " + args.length);
- }
-
- // Load the native code if it has not been already loaded. This is done here
- // rather than in a static code block since the driver may not have the
- // required CUDA environment.
- NativeUDFExamplesLoader.ensureLoaded();
-
- return new ColumnVector(cosineSimilarity(args[0].getNativeView(), args[1].getNativeView()));
- }
-
- /** Native implementation that computes on the GPU */
- private static native long cosineSimilarity(long vectorView1, long vectorView2);
-}
diff --git a/udf-examples/src/main/java/com/nvidia/spark/rapids/udf/java/DecimalFraction.java b/udf-examples/src/main/java/com/nvidia/spark/rapids/udf/java/DecimalFraction.java
deleted file mode 100644
index 2b6644841dc..00000000000
--- a/udf-examples/src/main/java/com/nvidia/spark/rapids/udf/java/DecimalFraction.java
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * Copyright (c) 2021, NVIDIA CORPORATION.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.nvidia.spark.rapids.udf.java;
-
-import ai.rapids.cudf.ColumnVector;
-import ai.rapids.cudf.Scalar;
-import com.nvidia.spark.RapidsUDF;
-import org.apache.spark.sql.api.java.UDF1;
-
-import java.math.BigDecimal;
-
-/**
- * A simple Java UDF demo for DecimalType, which extracts and returns the
- * fraction part of the input Decimal data. So, the output data has the
- * same precision and scale as the input one.
- */
-public class DecimalFraction implements UDF1, RapidsUDF {
-
- @Override
- public BigDecimal call(BigDecimal dec) throws Exception {
- if (dec == null) {
- return null;
- }
- BigDecimal integral = new BigDecimal(dec.toBigInteger());
- return dec.subtract(integral);
- }
-
- @Override
- public ColumnVector evaluateColumnar(ColumnVector... args) {
- if (args.length != 1) {
- throw new IllegalArgumentException("Unexpected argument count: " + args.length);
- }
- ColumnVector input = args[0];
- if (!input.getType().isDecimalType()) {
- throw new IllegalArgumentException("Argument type is not a decimal column: " +
- input.getType());
- }
-
- try (Scalar nullScalar = Scalar.fromNull(input.getType());
- ColumnVector nullPredicate = input.isNull();
- ColumnVector integral = input.floor();
- ColumnVector fraction = input.sub(integral, input.getType())) {
- return nullPredicate.ifElse(nullScalar, fraction);
- }
- }
-}
diff --git a/udf-examples/src/main/java/com/nvidia/spark/rapids/udf/java/NativeUDFExamplesLoader.java b/udf-examples/src/main/java/com/nvidia/spark/rapids/udf/java/NativeUDFExamplesLoader.java
deleted file mode 100644
index 844f9a0d5ef..00000000000
--- a/udf-examples/src/main/java/com/nvidia/spark/rapids/udf/java/NativeUDFExamplesLoader.java
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * Copyright (c) 2021, NVIDIA CORPORATION.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.nvidia.spark.rapids.udf.java;
-
-import ai.rapids.cudf.NativeDepsLoader;
-
-import java.io.IOException;
-
-/** Loads the native dependencies for UDF examples with a native implementation */
-public class NativeUDFExamplesLoader {
- private static boolean isLoaded;
-
- /** Loads native UDF code if necessary */
- public static synchronized void ensureLoaded() {
- if (!isLoaded) {
- try {
- NativeDepsLoader.loadNativeDeps(new String[]{"udfexamplesjni"});
- isLoaded = true;
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
- }
- }
-}
diff --git a/udf-examples/src/main/java/com/nvidia/spark/rapids/udf/java/URLDecode.java b/udf-examples/src/main/java/com/nvidia/spark/rapids/udf/java/URLDecode.java
deleted file mode 100644
index b5dbfd30b91..00000000000
--- a/udf-examples/src/main/java/com/nvidia/spark/rapids/udf/java/URLDecode.java
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
- * Copyright (c) 2021, NVIDIA CORPORATION.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.nvidia.spark.rapids.udf.java;
-
-import ai.rapids.cudf.ColumnVector;
-import ai.rapids.cudf.DType;
-import ai.rapids.cudf.Scalar;
-import com.nvidia.spark.RapidsUDF;
-import org.apache.spark.sql.api.java.UDF1;
-
-import java.io.UnsupportedEncodingException;
-import java.net.URLDecoder;
-
-/**
- * A Java user-defined function (UDF) that decodes URL-encoded strings.
- * This class demonstrates how to implement a Java UDF that also
- * provides a RAPIDS implementation that can run on the GPU when the query
- * is executed with the RAPIDS Accelerator for Apache Spark.
- */
-public class URLDecode implements UDF1, RapidsUDF {
- /** Row-by-row implementation that executes on the CPU */
- @Override
- public String call(String s) {
- String result = null;
- if (s != null) {
- try {
- result = URLDecoder.decode(s, "utf-8");
- } catch (IllegalArgumentException ignored) {
- result = s;
- } catch (UnsupportedEncodingException e) {
- // utf-8 is a builtin, standard encoding, so this should never happen
- throw new RuntimeException(e);
- }
- }
- return result;
- }
-
- /** Columnar implementation that runs on the GPU */
- @Override
- public ColumnVector evaluateColumnar(ColumnVector... args) {
- // The CPU implementation takes a single string argument, so similarly
- // there should only be one column argument of type STRING.
- if (args.length != 1) {
- throw new IllegalArgumentException("Unexpected argument count: " + args.length);
- }
- ColumnVector input = args[0];
- if (!input.getType().equals(DType.STRING)) {
- throw new IllegalArgumentException("Argument type is not a string column: " +
- input.getType());
- }
-
- // The cudf urlDecode does not convert '+' to a space, so do that as a pre-pass first.
- // All intermediate results are closed to avoid leaking GPU resources.
- try (Scalar plusScalar = Scalar.fromString("+");
- Scalar spaceScalar = Scalar.fromString(" ");
- ColumnVector replaced = input.stringReplace(plusScalar, spaceScalar)) {
- return replaced.urlDecode();
- }
- }
-}
diff --git a/udf-examples/src/main/java/com/nvidia/spark/rapids/udf/java/URLEncode.java b/udf-examples/src/main/java/com/nvidia/spark/rapids/udf/java/URLEncode.java
deleted file mode 100644
index 810d99aec5f..00000000000
--- a/udf-examples/src/main/java/com/nvidia/spark/rapids/udf/java/URLEncode.java
+++ /dev/null
@@ -1,67 +0,0 @@
-/*
- * Copyright (c) 2021, NVIDIA CORPORATION.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.nvidia.spark.rapids.udf.java;
-
-import ai.rapids.cudf.ColumnVector;
-import ai.rapids.cudf.DType;
-import com.nvidia.spark.RapidsUDF;
-import org.apache.spark.sql.api.java.UDF1;
-
-import java.io.UnsupportedEncodingException;
-import java.net.URLEncoder;
-
-/**
- * A Java user-defined function (UDF) that URL-encodes strings.
- * This class demonstrates how to implement a Java UDF that also
- * provides a RAPIDS implementation that can run on the GPU when the query
- * is executed with the RAPIDS Accelerator for Apache Spark.
- */
-public class URLEncode implements UDF1, RapidsUDF {
- /** Row-by-row implementation that executes on the CPU */
- @Override
- public String call(String s) {
- if (s == null) {
- return null;
- }
- try {
- return URLEncoder.encode(s, "utf-8")
- .replace("+", "%20")
- .replace("*", "%2A")
- .replace("%7E", "~");
- } catch (UnsupportedEncodingException e) {
- // utf-8 is a builtin, standard encoding, so this should never happen
- throw new RuntimeException(e);
- }
- }
-
- /** Columnar implementation that runs on the GPU */
- @Override
- public ColumnVector evaluateColumnar(ColumnVector... args) {
- // The CPU implementation takes a single string argument, so similarly
- // there should only be one column argument of type STRING.
- if (args.length != 1) {
- throw new IllegalArgumentException("Unexpected argument count: " + args.length);
- }
- ColumnVector input = args[0];
- if (!input.getType().equals(DType.STRING)) {
- throw new IllegalArgumentException("Argument type is not a string column: " +
- input.getType());
- }
-
- return input.urlEncode();
- }
-}