Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangstar333 committed Oct 12, 2024
1 parent efdd60a commit e25841c
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1270,7 +1270,7 @@ public static long copyBatchArrayStringResult(long hasPutElementNum, boolean isN
offset += byteRes[i].length;
offsets[i] = offset;
}
int oldSzie = 0;
int oldSzie = oldOffsetNum;
if (num > 0) {
oldSzie = offsets[num - 1];
}
Expand Down Expand Up @@ -1305,11 +1305,11 @@ public static long copyBatchArrayStringResult(long hasPutElementNum, boolean isN
offset += byteRes[i].length;
offsets[i] = offset;
}
int oldSzie = 0;
int oldSzie = oldOffsetNum;
if (num > 0) {
oldSzie = offsets[num - 1];
}
byte[] bytes = new byte[oldSzie];
byte[] bytes = new byte[oldSzie - oldOffsetNum];
long bytesAddr = JNINativeMethod.resizeStringColumn(dataAddr, oldSzie);
int dst = 0;
for (int i = 0; i < num; i++) {
Expand Down
12 changes: 12 additions & 0 deletions regression-test/data/javaudf_p0/test_javaudf_array.out
Original file line number Diff line number Diff line change
Expand Up @@ -131,3 +131,15 @@ a10b10 20
["2022-01-01"] 18
["2022-06-06"] 20

-- !select_14 --
["111", "aaa", null] 1
[] 2
[] 3
[] 4
[] 5
[] 6
[] 7
[] 8
[] 9
[] 10

Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// 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 org.apache.doris.udf;

import java.util.ArrayList;

public class ArrayReturnArrayStringTest2 {
public ArrayList<String> evaluate(Integer res) {
ArrayList<String> result = new ArrayList<String>();
if (res == null) {
return null;
}
switch (res.intValue()) {
case 1: {
result.add("111");
result.add("aaa");
result.add(null);
}
break;
default:
break;
}
return result;
}
}
9 changes: 9 additions & 0 deletions regression-test/suites/javaudf_p0/test_javaudf_array.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,19 @@ suite("test_javaudf_array") {
); """
qt_select_13 """ SELECT java_udf_array_date_test(array(datev2_col)), tinyint_col as result FROM ${tableName} ORDER BY result; """

sql """ DROP FUNCTION IF EXISTS java_udf_array_return_string_test2(array<string>); """
sql """ CREATE FUNCTION java_udf_array_return_string_test2(int) RETURNS array<string> PROPERTIES (
"file"="file://${jarPath}",
"symbol"="org.apache.doris.udf.ArrayReturnArrayStringTest2",
"type"="JAVA_UDF"
); """
qt_select_14 """ SELECT java_udf_array_return_string_test2(user_id), user_id as result FROM ${tableName} ORDER BY result; """

} finally {
try_sql("DROP FUNCTION IF EXISTS java_udf_array_int_test(array<int>);")
try_sql("DROP FUNCTION IF EXISTS java_udf_array_return_int_test(array<int>);")
try_sql("DROP FUNCTION IF EXISTS java_udf_array_return_string_test(array<string>);")
try_sql("DROP FUNCTION IF EXISTS java_udf_array_return_string_test2(int);")
try_sql("DROP FUNCTION IF EXISTS java_udf_array_string_test(array<string>);")
try_sql("DROP FUNCTION IF EXISTS java_udf_array_datatime_test(array<datetime>);")
try_sql("DROP FUNCTION IF EXISTS java_udf_array_date_test(array<date>);")
Expand Down

0 comments on commit e25841c

Please sign in to comment.