This is an automated email from the ASF dual-hosted git repository.
zhangliang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git
The following commit(s) were added to refs/heads/master by this push:
new 713824400b2 Add more converter test cases (#37349)
713824400b2 is described below
commit 713824400b29bcfba87e8a406f1746dda13a0c45
Author: Liang Zhang <[email protected]>
AuthorDate: Thu Dec 11 18:56:05 2025 +0800
Add more converter test cases (#37349)
---
.../segment/generic/OwnerConverterTest.java | 45 +++++++++++++++
.../segment/groupby/GroupByConverterTest.java | 66 ++++++++++++++++++++++
.../segment/groupby/HavingConverterTest.java | 56 ++++++++++++++++++
.../limit/PaginationValueSQLConverterTest.java | 51 +++++++++++++++++
4 files changed, 218 insertions(+)
diff --git
a/kernel/sql-federation/compiler/src/test/java/org/apache/shardingsphere/sqlfederation/compiler/sql/ast/converter/segment/generic/OwnerConverterTest.java
b/kernel/sql-federation/compiler/src/test/java/org/apache/shardingsphere/sqlfederation/compiler/sql/ast/converter/segment/generic/OwnerConverterTest.java
new file mode 100644
index 00000000000..15be1faf54a
--- /dev/null
+++
b/kernel/sql-federation/compiler/src/test/java/org/apache/shardingsphere/sqlfederation/compiler/sql/ast/converter/segment/generic/OwnerConverterTest.java
@@ -0,0 +1,45 @@
+/*
+ * 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.shardingsphere.sqlfederation.compiler.sql.ast.converter.segment.generic;
+
+import
org.apache.shardingsphere.sql.parser.statement.core.segment.generic.OwnerSegment;
+import
org.apache.shardingsphere.sql.parser.statement.core.value.identifier.IdentifierValue;
+import org.junit.jupiter.api.Test;
+
+import java.util.Arrays;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+class OwnerConverterTest {
+
+ @Test
+ void assertConvertReturnsEmptyForNullSegment() {
+ assertTrue(OwnerConverter.convert(null).isEmpty());
+ }
+
+ @Test
+ void assertConvertReturnsAllOwnersInOrder() {
+ OwnerSegment childOwner = new OwnerSegment(0, 0, new
IdentifierValue("child"));
+ childOwner.setOwner(new OwnerSegment(0, 0, new
IdentifierValue("root")));
+ OwnerSegment leafOwner = new OwnerSegment(0, 0, new
IdentifierValue("leaf"));
+ leafOwner.setOwner(childOwner);
+ assertThat(OwnerConverter.convert(leafOwner), is(Arrays.asList("root",
"child", "leaf")));
+ }
+}
diff --git
a/kernel/sql-federation/compiler/src/test/java/org/apache/shardingsphere/sqlfederation/compiler/sql/ast/converter/segment/groupby/GroupByConverterTest.java
b/kernel/sql-federation/compiler/src/test/java/org/apache/shardingsphere/sqlfederation/compiler/sql/ast/converter/segment/groupby/GroupByConverterTest.java
new file mode 100644
index 00000000000..cf252e5c421
--- /dev/null
+++
b/kernel/sql-federation/compiler/src/test/java/org/apache/shardingsphere/sqlfederation/compiler/sql/ast/converter/segment/groupby/GroupByConverterTest.java
@@ -0,0 +1,66 @@
+/*
+ * 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.shardingsphere.sqlfederation.compiler.sql.ast.converter.segment.groupby;
+
+import org.apache.calcite.sql.SqlNode;
+import org.apache.calcite.sql.SqlNodeList;
+import
org.apache.shardingsphere.sql.parser.statement.core.segment.dml.order.GroupBySegment;
+import
org.apache.shardingsphere.sql.parser.statement.core.segment.dml.order.item.OrderByItemSegment;
+import
org.apache.shardingsphere.sqlfederation.compiler.sql.ast.converter.segment.orderby.item.OrderByItemConverterUtils;
+import
org.apache.shardingsphere.test.infra.framework.extension.mock.AutoMockExtension;
+import
org.apache.shardingsphere.test.infra.framework.extension.mock.StaticMockSettings;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Optional;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+@ExtendWith(AutoMockExtension.class)
+@StaticMockSettings(OrderByItemConverterUtils.class)
+class GroupByConverterTest {
+
+ @Test
+ void assertConvertReturnsEmptyForNullSegment() {
+ assertFalse(GroupByConverter.convert(null).isPresent());
+ }
+
+ @Test
+ void assertConvertReturnsEmptyForEmptyItems() {
+ assertFalse(GroupByConverter.convert(new GroupBySegment(0, 0,
Collections.emptyList())).isPresent());
+ }
+
+ @Test
+ void assertConvertReturnsSqlNodeListWhenItemsPresent() {
+ Collection<OrderByItemSegment> groupByItems = new
ArrayList<>(Collections.singletonList(mock(OrderByItemSegment.class)));
+ SqlNode expectedNode = mock(SqlNode.class);
+
when(OrderByItemConverterUtils.convert(groupByItems)).thenReturn(Collections.singleton(expectedNode));
+ Optional<SqlNodeList> actual = GroupByConverter.convert(new
GroupBySegment(0, 0, groupByItems));
+ assertTrue(actual.isPresent());
+ assertThat(actual.get().get(0), is(expectedNode));
+ assertThat(actual.get().size(), is(1));
+ }
+}
diff --git
a/kernel/sql-federation/compiler/src/test/java/org/apache/shardingsphere/sqlfederation/compiler/sql/ast/converter/segment/groupby/HavingConverterTest.java
b/kernel/sql-federation/compiler/src/test/java/org/apache/shardingsphere/sqlfederation/compiler/sql/ast/converter/segment/groupby/HavingConverterTest.java
new file mode 100644
index 00000000000..cd1ddb4be35
--- /dev/null
+++
b/kernel/sql-federation/compiler/src/test/java/org/apache/shardingsphere/sqlfederation/compiler/sql/ast/converter/segment/groupby/HavingConverterTest.java
@@ -0,0 +1,56 @@
+/*
+ * 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.shardingsphere.sqlfederation.compiler.sql.ast.converter.segment.groupby;
+
+import org.apache.calcite.sql.SqlNode;
+import
org.apache.shardingsphere.sql.parser.statement.core.segment.dml.expr.ExpressionSegment;
+import
org.apache.shardingsphere.sql.parser.statement.core.segment.dml.predicate.HavingSegment;
+import
org.apache.shardingsphere.sqlfederation.compiler.sql.ast.converter.segment.expression.ExpressionConverter;
+import
org.apache.shardingsphere.test.infra.framework.extension.mock.AutoMockExtension;
+import
org.apache.shardingsphere.test.infra.framework.extension.mock.StaticMockSettings;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+
+import java.util.Optional;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+@ExtendWith(AutoMockExtension.class)
+@StaticMockSettings(ExpressionConverter.class)
+class HavingConverterTest {
+
+ @Test
+ void assertConvertReturnsEmptyForNullSegment() {
+ assertFalse(HavingConverter.convert(null).isPresent());
+ }
+
+ @Test
+ void assertConvertDelegatesToExpressionConverter() {
+ ExpressionSegment expr = mock(ExpressionSegment.class);
+ SqlNode expectedSqlNode = mock(SqlNode.class);
+
when(ExpressionConverter.convert(expr)).thenReturn(Optional.of(expectedSqlNode));
+ Optional<SqlNode> actual = HavingConverter.convert(new
HavingSegment(0, 0, expr));
+ assertTrue(actual.isPresent());
+ assertThat(actual.get(), is(expectedSqlNode));
+ }
+}
diff --git
a/kernel/sql-federation/compiler/src/test/java/org/apache/shardingsphere/sqlfederation/compiler/sql/ast/converter/segment/limit/PaginationValueSQLConverterTest.java
b/kernel/sql-federation/compiler/src/test/java/org/apache/shardingsphere/sqlfederation/compiler/sql/ast/converter/segment/limit/PaginationValueSQLConverterTest.java
new file mode 100644
index 00000000000..f713bb43371
--- /dev/null
+++
b/kernel/sql-federation/compiler/src/test/java/org/apache/shardingsphere/sqlfederation/compiler/sql/ast/converter/segment/limit/PaginationValueSQLConverterTest.java
@@ -0,0 +1,51 @@
+/*
+ * 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.shardingsphere.sqlfederation.compiler.sql.ast.converter.segment.limit;
+
+import org.apache.calcite.sql.SqlDynamicParam;
+import org.apache.calcite.sql.SqlLiteral;
+import org.apache.calcite.sql.SqlNode;
+import
org.apache.shardingsphere.sql.parser.statement.core.segment.dml.pagination.limit.NumberLiteralLimitValueSegment;
+import
org.apache.shardingsphere.sql.parser.statement.core.segment.dml.pagination.limit.ParameterMarkerLimitValueSegment;
+import org.junit.jupiter.api.Test;
+
+import java.util.Optional;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.isA;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+class PaginationValueSQLConverterTest {
+
+ @Test
+ void assertConvertReturnsLiteralSqlNodeForNumberLiteral() {
+ Optional<SqlNode> actual = PaginationValueSQLConverter.convert(new
NumberLiteralLimitValueSegment(0, 0, 5L));
+ assertTrue(actual.isPresent());
+ assertThat(actual.get(), isA(SqlLiteral.class));
+ assertThat(((SqlLiteral) actual.get()).toValue(), is("5"));
+ }
+
+ @Test
+ void assertConvertReturnsDynamicParamForParameterMarker() {
+ Optional<SqlNode> actual = PaginationValueSQLConverter.convert(new
ParameterMarkerLimitValueSegment(0, 0, 2));
+ assertTrue(actual.isPresent());
+ assertThat(actual.get(), isA(SqlDynamicParam.class));
+ assertThat(((SqlDynamicParam) actual.get()).getIndex(), is(2));
+ }
+}