1

I'm writing a Java Spark application and I'm trying to write a unit test for one of my UDFs. This UDF accept Array of String and return Long:

protected UDF1<WrappedArray<String>, Long> convertMyArray() {
    return (WrappedArray<String> s) -> {
        
        return ...;
    };
}

When I test it with a Spark session, the logic works fine. my problem is how can I unittest this logic.

 @Test
    public void arrayConversion() throws Exception {
        ArrayList<String> inputName = new ArrayList<String>() {
            {
                add("Inp1");
                add("Inp2");
            }
        };

        assertEquals(5, myUDF.convertMyArray().call(...);
        
    }

How can I convert inputName into wappedArray. I can not just simply pass inputName into my UDF call because of input mismatch.

I have also tried to use make based on WrappedArray.scala::Make

WrappedArray<String> stringInput = WrappedArray.make(inputName);

But I still get run time error:

scala.MatchError: [Inp1, Inp2] when using make
2
  • 1
    The companion object in WrappedArray.scala has a make method. Is that method showing up in your setup? Commented Aug 3, 2021 at 17:09
  • @aksappy I am getting scala.MatchError: [Inp1, Inp2] when using make Commented Aug 3, 2021 at 19:25

1 Answer 1

4

You are constructing a Java ArrayList, which isn't an array but a Java collection.

You can convert it to a WrappedArray with

WrappedArray<String> stringInput = WrappedArray.make(inputName.toArray(new String[0]))
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.