|
| 1 | +// Copyright 2021-present StarRocks, Inc. All rights reserved. |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// https://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +package com.starrocks.analysis; |
| 16 | + |
| 17 | +import com.google.common.collect.Lists; |
| 18 | +import com.starrocks.catalog.AggregateFunction; |
| 19 | +import com.starrocks.catalog.ScalarFunction; |
| 20 | +import com.starrocks.catalog.Type; |
| 21 | +import com.starrocks.thrift.TFunctionBinaryType; |
| 22 | +import org.junit.jupiter.api.Assertions; |
| 23 | +import org.junit.jupiter.api.Test; |
| 24 | + |
| 25 | +// Regression coverage for the Properties shown by SHOW [FULL] FUNCTIONS (Function#getProperties) |
| 26 | +// exposing the "isolation" entry so users can tell whether a UDF/UDAF was created with |
| 27 | +// isolation = "shared". isolationType == false means shared; true (default) means isolated. |
| 28 | +public class ShowFunctionsIsolationTest { |
| 29 | + |
| 30 | + private static ScalarFunction scalarUdf(boolean isolationType) { |
| 31 | + Type[] args = new Type[] {Type.INT}; |
| 32 | + return ScalarFunction.createUdf(new FunctionName("db", "my_udf"), args, Type.INT, |
| 33 | + false, TFunctionBinaryType.SRJAR, "objectFile", "symbol", "", "", isolationType); |
| 34 | + } |
| 35 | + |
| 36 | + private static AggregateFunction aggregateUdf(boolean isolationType) { |
| 37 | + AggregateFunction fn = new AggregateFunction(new FunctionName("db", "my_agg"), |
| 38 | + Lists.newArrayList(Type.INT), Type.INT, Type.INT, false); |
| 39 | + fn.setBinaryType(TFunctionBinaryType.SRJAR); |
| 40 | + fn.setIsolationType(isolationType); |
| 41 | + return fn; |
| 42 | + } |
| 43 | + |
| 44 | + @Test |
| 45 | + public void testSharedScalarFunctionShowsIsolation() { |
| 46 | + String props = scalarUdf(false).getProperties(); |
| 47 | + Assertions.assertTrue(props.contains("\"isolation\":\"shared\""), props); |
| 48 | + } |
| 49 | + |
| 50 | + @Test |
| 51 | + public void testIsolatedScalarFunctionShowsIsolation() { |
| 52 | + String props = scalarUdf(true).getProperties(); |
| 53 | + Assertions.assertTrue(props.contains("\"isolation\":\"isolated\""), props); |
| 54 | + } |
| 55 | + |
| 56 | + @Test |
| 57 | + public void testSharedAggregateFunctionShowsIsolation() { |
| 58 | + String props = aggregateUdf(false).getProperties(); |
| 59 | + Assertions.assertTrue(props.contains("\"isolation\":\"shared\""), props); |
| 60 | + } |
| 61 | + |
| 62 | + @Test |
| 63 | + public void testIsolatedAggregateFunctionShowsIsolation() { |
| 64 | + String props = aggregateUdf(true).getProperties(); |
| 65 | + Assertions.assertTrue(props.contains("\"isolation\":\"isolated\""), props); |
| 66 | + } |
| 67 | +} |
0 commit comments