Skip to content

Commit 7a45dae

Browse files
committed
added endian tests. just in case
1 parent 4c9f23d commit 7a45dae

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

client-v2/src/test/java/com/clickhouse/client/query/QueryTests.java

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,39 @@ public void testBigUnsignedInt() throws Exception {
185185
Assert.assertEquals(firstRecord.getBigInteger("i256"), expected256);
186186
}
187187

188+
@Test(groups = {"integration"})
189+
public void testEndianReadingNumbers() throws Exception {
190+
191+
byte[][] numbers = new byte[][] {
192+
new byte[] {0x00, 0x02, 0x00, 0x01},
193+
new byte[] {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08},
194+
new byte[] {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10},
195+
};
196+
197+
198+
for (byte[] number : numbers) {
199+
String typeName = "UInt32";
200+
if (number.length == 8) {
201+
typeName = "UInt64";
202+
} else if (number.length == 16) {
203+
typeName = "UInt128";
204+
}
205+
BigInteger expected = new BigInteger(number);
206+
String sqlQuery = "SELECT to" + typeName + "('" + expected + "') as value1";
207+
System.out.println(sqlQuery);
208+
Records records = client.queryRecords(sqlQuery).get(3, TimeUnit.SECONDS);
209+
GenericRecord firstRecord = records.iterator().next();
210+
211+
if (number.length == 4) {
212+
System.out.println(firstRecord.getLong("value1"));
213+
Assert.assertEquals(firstRecord.getLong("value1"), expected.longValue());
214+
} else {
215+
System.out.println(firstRecord.getBigInteger("value1"));
216+
Assert.assertEquals(firstRecord.getBigInteger("value1"), expected);
217+
}
218+
}
219+
}
220+
188221
@Test(groups = {"integration"})
189222
public void testReadRecordsWithStreamAPI() throws Exception {
190223
final int tables = 10;

0 commit comments

Comments
 (0)