Skip to content

Commit 5280c6f

Browse files
author
Paultagoras
committed
Update RowBinaryFormatWriterTest.java
1 parent 752c3e3 commit 5280c6f

File tree

1 file changed

+55
-27
lines changed

1 file changed

+55
-27
lines changed

client-v2/src/test/java/com/clickhouse/client/datatypes/RowBinaryFormatWriterTest.java

Lines changed: 55 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import java.io.IOException;
2323
import java.math.BigDecimal;
2424
import java.math.BigInteger;
25+
import java.time.ZonedDateTime;
2526
import java.util.List;
2627
import java.util.Map;
2728
import java.util.Random;
@@ -75,6 +76,14 @@ protected void initTable(String tableName, String createTableSQL, CommandSetting
7576
}
7677

7778
private static void assertEqualsKinda(Object actual, Object expected) {
79+
if (actual instanceof ZonedDateTime) {
80+
actual = ((ZonedDateTime) actual).toInstant().getEpochSecond();
81+
}
82+
83+
if (expected instanceof ZonedDateTime) {
84+
expected = ((ZonedDateTime) expected).toInstant().getEpochSecond();
85+
}
86+
7887
assertEquals(String.valueOf(actual), String.valueOf(expected));
7988
}
8089

@@ -102,12 +111,37 @@ private void writeTest(String tableName, String tableCreate, Field[][] rows) thr
102111
Map<String, Object> row = record.getValues();
103112
//Validate data
104113
for (Field field : rows[id - 1]) {
105-
assertEqualsKinda(row.get(field.name), field.getValue());
114+
assertEqualsKinda(row.get(field.name), field.comparisonValue);
106115
}
107116
id++;
108117
}
109118
}
110119

120+
private static class Field {
121+
String name;
122+
Object value;
123+
Object comparisonValue;
124+
125+
Field(String name) {
126+
this.name = name;
127+
this.value = null;
128+
this.comparisonValue = null;
129+
}
130+
131+
Field(String name, Object value) {
132+
this.name = name;
133+
this.value = value;
134+
this.comparisonValue = value;
135+
}
136+
137+
public Field set(Object comparisonValue) {//For comparison purposes
138+
this.comparisonValue = comparisonValue;
139+
return this;
140+
}
141+
}
142+
143+
144+
111145

112146

113147
@Test (groups = { "integration" })
@@ -223,33 +257,27 @@ public void writeStringsTest() throws Exception {
223257
}
224258

225259

226-
private static class Field {
227-
String name;
228-
Object value;
229-
Object defaultValue;
230-
231-
Field(String name) {
232-
this.name = name;
233-
this.value = null;
234-
this.defaultValue = null;
235-
}
236-
237-
Field(String name, Object value) {
238-
this.name = name;
239-
this.value = value;
240-
}
241-
242-
public Field set(Object defaultValue) {//For default value for comparison purposes
243-
this.defaultValue = defaultValue;
244-
return this;
245-
}
260+
@Test (groups = { "integration" })
261+
public void writeDatetimeTests() throws Exception {
262+
String tableName = "rowBinaryFormatWriterTest_writeNumbersTest_" + UUID.randomUUID().toString().replace('-', '_');
263+
String tableCreate = "CREATE TABLE \"" + tableName + "\" " +
264+
" (id Int32, " +
265+
" datetime DateTime, datetime_nullable Nullable(DateTime), datetime_default DateTime DEFAULT '2020-01-01 00:00:00', " +
266+
" datetime64 DateTime64, datetime64_nullable Nullable(DateTime64), datetime64_default DateTime64 DEFAULT '2025-01-01 00:00:00', " +
267+
" date Date, date_nullable Nullable(Date), date_default Date DEFAULT '2020-01-01', " +
268+
" date32 Date32, date32_nullable Nullable(Date32), date32_default Date32 DEFAULT '2025-01-01', " +
269+
" ) Engine = MergeTree ORDER BY id";
246270

247-
public Object getValue() {
248-
if (value == null && defaultValue != null) {
249-
return defaultValue;
250-
}
271+
// Insert random (valid) values
272+
Field[][] rows = new Field[][] {{
273+
new Field("id", 1), //Row ID
274+
new Field("datetime", ZonedDateTime.now()), new Field("datetime_nullable"), new Field("datetime_default").set(ZonedDateTime.parse("2020-01-01T00:00:00+00:00[UTC]")), //DateTime
275+
new Field("datetime64", ZonedDateTime.now()), new Field("datetime64_nullable"), new Field("datetime64_default").set(ZonedDateTime.parse("2025-01-01T00:00:00+00:00[UTC]")), //DateTime64
276+
new Field("date", ZonedDateTime.parse("2021-01-01T00:00:00+00:00[UTC]")), new Field("date_nullable"), new Field("date_default").set(ZonedDateTime.parse("2020-01-01T00:00:00+00:00[UTC]").toEpochSecond()), //Date
277+
new Field("date32", ZonedDateTime.parse("2021-01-01T00:00:00+00:00[UTC]")), new Field("date32_nullable"), new Field("date32_default").set(ZonedDateTime.parse("2025-01-01T00:00:00+00:00[UTC]").toEpochSecond()) //Date
278+
}
279+
};
251280

252-
return value;
253-
}
281+
writeTest(tableName, tableCreate, rows);
254282
}
255283
}

0 commit comments

Comments
 (0)