Skip to content

Commit 9c6ba32

Browse files
committed
fixed some type encoding. added type cast draft
1 parent 4abffae commit 9c6ba32

File tree

7 files changed

+268
-74
lines changed

7 files changed

+268
-74
lines changed

clickhouse-data/src/main/java/com/clickhouse/data/ClickHouseDataType.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import java.math.BigInteger;
55
import java.net.Inet4Address;
66
import java.net.Inet6Address;
7+
import java.sql.SQLType;
78
import java.time.Duration;
89
import java.time.Instant;
910
import java.time.LocalDate;
@@ -50,7 +51,7 @@
5051
* modifiers for the underlying base data types.
5152
*/
5253
@SuppressWarnings("squid:S115")
53-
public enum ClickHouseDataType {
54+
public enum ClickHouseDataType implements SQLType {
5455
Bool(Boolean.class, false, false, true, 1, 1, 0, 0, 0, false,0x2D, "BOOLEAN"),
5556
Date(LocalDate.class, false, false, false, 2, 10, 0, 0, 0, false, 0x0F),
5657
Date32(LocalDate.class, false, false, false, 4, 10, 0, 0, 0, false, 0x10),
@@ -264,6 +265,21 @@ private static Set<Class<?>> setOf(Class<?>... args) {
264265

265266
public static final byte TUPLE_WITH_NAMES_BIN_TAG = 0x20;
266267

268+
@Override
269+
public String getName() {
270+
return name();
271+
}
272+
273+
@Override
274+
public String getVendor() {
275+
return "com.clickhouse";
276+
}
277+
278+
@Override
279+
public Integer getVendorTypeNumber() {
280+
return (int) binTag;
281+
}
282+
267283
public enum IntervalKind {
268284
Nanosecond(IntervalNanosecond, ChronoUnit.NANOS, 0x00),
269285
Microsecond(IntervalMicrosecond, ChronoUnit.MICROS, 0x01),

client-v2/src/main/java/com/clickhouse/client/api/DataTypeUtils.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,17 @@ public class DataTypeUtils {
2020
/**
2121
* Formatter for the DateTime type.
2222
*/
23-
public static DateTimeFormatter DATETIME_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
23+
public static DateTimeFormatter DATETIME_FORMATTER = DateTimeFormatter.ofPattern("uuuu-MM-dd HH:mm:ss");
2424

2525
/**
2626
* Formatter for the Date type.
2727
*/
28-
public static DateTimeFormatter DATE_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd");
28+
public static DateTimeFormatter DATE_FORMATTER = DateTimeFormatter.ofPattern("uuuu-MM-dd");
2929

3030
/**
3131
* Formatter for the DateTime type with nanoseconds.
3232
*/
33-
public static DateTimeFormatter DATETIME_WITH_NANOS_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.nnnnnnnnn");
33+
public static DateTimeFormatter DATETIME_WITH_NANOS_FORMATTER = DateTimeFormatter.ofPattern("uuuu-MM-dd HH:mm:ss.nnnnnnnnn");
3434

3535
private static final DateTimeFormatter INSTANT_FORMATTER = new DateTimeFormatterBuilder()
3636
.appendValue(ChronoField.INSTANT_SECONDS)

client-v2/src/main/java/com/clickhouse/client/api/sql/SQLUtils.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,4 +132,8 @@ public static String unquoteIdentifier(String str) {
132132
return str;
133133
}
134134
}
135+
136+
public static String escapeSingleQuotes(String x) {
137+
return x.replace("\\", "\\\\").replace("'", "\\'");//Escape single quotes
138+
}
135139
}

jdbc-v2/src/main/java/com/clickhouse/data/Tuple.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.clickhouse.data;
22

3+
import java.util.Arrays;
4+
35
public class Tuple {
46
private final Object[] values;
57
private volatile String output;
@@ -37,4 +39,22 @@ public String toString() {
3739
}
3840
return output;
3941
}
42+
43+
44+
@Override
45+
public boolean equals(Object obj) {
46+
if (this == obj) {
47+
return true;
48+
}
49+
if (obj instanceof Tuple) {
50+
Tuple other = (Tuple) obj;
51+
return Arrays.equals(values, other.values);
52+
}
53+
return false;
54+
}
55+
56+
@Override
57+
public int hashCode() {
58+
return Arrays.hashCode(values);
59+
}
4060
}

0 commit comments

Comments
 (0)