Skip to content

Commit d3f4233

Browse files
committed
added tests for LowCardinality()
1 parent 0992132 commit d3f4233

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

client-v2/src/test/java/com/clickhouse/client/insert/SamplePOJO.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ public class SamplePOJO {
8585
private ClickHouseBitmap groupBitmapUint32;
8686
private ClickHouseBitmap groupBitmapUint64;
8787

88+
private String keyword;
89+
8890
public SamplePOJO() {
8991
final Random random = new Random();
9092
byteValue = (byte) random.nextInt();
@@ -180,6 +182,8 @@ public SamplePOJO() {
180182

181183
groupBitmapUint32 = ClickHouseBitmap.wrap(random.ints(5, Integer.MAX_VALUE - 100, Integer.MAX_VALUE).toArray());
182184
groupBitmapUint64 = ClickHouseBitmap.wrap(random.longs(5, Long.MAX_VALUE - 100, Long.MAX_VALUE).toArray());
185+
186+
keyword = "database";
183187
}
184188

185189
public byte getByteValue() {
@@ -574,6 +578,14 @@ public void setGroupBitmapUint64(ClickHouseBitmap groupBitmapUint64) {
574578
this.groupBitmapUint64 = groupBitmapUint64;
575579
}
576580

581+
public String getKeyword() {
582+
return keyword;
583+
}
584+
585+
public void setKeyword(String keyword) {
586+
this.keyword = keyword;
587+
}
588+
577589
@Override
578590
public String toString() {
579591
return "SamplePOJO{" +
@@ -683,7 +695,8 @@ public static String generateTableCreateSQL(String tableName) {
683695
"nested Nested (innerInt Int32, innerString String, " +
684696
"innerNullableInt Nullable(Int32)), " +
685697
"groupBitmapUint32 AggregateFunction(groupBitmap, UInt32), " +
686-
"groupBitmapUint64 AggregateFunction(groupBitmap, UInt64) " +
698+
"groupBitmapUint64 AggregateFunction(groupBitmap, UInt64), " +
699+
"keyword LowCardinality(String) " +
687700
") ENGINE = MergeTree ORDER BY ()";
688701
}
689702
}

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
import java.time.ZonedDateTime;
6363
import java.util.ArrayList;
6464
import java.util.Arrays;
65+
import java.util.Collection;
6566
import java.util.Collections;
6667
import java.util.HashMap;
6768
import java.util.HashSet;
@@ -2000,4 +2001,21 @@ public void testServerTimezone() throws Exception {
20002001
Assert.assertEquals(serverUtcTime.withZoneSameInstant(ZoneId.of("America/New_York")), serverEstTime);
20012002
}
20022003
}
2004+
2005+
@Test(groups = {"integration"})
2006+
public void testLowCardinalityValues() throws Exception {
2007+
final String table = "test_low_cardinality_values";
2008+
final String tableCreate = "CREATE TABLE " + table + "(rowID Int32, keyword LowCardinality(String)) Engine = MergeTree ORDER BY ()";
2009+
2010+
client.execute("DROP TABLE IF EXISTS " + table);
2011+
client.execute(tableCreate);
2012+
2013+
client.execute("INSERT INTO " + table + " VALUES (0, 'db'), (1, 'fast'), (2, 'not a java')");
2014+
String[] values = new String[] {"db", "fast", "not a java"};
2015+
Collection<GenericRecord> records = client.queryAll("SELECT * FROM " + table);
2016+
for (GenericRecord record : records) {
2017+
int rowId = record.getInteger("rowID");
2018+
Assert.assertEquals(record.getString("keyword"), values[rowId]);
2019+
}
2020+
}
20032021
}

0 commit comments

Comments
 (0)