Copilot commented on code in PR #17023:
URL: https://github.com/apache/iotdb/pull/17023#discussion_r2688770914


##########
iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/plan/relational/sql/ast/SqlParserErrorHandlerTest.java:
##########
@@ -0,0 +1,75 @@
+/*
+ * 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.iotdb.db.queryengine.plan.relational.sql.ast;
+
+import 
org.apache.iotdb.db.queryengine.plan.relational.sql.parser.ParsingException;
+import org.apache.iotdb.db.queryengine.plan.relational.sql.parser.SqlParser;
+
+import org.junit.Test;
+
+import java.time.ZoneId;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
+
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+public class SqlParserErrorHandlerTest {
+
+  @Test
+  public void testParseLimitOffsetError() {
+    String sql = "select * from information_schema.queries offset 48 limit1";
+    SqlParser sqlParser = new SqlParser();
+    ExecutorService executor = Executors.newSingleThreadExecutor();
+    Future<?> future =
+        executor.submit(
+            () -> {
+              try {
+                sqlParser.createStatement(sql, ZoneId.systemDefault(), null);
+              } catch (ParsingException e) {
+                assertTrue(e.getMessage().contains("mismatched input 
'limit1'"));
+              }
+            });
+
+    try {
+      // The parsing should fail quickly. If it hangs (OOM), this timeout will
+      // trigger.
+      future.get(5, TimeUnit.SECONDS);
+    } catch (InterruptedException e) {
+      fail("Interrupted");
+    } catch (ExecutionException e) {
+      // If parsing exception propagates here (which it shouldn't as it's 
caught in
+      // the task), handle it
+      if (e.getCause() instanceof ParsingException) {
+        assertTrue(e.getMessage().contains("mismatched input 'limit1'"));

Review Comment:
   The assertion here checks e.getMessage() which is the ExecutionException 
message, but should be checking e.getCause().getMessage() to verify the 
ParsingException's message content.
   ```suggestion
           assertTrue(e.getCause().getMessage().contains("mismatched input 
'limit1'"));
   ```



##########
iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/plan/relational/sql/ast/SqlParserErrorHandlerTest.java:
##########
@@ -0,0 +1,75 @@
+/*
+ * 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.iotdb.db.queryengine.plan.relational.sql.ast;
+
+import 
org.apache.iotdb.db.queryengine.plan.relational.sql.parser.ParsingException;
+import org.apache.iotdb.db.queryengine.plan.relational.sql.parser.SqlParser;
+
+import org.junit.Test;
+
+import java.time.ZoneId;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
+
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+public class SqlParserErrorHandlerTest {
+
+  @Test
+  public void testParseLimitOffsetError() {
+    String sql = "select * from information_schema.queries offset 48 limit1";
+    SqlParser sqlParser = new SqlParser();
+    ExecutorService executor = Executors.newSingleThreadExecutor();
+    Future<?> future =
+        executor.submit(
+            () -> {
+              try {
+                sqlParser.createStatement(sql, ZoneId.systemDefault(), null);

Review Comment:
   The test may not properly verify that a ParsingException is thrown. If the 
sqlParser.createStatement call completes successfully without throwing an 
exception, the test will pass silently. The test should explicitly fail if no 
exception is thrown, or use assertThrows to ensure the exception occurs.
   ```suggestion
                   sqlParser.createStatement(sql, ZoneId.systemDefault(), null);
                   fail("Expected ParsingException to be thrown");
   ```



-- 
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]

Reply via email to