From 2fcd7048fcfa35341ce754c8a3243d61447f78d4 Mon Sep 17 00:00:00 2001 From: yrizhkov Date: Thu, 19 Sep 2024 10:24:14 +0300 Subject: [PATCH] FMWK-560 Make upper boundary inclusive in the BETWEEN operator --- .../jdbc/predicate/QueryPredicateRange.java | 4 +++- .../com/aerospike/jdbc/SimpleQueriesTest.java | 19 ++++++++++++++++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/aerospike/jdbc/predicate/QueryPredicateRange.java b/src/main/java/com/aerospike/jdbc/predicate/QueryPredicateRange.java index f384daa..de891ee 100644 --- a/src/main/java/com/aerospike/jdbc/predicate/QueryPredicateRange.java +++ b/src/main/java/com/aerospike/jdbc/predicate/QueryPredicateRange.java @@ -24,9 +24,11 @@ public QueryPredicateRange( @Override public Exp toFilterExpression(boolean withPrimaryKey) { + // ANSI SQL defines the BETWEEN operator to be inclusive, + // so both boundary values are included in the range. return Exp.and( Exp.ge(buildLeftExp(), getValueExp(lowValue)), - Exp.lt(buildLeftExp(), getValueExp(highValue)) + Exp.le(buildLeftExp(), getValueExp(highValue)) ); } diff --git a/src/test/java/com/aerospike/jdbc/SimpleQueriesTest.java b/src/test/java/com/aerospike/jdbc/SimpleQueriesTest.java index e9969e0..a7405c1 100644 --- a/src/test/java/com/aerospike/jdbc/SimpleQueriesTest.java +++ b/src/test/java/com/aerospike/jdbc/SimpleQueriesTest.java @@ -304,7 +304,7 @@ public void testSelectInQuery() throws SQLException { } @Test - public void testSelectBetweenQuery() throws SQLException { + public void testSelectLowerBoundaryBetweenQuery() throws SQLException { Statement statement = null; ResultSet resultSet = null; String query = format("SELECT * FROM %s WHERE int2 BETWEEN 1 AND 3", TABLE_NAME); @@ -319,4 +319,21 @@ public void testSelectBetweenQuery() throws SQLException { closeQuietly(resultSet); } } + + @Test + public void testSelectUpperBoundaryBetweenQuery() throws SQLException { + Statement statement = null; + ResultSet resultSet = null; + String query = format("SELECT * FROM %s WHERE int2 BETWEEN 0 AND 1", TABLE_NAME); + try { + statement = connection.createStatement(); + resultSet = statement.executeQuery(query); + assertTrue(resultSet.next()); + + testRecord.assertResultSet(resultSet); + } finally { + closeQuietly(statement); + closeQuietly(resultSet); + } + } }