|
| 1 | +/* |
| 2 | + * CompilableSqlFunctionTest.java |
| 3 | + * |
| 4 | + * This source file is part of the FoundationDB open source project |
| 5 | + * |
| 6 | + * Copyright 2021-2025 Apple Inc. and the FoundationDB project authors |
| 7 | + * |
| 8 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 9 | + * you may not use this file except in compliance with the License. |
| 10 | + * You may obtain a copy of the License at |
| 11 | + * |
| 12 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 13 | + * |
| 14 | + * Unless required by applicable law or agreed to in writing, software |
| 15 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 16 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 17 | + * See the License for the specific language governing permissions and |
| 18 | + * limitations under the License. |
| 19 | + */ |
| 20 | + |
| 21 | +package com.apple.foundationdb.relational.recordlayer.query.functions; |
| 22 | + |
| 23 | +import com.apple.foundationdb.record.RecordCoreException; |
| 24 | +import com.apple.foundationdb.record.query.plan.cascades.expressions.RelationalExpression; |
| 25 | +import com.apple.foundationdb.record.query.plan.cascades.expressions.SelectExpression; |
| 26 | +import com.apple.foundationdb.relational.recordlayer.query.Literals; |
| 27 | +import com.google.common.collect.ImmutableList; |
| 28 | +import org.junit.jupiter.api.Assertions; |
| 29 | +import org.junit.jupiter.api.Test; |
| 30 | + |
| 31 | +import javax.annotation.Nonnull; |
| 32 | +import java.util.Optional; |
| 33 | + |
| 34 | +/** |
| 35 | + * Tests for {@link CompilableSqlFunction}. |
| 36 | + */ |
| 37 | +class CompilableSqlFunctionTest { |
| 38 | + |
| 39 | + @Test |
| 40 | + void toProtoThrowsRecordCoreException() { |
| 41 | + final var function = createTestFunction(); |
| 42 | + |
| 43 | + final var exception = Assertions.assertThrows(RecordCoreException.class, function::toProto); |
| 44 | + |
| 45 | + Assertions.assertNotNull(exception); |
| 46 | + Assertions.assertEquals("attempt to serialize compiled SQL function", exception.getMessage()); |
| 47 | + } |
| 48 | + |
| 49 | + /** |
| 50 | + * Creates a simple test function with basic parameters. |
| 51 | + */ |
| 52 | + @Nonnull |
| 53 | + private CompilableSqlFunction createTestFunction() { |
| 54 | + return new CompilableSqlFunction( |
| 55 | + "testFunction", |
| 56 | + ImmutableList.of("param1", "param2"), |
| 57 | + ImmutableList.of( |
| 58 | + com.apple.foundationdb.record.query.plan.cascades.typing.Type.primitiveType( |
| 59 | + com.apple.foundationdb.record.query.plan.cascades.typing.Type.TypeCode.INT), |
| 60 | + com.apple.foundationdb.record.query.plan.cascades.typing.Type.primitiveType( |
| 61 | + com.apple.foundationdb.record.query.plan.cascades.typing.Type.TypeCode.STRING) |
| 62 | + ), |
| 63 | + ImmutableList.of(Optional.empty(), Optional.empty()), |
| 64 | + Optional.of(com.apple.foundationdb.record.query.plan.cascades.CorrelationIdentifier.of("test")), |
| 65 | + createDummyBody(), |
| 66 | + Literals.empty() |
| 67 | + ); |
| 68 | + } |
| 69 | + |
| 70 | + /** |
| 71 | + * Creates a dummy relational expression to use as function body. |
| 72 | + */ |
| 73 | + @Nonnull |
| 74 | + private RelationalExpression createDummyBody() { |
| 75 | + // Create a minimal SelectExpression as the function body |
| 76 | + return new SelectExpression( |
| 77 | + com.apple.foundationdb.record.query.plan.cascades.values.RecordConstructorValue.ofUnnamed(ImmutableList.of()), |
| 78 | + ImmutableList.of(), |
| 79 | + ImmutableList.of() |
| 80 | + ); |
| 81 | + } |
| 82 | +} |
0 commit comments