nielspardon commented on code in PR #4239: URL: https://github.com/apache/calcite/pull/4239#discussion_r1990018520
########## core/src/test/java/org/apache/calcite/rel/RelRootTest.java: ########## @@ -0,0 +1,122 @@ +/* + * 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.calcite.rel; + +import org.apache.calcite.rel.logical.LogicalProject; +import org.apache.calcite.rel.type.RelDataTypeField; +import org.apache.calcite.rel.type.RelDataTypeFieldImpl; +import org.apache.calcite.rel.type.RelRecordType; +import org.apache.calcite.schema.SchemaPlus; +import org.apache.calcite.sql.SqlKind; +import org.apache.calcite.test.CalciteAssert; +import org.apache.calcite.test.RelBuilderTest; +import org.apache.calcite.tools.FrameworkConfig; +import org.apache.calcite.tools.Frameworks; +import org.apache.calcite.tools.RelBuilder; + +import org.junit.jupiter.api.Test; + +import java.util.Collections; +import java.util.List; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertInstanceOf; +import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + +/** + * Tests for {@link RelRoot}. + */ +public class RelRootTest { + /** Test case for + * <a href="https://issues.apache.org/jira/browse/CALCITE-6877">[CALCITE-6877] + * Generate LogicalProject in RelRoot.project() when mapping is not name trivial</a>. */ + @Test void testRelRootProjectForceNonNameTrivial() { + final SchemaPlus rootSchema = Frameworks.createRootSchema(true); + final SchemaPlus defaultSchema = + CalciteAssert.addSchema(rootSchema, CalciteAssert.SchemaSpec.HR); + final FrameworkConfig frameworkConfig = RelBuilderTest.config() + .defaultSchema(defaultSchema) + .build(); + final RelBuilder relBuilder = RelBuilder.create(frameworkConfig); + final RelNode inputRel = relBuilder.scan("emps") + .project(relBuilder.fields(Collections.singletonList("empid"))).build(); + + final List<RelDataTypeField> fields = + Collections.singletonList( + // rename empid to empno via RelRoot + new RelDataTypeFieldImpl("empno", + inputRel.getRowType().getFieldList().get(0).getIndex(), + inputRel.getRowType().getFieldList().get(0).getType())); + + final RelRoot root = RelRoot.of(inputRel, new RelRecordType(fields), SqlKind.SELECT); + + // inner LogicalProject selects one field and RelRoot only has one field + assertTrue(root.isRefTrivial()); + + // inner LogicalProject has different field name than RelRoot + assertFalse(root.isNameTrivial()); + + final RelNode project = root.project(); + assertEquals(inputRel, project); Review Comment: sure. changed it to assertThat -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
