Skip to content

Commit

Permalink
Fix TestSelect failure due to out-of-bounds smallint
Browse files Browse the repository at this point in the history
Summary: Max value is 32767 but the test was using 65535.

Test Plan: jenkins TestSelect.

Reviewers: ayush_sengupta1991, pritam.damania

Reviewed By: ayush_sengupta1991, pritam.damania

Subscribers: yql

Differential Revision: https://phabricator.dev.yugabyte.com/D4900
  • Loading branch information
m-iancu committed May 30, 2018
1 parent 98c1250 commit ffb0f50
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
36 changes: 35 additions & 1 deletion java/yb-cql/src/test/java/org/yb/cql/TestSelect.java
Original file line number Diff line number Diff line change
Expand Up @@ -925,6 +925,40 @@ private void selectAndVerify(String query, double result) {
assertEquals(result, session.execute(query).one().getDouble(0), 1e-13);
}

@Test
public void testIntegerBounds() throws Exception {
session.execute("CREATE TABLE test_int_bounds(h int primary key, " +
"t tinyint, s smallint, i int, b bigint)");

String insertStmt = "INSERT INTO test_int_bounds(h, %s) VALUES (1, %s)";

// Test upper bounds.
session.execute(String.format(insertStmt, "t", "127"));
session.execute(String.format(insertStmt, "s", "32767"));
session.execute(String.format(insertStmt, "i", "2147483647"));
session.execute(String.format(insertStmt, "b", "9223372036854775807"));
assertQuery("SELECT t, s, i, b FROM test_int_bounds WHERE h = 1",
"Row[127, 32767, 2147483647, 9223372036854775807]");

runInvalidStmt(String.format(insertStmt, "t", "128"));
runInvalidStmt(String.format(insertStmt, "s", "32768"));
runInvalidStmt(String.format(insertStmt, "i", "2147483648"));
runInvalidStmt(String.format(insertStmt, "b", "9223372036854775808"));

// Test lower bounds.
session.execute(String.format(insertStmt, "t", "-128"));
session.execute(String.format(insertStmt, "s", "-32768"));
session.execute(String.format(insertStmt, "i", "-2147483648"));
session.execute(String.format(insertStmt, "b", "-9223372036854775808"));
assertQuery("SELECT t, s, i, b FROM test_int_bounds WHERE h = 1",
"Row[-128, -32768, -2147483648, -9223372036854775808]");

runInvalidStmt(String.format(insertStmt, "t", "-129"));
runInvalidStmt(String.format(insertStmt, "s", "-32769"));
runInvalidStmt(String.format(insertStmt, "i", "-2147483649"));
runInvalidStmt(String.format(insertStmt, "b", "-9223372036854775809"));
}

@Test
public void testCasts() throws Exception {
// Create test table.
Expand Down Expand Up @@ -975,7 +1009,7 @@ public void testCasts() throws Exception {

// Try edge cases.
session.execute("INSERT INTO test_local (c1, c2, c3, c4, c5, c6) values (2147483647, 2.5, " +
"3.3, 65535, 9223372036854775807, '2147483647')");
"3.3, 32767, 9223372036854775807, '2147483647')");
selectAndVerify("SELECT CAST(c1 as int) FROM test_local WHERE c1 = 2147483647", 2147483647);
selectAndVerify("SELECT CAST(c1 as bigint) FROM test_local WHERE c1 = 2147483647", 2147483647L);
selectAndVerify("SELECT CAST(c1 as smallint) FROM test_local WHERE c1 = 2147483647",
Expand Down
1 change: 0 additions & 1 deletion src/yb/yql/cql/ql/exec/eval_const.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
#include "yb/common/jsonb.h"
#include "yb/util/bytes_formatter.h"
#include "yb/yql/cql/ql/exec/executor.h"
// #include "yb/util/jsonb.h"
#include "yb/util/logging.h"
#include "yb/util/bfql/bfunc.h"
#include "yb/util/net/inetaddress.h"
Expand Down

0 comments on commit ffb0f50

Please sign in to comment.