Skip to content
This repository has been archived by the owner on Sep 18, 2023. It is now read-only.

[NSE-1007] Add a test guide for columnar UDF #1006

Merged
merged 1 commit into from
Jul 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions tests/udf/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@

## Hive UDF Test Guide

Currently, Gazelle supports a UDF called URLDecoder whose original implementation is under `src/`.
To test a UDF, we should compile the original hive UDF code into a jar and put it into spark classpath.

Take URLDecoder as example.

1. Compile original Hive UDF code with `hive-exec` dependency provided.

2. Deploy the jar and configure it into Spark classpath. We can deploy it with Gazelle jar and make
the below configuration to include them in spark classpath.

```
--conf spark.driver.extraClassPath="YOUR_JAR_PATH"
--conf spark.executor.extraClassPath="YOUR_JAR_PATH"
```

3. Register the UDF to Spark.

```
spark.sql("CREATE TEMPORARY FUNCTION URLDecoder AS 'com.intel.oap.URLDecoderNew';")
```

4. Run SQL with UrlDecoder used.

```
spark.sql("SELECT UrlDecoder(<YOUR_COL>) from <YOUR_TABLE>;")
```
36 changes: 36 additions & 0 deletions tests/udf/src/com/intel/oap/URLDecoderNew.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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.intel.oap;

import java.net.URLDecoder;
import org.apache.hadoop.hive.ql.exec.UDF;

public class URLDecoderNew extends UDF {

public String evaluate(String b) {
if (b == null) {
return null;
}
try {
return URLDecoder.decode(b, "utf-8");
} catch (Exception e) {
e.printStackTrace();
return b;
}
}
}