|
5 | 5 |
|
6 | 6 | package org.opensearch.sql.calcite.standalone; |
7 | 7 |
|
8 | | -import java.io.IOException; |
9 | | -import java.sql.PreparedStatement; |
10 | | -import java.sql.ResultSet; |
11 | | -import java.sql.SQLException; |
12 | | -import java.util.List; |
13 | 8 | import java.util.Map; |
14 | | -import org.apache.calcite.plan.Contexts; |
15 | | -import org.apache.calcite.plan.RelTraitDef; |
16 | 9 | import org.apache.calcite.rel.RelNode; |
17 | 10 | import org.apache.calcite.rel.type.RelDataType; |
18 | | -import org.apache.calcite.rex.RexBuilder; |
19 | 11 | import org.apache.calcite.rex.RexNode; |
20 | | -import org.apache.calcite.schema.SchemaPlus; |
21 | 12 | import org.apache.calcite.sql.fun.SqlStdOperatorTable; |
22 | | -import org.apache.calcite.sql.parser.SqlParser; |
23 | | -import org.apache.calcite.sql.type.SqlTypeName; |
24 | | -import org.apache.calcite.tools.Frameworks; |
25 | | -import org.apache.calcite.tools.Programs; |
26 | | -import org.apache.calcite.tools.RelBuilder; |
27 | 13 | import org.junit.jupiter.api.Test; |
28 | | -import org.opensearch.sql.calcite.CalcitePlanContext; |
29 | | -import org.opensearch.sql.calcite.SysLimit; |
30 | | -import org.opensearch.sql.calcite.utils.CalciteToolsHelper.OpenSearchRelRunners; |
31 | | -import org.opensearch.sql.common.setting.Settings; |
32 | | -import org.opensearch.sql.executor.QueryType; |
33 | 14 | import org.opensearch.sql.expression.function.BuiltinFunctionName; |
34 | 15 | import org.opensearch.sql.expression.function.PPLFuncImpTable; |
35 | 16 |
|
36 | | -public class MapConcatFunctionIT extends CalcitePPLIntegTestCase { |
| 17 | +public class MapConcatFunctionIT extends CalcitePPLRelNodeIntegTestCase { |
37 | 18 |
|
38 | 19 | private static final String MAP_FIELD = "map"; |
39 | 20 | private static final String ID_FIELD = "id"; |
40 | | - TestContext context; |
41 | | - |
42 | | - @Override |
43 | | - public void init() throws IOException { |
44 | | - super.init(); |
45 | | - context = createTestContext(); |
46 | | - enableCalcite(); |
47 | | - } |
48 | 21 |
|
49 | 22 | @Test |
50 | 23 | public void testMapConcatWithNullValues() throws Exception { |
@@ -113,69 +86,4 @@ public void testMapConcat() throws Exception { |
113 | 86 | assertEquals("value3", result.get("key3")); |
114 | 87 | }); |
115 | 88 | } |
116 | | - |
117 | | - private static class TestContext { |
118 | | - final CalcitePlanContext planContext; |
119 | | - final RelBuilder relBuilder; |
120 | | - final RexBuilder rexBuilder; |
121 | | - |
122 | | - TestContext(CalcitePlanContext planContext, RelBuilder relBuilder, RexBuilder rexBuilder) { |
123 | | - this.planContext = planContext; |
124 | | - this.relBuilder = relBuilder; |
125 | | - this.rexBuilder = rexBuilder; |
126 | | - } |
127 | | - } |
128 | | - |
129 | | - @FunctionalInterface |
130 | | - private interface ResultVerifier { |
131 | | - void verify(ResultSet resultSet) throws SQLException; |
132 | | - } |
133 | | - |
134 | | - private TestContext createTestContext() { |
135 | | - CalcitePlanContext planContext = createCalcitePlanContext(); |
136 | | - return new TestContext(planContext, planContext.relBuilder, planContext.rexBuilder); |
137 | | - } |
138 | | - |
139 | | - private RelDataType createMapType(RexBuilder rexBuilder) { |
140 | | - RelDataType stringType = rexBuilder.getTypeFactory().createSqlType(SqlTypeName.VARCHAR); |
141 | | - RelDataType anyType = rexBuilder.getTypeFactory().createSqlType(SqlTypeName.ANY); |
142 | | - return rexBuilder.getTypeFactory().createMapType(stringType, anyType); |
143 | | - } |
144 | | - |
145 | | - private void executeRelNodeAndVerify( |
146 | | - CalcitePlanContext planContext, RelNode relNode, ResultVerifier verifier) |
147 | | - throws SQLException { |
148 | | - try (PreparedStatement statement = OpenSearchRelRunners.run(planContext, relNode)) { |
149 | | - ResultSet resultSet = statement.executeQuery(); |
150 | | - verifier.verify(resultSet); |
151 | | - } |
152 | | - } |
153 | | - |
154 | | - private void verifyColumns(ResultSet resultSet, String... expectedColumnNames) |
155 | | - throws SQLException { |
156 | | - assertEquals(expectedColumnNames.length, resultSet.getMetaData().getColumnCount()); |
157 | | - |
158 | | - for (int i = 0; i < expectedColumnNames.length; i++) { |
159 | | - String expectedName = expectedColumnNames[i]; |
160 | | - String actualName = resultSet.getMetaData().getColumnName(i + 1); |
161 | | - assertEquals(expectedName, actualName); |
162 | | - } |
163 | | - } |
164 | | - |
165 | | - private CalcitePlanContext createCalcitePlanContext() { |
166 | | - // Create a Frameworks.ConfigBuilder similar to CalcitePPLAbstractTest |
167 | | - final SchemaPlus rootSchema = Frameworks.createRootSchema(true); |
168 | | - Frameworks.ConfigBuilder config = |
169 | | - Frameworks.newConfigBuilder() |
170 | | - .parserConfig(SqlParser.Config.DEFAULT) |
171 | | - .defaultSchema(rootSchema) |
172 | | - .traitDefs((List<RelTraitDef>) null) |
173 | | - .programs(Programs.heuristicJoinOrder(Programs.RULE_SET, true, 2)); |
174 | | - |
175 | | - config.context(Contexts.of(RelBuilder.Config.DEFAULT)); |
176 | | - |
177 | | - Settings settings = getSettings(); |
178 | | - return CalcitePlanContext.create( |
179 | | - config.build(), SysLimit.fromSettings(settings), QueryType.PPL); |
180 | | - } |
181 | 89 | } |
0 commit comments