MartijnVisser commented on code in PR #29333: URL: https://github.com/apache/flink/pull/29333#discussion_r4149020273
########## flink-table/flink-table-planner/src/test/java/org/apache/flink/table/planner/parse/CalciteParserTest.java: ########## @@ -0,0 +1,162 @@ +/* + * 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.flink.table.planner.parse; + +import org.apache.flink.sql.parser.impl.FlinkSqlParserImpl; +import org.apache.flink.sql.parser.validate.FlinkSqlConformance; +import org.apache.flink.table.api.SqlParserEOFException; +import org.apache.flink.table.api.SqlParserException; + +import org.apache.calcite.config.Lex; +import org.apache.calcite.sql.parser.SqlParser; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; + +import java.util.stream.Collectors; +import java.util.stream.IntStream; +import java.util.stream.Stream; + +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +/** Tests for the exception conversion in {@link CalciteParser}. */ +class CalciteParserTest { + + private static final String NON_QUERY = "Non-query expression encountered in illegal context"; + + private final CalciteParser parser = + new CalciteParser( + SqlParser.config() + .withParserFactory(FlinkSqlParserImpl.FACTORY) + .withConformance(FlinkSqlConformance.DEFAULT) + .withLex(Lex.JAVA) + .withIdentifierMaxLength(256)); + + /** + * Errors that the grammar raises through {@code SqlUtil.newContextException}. Calcite keeps + * their position only in {@code SqlParseException#getPos()}, so the message has to name it. + */ + private static Stream<Arguments> statementsWithContextErrors() { + return Stream.of( + Arguments.of( + "misspelled keyword", + "ELECT 1", + "From line 1, column 1 to line 1, column 5: " + NON_QUERY), + Arguments.of( + "non-query INSERT body", + "INSERT INTO t 1", + "At line 1, column 15: " + NON_QUERY), Review Comment: I've added it: the message now echoes the failing line with a caret under it, like psql. In the message rather than in the client, so Table API and JDBC users get it too. -- 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]
