generated from amazon-archives/__template_Custom
-
Notifications
You must be signed in to change notification settings - Fork 188
Fix multisearch UDT type loss through UNION (#5145, #5146, #5147) #5154
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ahkcs
wants to merge
4
commits into
opensearch-project:main
Choose a base branch
from
ahkcs:fix/multisearch-issues-5145-5146-5147
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+261
−3
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
131 changes: 131 additions & 0 deletions
131
core/src/test/java/org/opensearch/sql/calcite/utils/OpenSearchTypeFactoryTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,131 @@ | ||
| /* | ||
| * Copyright OpenSearch Contributors | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| package org.opensearch.sql.calcite.utils; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
| import static org.junit.jupiter.api.Assertions.assertInstanceOf; | ||
| import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
| import static org.junit.jupiter.api.Assertions.assertTrue; | ||
| import static org.opensearch.sql.calcite.utils.OpenSearchTypeFactory.TYPE_FACTORY; | ||
|
|
||
| import java.util.List; | ||
| import org.apache.calcite.rel.type.RelDataType; | ||
| import org.apache.calcite.sql.type.SqlTypeName; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.opensearch.sql.calcite.type.AbstractExprRelDataType; | ||
| import org.opensearch.sql.calcite.utils.OpenSearchTypeFactory.ExprUDT; | ||
|
|
||
| public class OpenSearchTypeFactoryTest { | ||
|
|
||
| @Test | ||
| public void testLeastRestrictivePreservesUdtWhenAllInputsSameUdt() { | ||
| RelDataType ts1 = TYPE_FACTORY.createUDT(ExprUDT.EXPR_TIMESTAMP); | ||
| RelDataType ts2 = TYPE_FACTORY.createUDT(ExprUDT.EXPR_TIMESTAMP); | ||
|
|
||
| RelDataType result = TYPE_FACTORY.leastRestrictive(List.of(ts1, ts2)); | ||
|
|
||
| assertNotNull(result); | ||
| assertInstanceOf(AbstractExprRelDataType.class, result); | ||
| assertEquals(ExprUDT.EXPR_TIMESTAMP, ((AbstractExprRelDataType<?>) result).getUdt()); | ||
| } | ||
|
|
||
| @Test | ||
| public void testLeastRestrictivePreservesUdtForDateType() { | ||
| RelDataType d1 = TYPE_FACTORY.createUDT(ExprUDT.EXPR_DATE); | ||
| RelDataType d2 = TYPE_FACTORY.createUDT(ExprUDT.EXPR_DATE); | ||
|
|
||
| RelDataType result = TYPE_FACTORY.leastRestrictive(List.of(d1, d2)); | ||
|
|
||
| assertNotNull(result); | ||
| assertInstanceOf(AbstractExprRelDataType.class, result); | ||
| assertEquals(ExprUDT.EXPR_DATE, ((AbstractExprRelDataType<?>) result).getUdt()); | ||
| } | ||
|
|
||
| @Test | ||
| public void testLeastRestrictivePreservesUdtForThreeInputs() { | ||
| RelDataType ts1 = TYPE_FACTORY.createUDT(ExprUDT.EXPR_TIMESTAMP); | ||
| RelDataType ts2 = TYPE_FACTORY.createUDT(ExprUDT.EXPR_TIMESTAMP); | ||
| RelDataType ts3 = TYPE_FACTORY.createUDT(ExprUDT.EXPR_TIMESTAMP); | ||
|
|
||
| RelDataType result = TYPE_FACTORY.leastRestrictive(List.of(ts1, ts2, ts3)); | ||
|
|
||
| assertNotNull(result); | ||
| assertInstanceOf(AbstractExprRelDataType.class, result); | ||
| assertEquals(ExprUDT.EXPR_TIMESTAMP, ((AbstractExprRelDataType<?>) result).getUdt()); | ||
| } | ||
|
|
||
| @Test | ||
| public void testLeastRestrictiveReturnsNullableWhenAnyInputIsNullable() { | ||
| RelDataType nonNullable = TYPE_FACTORY.createUDT(ExprUDT.EXPR_TIMESTAMP, false); | ||
| RelDataType nullable = TYPE_FACTORY.createUDT(ExprUDT.EXPR_TIMESTAMP, true); | ||
|
|
||
| RelDataType result = TYPE_FACTORY.leastRestrictive(List.of(nonNullable, nullable)); | ||
|
|
||
| assertNotNull(result); | ||
| assertInstanceOf(AbstractExprRelDataType.class, result); | ||
| assertEquals(ExprUDT.EXPR_TIMESTAMP, ((AbstractExprRelDataType<?>) result).getUdt()); | ||
| assertTrue(result.isNullable()); | ||
| } | ||
|
|
||
| @Test | ||
| public void testLeastRestrictiveReturnsNullableWhenFirstNullableSecondNot() { | ||
| RelDataType nullable = TYPE_FACTORY.createUDT(ExprUDT.EXPR_TIMESTAMP, true); | ||
| RelDataType nonNullable = TYPE_FACTORY.createUDT(ExprUDT.EXPR_TIMESTAMP, false); | ||
|
|
||
| RelDataType result = TYPE_FACTORY.leastRestrictive(List.of(nullable, nonNullable)); | ||
|
|
||
| assertNotNull(result); | ||
| assertInstanceOf(AbstractExprRelDataType.class, result); | ||
| assertTrue(result.isNullable()); | ||
| } | ||
|
|
||
| @Test | ||
| public void testLeastRestrictiveFallsBackForMixedUdtAndNonUdt() { | ||
| RelDataType udt = TYPE_FACTORY.createUDT(ExprUDT.EXPR_TIMESTAMP); | ||
| RelDataType plain = TYPE_FACTORY.createSqlType(SqlTypeName.VARCHAR); | ||
|
|
||
| RelDataType result = TYPE_FACTORY.leastRestrictive(List.of(udt, plain)); | ||
|
|
||
| // Falls back to super.leastRestrictive which may return a plain type or null | ||
| if (result != null) { | ||
| assertEquals(SqlTypeName.VARCHAR, result.getSqlTypeName()); | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| public void testLeastRestrictiveFallsBackForDifferentUdts() { | ||
| RelDataType timestamp = TYPE_FACTORY.createUDT(ExprUDT.EXPR_TIMESTAMP); | ||
| RelDataType date = TYPE_FACTORY.createUDT(ExprUDT.EXPR_DATE); | ||
|
|
||
| RelDataType result = TYPE_FACTORY.leastRestrictive(List.of(timestamp, date)); | ||
|
|
||
| // Different UDTs — falls back to super.leastRestrictive | ||
| if (result != null) { | ||
| assertEquals(SqlTypeName.VARCHAR, result.getSqlTypeName()); | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| public void testLeastRestrictiveDelegatesToSuperForSingleType() { | ||
| RelDataType single = TYPE_FACTORY.createSqlType(SqlTypeName.INTEGER); | ||
|
|
||
| RelDataType result = TYPE_FACTORY.leastRestrictive(List.of(single)); | ||
|
|
||
| assertNotNull(result); | ||
| assertEquals(SqlTypeName.INTEGER, result.getSqlTypeName()); | ||
| } | ||
|
|
||
| @Test | ||
| public void testLeastRestrictiveDelegatesToSuperForPlainTypes() { | ||
| RelDataType int1 = TYPE_FACTORY.createSqlType(SqlTypeName.INTEGER); | ||
| RelDataType int2 = TYPE_FACTORY.createSqlType(SqlTypeName.INTEGER); | ||
|
|
||
| RelDataType result = TYPE_FACTORY.leastRestrictive(List.of(int1, int2)); | ||
|
|
||
| assertNotNull(result); | ||
| assertEquals(SqlTypeName.INTEGER, result.getSqlTypeName()); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.