@Test
public void testNegativeCompareNegativeValue() throws Exception {
String query = "SELECT string_key FROM HBASE_NATIVE WHERE uint_key > 100000";
String url = PHOENIX_JDBC_URL + ";" + PhoenixRuntime.CURRENT_SCN_ATTRIB + "=" + (ts + 7); // Run query at timestamp 7
Properties props = new Properties(TEST_PROPERTIES);
PhoenixConnection conn = DriverManager.getConnection(url, props).unwrap(PhoenixConnection.class);
HTableInterface hTable = conn.getQueryServices().getTable(SchemaUtil.getTableNameAsBytes(HBASE_NATIVE_SCHEMA_NAME, HBASE_NATIVE));
List<Row> mutations = new ArrayList<Row>();
byte[] family = Bytes.toBytes("1");
byte[] uintCol = Bytes.toBytes("UINT_COL");
byte[] ulongCol = Bytes.toBytes("ULONG_COL");
byte[] key;
Put put;
// Need to use native APIs because the Phoenix APIs wouldn't let you insert a
// negative number for an unsigned type
key = ByteUtil.concat(Bytes.toBytes(-10), Bytes.toBytes(100L), Bytes.toBytes("e"));
put = new Put(key);
// Insert at later timestamp than other queries in this test are using, so that
// we don't affect them
put.add(family, uintCol, ts+6, Bytes.toBytes(10));
put.add(family, ulongCol, ts+6, Bytes.toBytes(100L));
put.add(family, QueryConstants.EMPTY_COLUMN_BYTES, ts+6, ByteUtil.EMPTY_BYTE_ARRAY);
mutations.add(put);
hTable.batch(mutations);
// Demonstrates weakness of HBase Bytes serialization. Negative numbers
// show up as bigger than positive numbers
PreparedStatement statement = conn.prepareStatement(query);
ResultSet rs = statement.executeQuery();
assertTrue(rs.next());
assertEquals("e", rs.getString(1));
assertFalse(rs.next());
}