This is an automated email from the ASF dual-hosted git repository. haonan pushed a commit to branch cp_3719 in repository https://gitbox.apache.org/repos/asf/iotdb.git
commit ac53707698057259a5aaa3c5a5f17d47bfe69e21 Author: xinzhongtianxia <[email protected]> AuthorDate: Mon Aug 16 10:17:20 2021 +0800 [IOTDB-1539] [To rel/0.12] Fix delete operation with value filter is abnormal Co-authored-by: 还真 <[email protected]> --- .../apache/iotdb/db/qp/sql/IoTDBSqlVisitor.java | 12 ++++ .../iotdb/db/integration/IoTDBDeletionIT.java | 81 ++++++++++++++++++++++ 2 files changed, 93 insertions(+) diff --git a/server/src/main/java/org/apache/iotdb/db/qp/sql/IoTDBSqlVisitor.java b/server/src/main/java/org/apache/iotdb/db/qp/sql/IoTDBSqlVisitor.java index ec721ea..d403298 100644 --- a/server/src/main/java/org/apache/iotdb/db/qp/sql/IoTDBSqlVisitor.java +++ b/server/src/main/java/org/apache/iotdb/db/qp/sql/IoTDBSqlVisitor.java @@ -18,6 +18,7 @@ */ package org.apache.iotdb.db.qp.sql; +import org.apache.iotdb.db.conf.IoTDBConstant; import org.apache.iotdb.db.conf.IoTDBDescriptor; import org.apache.iotdb.db.engine.trigger.api.TriggerEvent; import org.apache.iotdb.db.exception.index.UnsupportedIndexTypeException; @@ -256,6 +257,11 @@ public class IoTDBSqlVisitor extends SqlBaseBaseVisitor<Operator> { private static final String DELETE_RANGE_ERROR_MSG = "For delete statement, where clause can only contain atomic expressions like : " + "time > XXX, time <= XXX, or two atomic expressions connected by 'AND'"; + + private static final String DELETE_ONLY_SUPPORT_TIME_EXP_ERROR_MSG = + "For delete statement, where clause can only contain time expressions, " + + "value filter is not currently supported."; + private ZoneId zoneId; QueryOperator queryOp; @@ -1713,6 +1719,12 @@ public class IoTDBSqlVisitor extends SqlBaseBaseVisitor<Operator> { } private Pair<Long, Long> calcOperatorInterval(FilterOperator filterOperator) { + + if (filterOperator.getSinglePath() != null + && !IoTDBConstant.TIME.equals(filterOperator.getSinglePath().getMeasurement())) { + throw new SQLParserException(DELETE_ONLY_SUPPORT_TIME_EXP_ERROR_MSG); + } + long time = Long.parseLong(((BasicFunctionOperator) filterOperator).getValue()); switch (filterOperator.getTokenIntType()) { case SQLConstant.LESSTHAN: diff --git a/server/src/test/java/org/apache/iotdb/db/integration/IoTDBDeletionIT.java b/server/src/test/java/org/apache/iotdb/db/integration/IoTDBDeletionIT.java index bd402a4..9e7242a 100644 --- a/server/src/test/java/org/apache/iotdb/db/integration/IoTDBDeletionIT.java +++ b/server/src/test/java/org/apache/iotdb/db/integration/IoTDBDeletionIT.java @@ -37,6 +37,7 @@ import java.util.Locale; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; +import static org.junit.Assert.fail; public class IoTDBDeletionIT { @@ -73,6 +74,86 @@ public class IoTDBDeletionIT { IoTDBDescriptor.getInstance().getConfig().setPartitionInterval(prevPartitionInterval); } + /** + * Should delete this case after the deletion value filter feature be implemented + * + * @throws SQLException + */ + @Test + public void testUnsupportedValueFilter() throws SQLException { + try (Connection connection = + DriverManager.getConnection( + Config.IOTDB_URL_PREFIX + "127.0.0.1:6667/", "root", "root"); + Statement statement = connection.createStatement()) { + + statement.execute("insert into root.vehicle.d0(time,s0) values (10,310)"); + statement.execute("insert into root.vehicle.d0(time,s3) values (10,'text')"); + statement.execute("insert into root.vehicle.d0(time,s4) values (10,true)"); + + String errorMsg = + "303: Check metadata error: For delete statement, where clause can only" + + " contain time expressions, value filter is not currently supported."; + + String errorMsg2 = + "303: Check metadata error: For delete statement, where clause can only contain" + + " atomic expressions like : time > XXX, time <= XXX," + + " or two atomic expressions connected by 'AND'"; + + try { + statement.execute( + "DELETE FROM root.vehicle.d0.s0 WHERE s0 <= 300 AND time > 0 AND time < 100"); + fail("should not reach here!"); + } catch (SQLException e) { + assertEquals(errorMsg2, e.getMessage()); + } + + try { + statement.execute("DELETE FROM root.vehicle.d0.s0 WHERE s0 <= 300 AND s0 > 0"); + fail("should not reach here!"); + } catch (SQLException e) { + assertEquals(errorMsg, e.getMessage()); + } + + try { + statement.execute("DELETE FROM root.vehicle.d0.s3 WHERE s3 = 'text'"); + fail("should not reach here!"); + } catch (SQLException e) { + assertEquals(errorMsg, e.getMessage()); + } + + try { + statement.execute("DELETE FROM root.vehicle.d0.s4 WHERE s4 != true"); + fail("should not reach here!"); + } catch (SQLException e) { + assertEquals(errorMsg, e.getMessage()); + } + + try (ResultSet set = statement.executeQuery("SELECT s0 FROM root.vehicle.d0")) { + int cnt = 0; + while (set.next()) { + cnt++; + } + assertEquals(1, cnt); + } + + try (ResultSet set = statement.executeQuery("SELECT s3 FROM root.vehicle.d0")) { + int cnt = 0; + while (set.next()) { + cnt++; + } + assertEquals(1, cnt); + } + + try (ResultSet set = statement.executeQuery("SELECT s4 FROM root.vehicle.d0")) { + int cnt = 0; + while (set.next()) { + cnt++; + } + assertEquals(1, cnt); + } + } + } + @Test public void test() throws SQLException { prepareData();
