mihaibudiu commented on code in PR #5189: URL: https://github.com/apache/calcite/pull/5189#discussion_r3809863943
########## core/src/test/java/org/apache/calcite/test/WindowPartitionAliasTest.java: ########## @@ -0,0 +1,79 @@ +/* + * 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.test; + +import org.junit.jupiter.api.Test; + +/** + * Tests for column aliases used as {@code PARTITION BY} keys of a window + * aggregate. + * + * <p>SQL allows quoted identifiers to contain almost any character; + * however, the enumerable convention materialises multi-column Review Comment: Is this true after this PR? If not, it should not be mentioned. We don't want to document behaviors which don't exist anymore. ########## core/src/test/java/org/apache/calcite/test/WindowPartitionAliasTest.java: ########## @@ -0,0 +1,79 @@ +/* + * 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.test; + +import org.junit.jupiter.api.Test; + +/** + * Tests for column aliases used as {@code PARTITION BY} keys of a window + * aggregate. + * + * <p>SQL allows quoted identifiers to contain almost any character; + * however, the enumerable convention materialises multi-column + * {@code PARTITION BY} keys as fields of a synthetic Java class emitted + * into generated source. Field names that are not valid Java identifiers + * cannot appear there: they must be rejected up front rather than + * producing an obscure compile error later. + */ +class WindowPartitionAliasTest { + + /** A quoted alias that is a valid Java identifier plans and runs + * normally when used as one of several {@code PARTITION BY} keys. The + * projection wraps the aliased column in a computation so field- Review Comment: I don't really understand what trimming has got to do with the current bug ########## core/src/test/java/org/apache/calcite/test/WindowPartitionAliasTest.java: ########## @@ -0,0 +1,79 @@ +/* + * 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.test; + +import org.junit.jupiter.api.Test; + +/** + * Tests for column aliases used as {@code PARTITION BY} keys of a window + * aggregate. + * + * <p>SQL allows quoted identifiers to contain almost any character; + * however, the enumerable convention materialises multi-column + * {@code PARTITION BY} keys as fields of a synthetic Java class emitted + * into generated source. Field names that are not valid Java identifiers + * cannot appear there: they must be rejected up front rather than + * producing an obscure compile error later. + */ +class WindowPartitionAliasTest { + + /** A quoted alias that is a valid Java identifier plans and runs + * normally when used as one of several {@code PARTITION BY} keys. The + * projection wraps the aliased column in a computation so field- + * trimming does not fold the sub-query away. */ + @Test void testValidIdentifierAlias() { + final String sql = "select \"aliased_deptno\"," + + " count(*) over (" + + " partition by \"aliased_deptno\", \"empid\") as c" + + " from (" + + " select \"deptno\" + 1 as \"aliased_deptno\", \"empid\"" + + " from \"hr\".\"emps\")"; + CalciteAssert.hr() + .query(sql) + .runs(); + } + + /** A quoted alias containing a space (a legal SQL identifier character + * that is not a legal Java identifier character) is rejected with a + * clear error rather than being propagated into generated code. */ + @Test void testAliasWithSpaceRejected() { + final String sql = "select \"has space\"," Review Comment: I actually think this shows the bug is not fixed. This is a legal SQL program, and it should not produce java-related errors. -- 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]
