Skip to content

Add null check for batch insert #935

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 11 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/third_party_libs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
version:
description: "Release version"
required: true
default: "1.0.0"
default: "1.2.0"

jobs:
release:
Expand Down
10 changes: 10 additions & 0 deletions .github/workflows/timezone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ jobs:
serverTz: ["Asia/Chongqing", "America/Los_Angeles", "Etc/UTC", "Europe/Berlin", "Europe/Moscow"]
clientTz: ["Asia/Chongqing", "America/Los_Angeles", "Etc/UTC", "Europe/Berlin", "Europe/Moscow"]
fail-fast: false
timeout-minutes: 30
name: "TimeZone(C/S): ${{ matrix.clientTz }} vs. ${{ matrix.serverTz }}"
steps:
- name: Check out Git repository
Expand Down Expand Up @@ -67,3 +68,12 @@ jobs:
-DclickhouseVersion=22.3 \
-Duser.timezone=${{ matrix.clientTz }} \
--also-make clean verify
- name: Upload test results
uses: actions/upload-artifact@v2
if: failure()
with:
name: result ${{ github.job }}
path: |
**/target/failsafe-reports
**/target/surefire-reports

Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,10 @@ public boolean isTuple() {
return dataType == ClickHouseDataType.Tuple;
}

public boolean isNestedType() {
return dataType.isNested();
}

public int getArrayNestedLevel() {
return arrayLevel;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,72 +31,76 @@
*/
@SuppressWarnings("squid:S115")
public enum ClickHouseDataType {
IntervalYear(Long.class, false, true, true, 8, 19, 0, 0, 0),
IntervalQuarter(Long.class, false, true, true, 8, 19, 0, 0, 0),
IntervalMonth(Long.class, false, true, true, 8, 19, 0, 0, 0),
IntervalWeek(Long.class, false, true, true, 8, 19, 0, 0, 0),
IntervalDay(Long.class, false, true, true, 8, 19, 0, 0, 0),
IntervalHour(Long.class, false, true, true, 8, 19, 0, 0, 0),
IntervalMinute(Long.class, false, true, true, 8, 19, 0, 0, 0),
IntervalSecond(Long.class, false, true, true, 8, 19, 0, 0, 0),
UInt8(Short.class, false, true, false, 1, 3, 0, 0, 0, "INT1 UNSIGNED", "TINYINT UNSIGNED"),
UInt16(Integer.class, false, true, false, 2, 5, 0, 0, 0, "SMALLINT UNSIGNED"),
UInt32(Long.class, false, true, false, 4, 10, 0, 0, 0, "INT UNSIGNED", "INTEGER UNSIGNED", "MEDIUMINT UNSIGNED"),
UInt64(Long.class, false, true, false, 8, 20, 0, 0, 0, "BIGINT UNSIGNED"),
UInt128(BigInteger.class, false, true, false, 16, 39, 0, 0, 0),
UInt256(BigInteger.class, false, true, false, 32, 78, 0, 0, 0),
Int8(Byte.class, false, true, true, 1, 3, 0, 0, 0, "BYTE", "INT1", "INT1 SIGNED", "TINYINT", "TINYINT SIGNED"),
Int16(Short.class, false, true, true, 2, 5, 0, 0, 0, "SMALLINT", "SMALLINT SIGNED"),
Int32(Integer.class, false, true, true, 4, 10, 0, 0, 0, "INT", "INTEGER", "MEDIUMINT", "INT SIGNED",
IntervalYear(Long.class, false, true, true, 8, 19, 0, 0, 0, false),
IntervalQuarter(Long.class, false, true, true, 8, 19, 0, 0, 0, false),
IntervalMonth(Long.class, false, true, true, 8, 19, 0, 0, 0, false),
IntervalWeek(Long.class, false, true, true, 8, 19, 0, 0, 0, false),
IntervalDay(Long.class, false, true, true, 8, 19, 0, 0, 0, false),
IntervalHour(Long.class, false, true, true, 8, 19, 0, 0, 0, false),
IntervalMinute(Long.class, false, true, true, 8, 19, 0, 0, 0, false),
IntervalSecond(Long.class, false, true, true, 8, 19, 0, 0, 0, false),
UInt8(Short.class, false, true, false, 1, 3, 0, 0, 0, false, "INT1 UNSIGNED", "TINYINT UNSIGNED"),
UInt16(Integer.class, false, true, false, 2, 5, 0, 0, 0, false, "SMALLINT UNSIGNED"),
UInt32(Long.class, false, true, false, 4, 10, 0, 0, 0, false, "INT UNSIGNED", "INTEGER UNSIGNED",
"MEDIUMINT UNSIGNED"),
UInt64(Long.class, false, true, false, 8, 20, 0, 0, 0, false, "BIGINT UNSIGNED"),
UInt128(BigInteger.class, false, true, false, 16, 39, 0, 0, 0, false),
UInt256(BigInteger.class, false, true, false, 32, 78, 0, 0, 0, false),
Int8(Byte.class, false, true, true, 1, 3, 0, 0, 0, false, "BYTE", "INT1", "INT1 SIGNED", "TINYINT",
"TINYINT SIGNED"),
Int16(Short.class, false, true, true, 2, 5, 0, 0, 0, false, "SMALLINT", "SMALLINT SIGNED"),
Int32(Integer.class, false, true, true, 4, 10, 0, 0, 0, false, "INT", "INTEGER", "MEDIUMINT", "INT SIGNED",
"INTEGER SIGNED", "MEDIUMINT SIGNED"),
Int64(Long.class, false, true, true, 8, 19, 0, 0, 0, "BIGINT", "BIGINT SIGNED"),
Int128(BigInteger.class, false, true, true, 16, 39, 0, 0, 0),
Int256(BigInteger.class, false, true, true, 32, 77, 0, 0, 0),
Bool(Boolean.class, false, false, true, 1, 1, 0, 0, 0, "BOOLEAN"),
Date(LocalDate.class, false, false, false, 2, 10, 0, 0, 0),
Date32(LocalDate.class, false, false, false, 4, 10, 0, 0, 0),
DateTime(LocalDateTime.class, true, false, false, 0, 29, 0, 0, 9, "TIMESTAMP"),
DateTime32(LocalDateTime.class, true, false, false, 4, 19, 0, 0, 0),
DateTime64(LocalDateTime.class, true, false, false, 8, 29, 3, 0, 9),
Decimal(BigDecimal.class, true, false, true, 0, 76, 0, 0, 76, "DEC", "NUMERIC", "FIXED"),
Decimal32(BigDecimal.class, true, false, true, 4, 9, 9, 0, 9),
Decimal64(BigDecimal.class, true, false, true, 8, 18, 18, 0, 18),
Decimal128(BigDecimal.class, true, false, true, 16, 38, 38, 0, 38),
Decimal256(BigDecimal.class, true, false, true, 32, 76, 20, 0, 76),
UUID(UUID.class, false, true, false, 16, 69, 0, 0, 0),
Int64(Long.class, false, true, true, 8, 19, 0, 0, 0, false, "BIGINT", "BIGINT SIGNED"),
Int128(BigInteger.class, false, true, true, 16, 39, 0, 0, 0, false),
Int256(BigInteger.class, false, true, true, 32, 77, 0, 0, 0, false),
Bool(Boolean.class, false, false, true, 1, 1, 0, 0, 0, false, "BOOLEAN"),
Date(LocalDate.class, false, false, false, 2, 10, 0, 0, 0, false),
Date32(LocalDate.class, false, false, false, 4, 10, 0, 0, 0, false),
DateTime(LocalDateTime.class, true, false, false, 0, 29, 0, 0, 9, false, "TIMESTAMP"),
DateTime32(LocalDateTime.class, true, false, false, 4, 19, 0, 0, 0, false),
DateTime64(LocalDateTime.class, true, false, false, 8, 29, 3, 0, 9, false),
Decimal(BigDecimal.class, true, false, true, 0, 76, 0, 0, 76, false, "DEC", "NUMERIC", "FIXED"),
Decimal32(BigDecimal.class, true, false, true, 4, 9, 9, 0, 9, false),
Decimal64(BigDecimal.class, true, false, true, 8, 18, 18, 0, 18, false),
Decimal128(BigDecimal.class, true, false, true, 16, 38, 38, 0, 38, false),
Decimal256(BigDecimal.class, true, false, true, 32, 76, 20, 0, 76, false),
UUID(UUID.class, false, true, false, 16, 69, 0, 0, 0, false),
/**
* Enum data type.
*
* @deprecated will be removed in v0.3.3, please use {@link #Enum8} instead
*/
@Deprecated
Enum(String.class, true, true, false, 1, 0, 0, 0, 0),
Enum8(String.class, true, true, false, 1, 0, 0, 0, 0), // "ENUM"),
Enum16(String.class, true, true, false, 2, 0, 0, 0, 0),
Float32(Float.class, false, true, true, 4, 12, 0, 0, 38, "FLOAT", "REAL", "SINGLE"),
Float64(Double.class, false, true, true, 16, 22, 0, 0, 308, "DOUBLE", "DOUBLE PRECISION"),
IPv4(Inet4Address.class, false, true, false, 4, 10, 0, 0, 0, "INET4"),
IPv6(Inet6Address.class, false, true, false, 16, 39, 0, 0, 0, "INET6"),
FixedString(String.class, true, true, false, 0, 0, 0, 0, 0, "BINARY"),
String(String.class, false, true, false, 0, 0, 0, 0, 0, "BINARY LARGE OBJECT", "BINARY VARYING", "BLOB", "BYTEA",
Enum(String.class, true, true, false, 1, 0, 0, 0, 0, false),
Enum8(String.class, true, true, false, 1, 0, 0, 0, 0, false), // "ENUM"),
Enum16(String.class, true, true, false, 2, 0, 0, 0, 0, false),
Float32(Float.class, false, true, true, 4, 12, 0, 0, 38, false, "FLOAT", "REAL", "SINGLE"),
Float64(Double.class, false, true, true, 16, 22, 0, 0, 308, false, "DOUBLE", "DOUBLE PRECISION"),
IPv4(Inet4Address.class, false, true, false, 4, 10, 0, 0, 0, false, "INET4"),
IPv6(Inet6Address.class, false, true, false, 16, 39, 0, 0, 0, false, "INET6"),
FixedString(String.class, true, true, false, 0, 0, 0, 0, 0, false, "BINARY"),
String(String.class, false, true, false, 0, 0, 0, 0, 0, false, "BINARY LARGE OBJECT", "BINARY VARYING", "BLOB",
"BYTEA",
"CHAR", "CHARACTER", "CHARACTER LARGE OBJECT", "CHARACTER VARYING", "CHAR LARGE OBJECT", "CHAR VARYING",
"CLOB", "LONGBLOB", "LONGTEXT", "MEDIUMBLOB", "MEDIUMTEXT", "NATIONAL CHAR", "NATIONAL CHARACTER",
"NATIONAL CHARACTER LARGE OBJECT", "NATIONAL CHARACTER VARYING", "NATIONAL CHAR VARYING", "NCHAR",
"NCHAR LARGE OBJECT", "NCHAR VARYING", "NVARCHAR", "TEXT", "TINYBLOB", "TINYTEXT", "VARBINARY", "VARCHAR",
"VARCHAR2"),
AggregateFunction(String.class, true, true, false, 0, 0, 0, 0, 0), // implementation-defined intermediate state
SimpleAggregateFunction(String.class, true, true, false, 0, 0, 0, 0, 0),
Array(Object.class, true, true, false, 0, 0, 0, 0, 0),
Map(Map.class, true, true, false, 0, 0, 0, 0, 0),
Nested(Object.class, true, true, false, 0, 0, 0, 0, 0),
Tuple(List.class, true, true, false, 0, 0, 0, 0, 0),
Object(Object.class, true, true, false, 0, 0, 0, 0, 0),
JSON(Object.class, false, false, false, 0, 0, 0, 0, 0), // same as Object('JSON')
Point(Object.class, false, true, true, 33, 0, 0, 0, 0), // same as Tuple(Float64, Float64)
Polygon(Object.class, false, true, true, 0, 0, 0, 0, 0), // same as Array(Ring)
MultiPolygon(Object.class, false, true, true, 0, 0, 0, 0, 0), // same as Array(Polygon)
Ring(Object.class, false, true, true, 0, 0, 0, 0, 0), // same as Array(Point)
Nothing(Object.class, false, true, false, 0, 0, 0, 0, 0);
AggregateFunction(String.class, true, true, false, 0, 0, 0, 0, 0, true), // implementation-defined intermediate
// state
SimpleAggregateFunction(String.class, true, true, false, 0, 0, 0, 0, 0, false),
Array(Object.class, true, true, false, 0, 0, 0, 0, 0, true),
Map(Map.class, true, true, false, 0, 0, 0, 0, 0, true),
Nested(Object.class, true, true, false, 0, 0, 0, 0, 0, true),
Tuple(List.class, true, true, false, 0, 0, 0, 0, 0, true),
Object(Object.class, true, true, false, 0, 0, 0, 0, 0, true),
JSON(Object.class, false, false, false, 0, 0, 0, 0, 0, true), // same as Object('JSON')
Point(Object.class, false, true, true, 33, 0, 0, 0, 0, true), // same as Tuple(Float64, Float64)
Polygon(Object.class, false, true, true, 0, 0, 0, 0, 0, true), // same as Array(Ring)
MultiPolygon(Object.class, false, true, true, 0, 0, 0, 0, 0, true), // same as Array(Polygon)
Ring(Object.class, false, true, true, 0, 0, 0, 0, 0, true), // same as Array(Point)
Nothing(Object.class, false, true, false, 0, 0, 0, 0, 0, true);

/**
* Immutable set(sorted) for all aliases.
Expand Down Expand Up @@ -294,9 +298,10 @@ public static Class<?> toPrimitiveType(Class<?> javaClass) {
private final int defaultScale;
private final int minScale;
private final int maxScale;
private final boolean nestedType;

ClickHouseDataType(Class<?> javaClass, boolean parameter, boolean caseSensitive, boolean signed, int byteLength,
int maxPrecision, int defaultScale, int minScale, int maxScale, String... aliases) {
int maxPrecision, int defaultScale, int minScale, int maxScale, boolean nestedType, String... aliases) {
this.objectType = toObjectType(javaClass);
this.primitiveType = toPrimitiveType(javaClass);
this.parameter = parameter;
Expand All @@ -307,6 +312,7 @@ public static Class<?> toPrimitiveType(Class<?> javaClass) {
this.defaultScale = defaultScale;
this.minScale = minScale;
this.maxScale = maxScale;
this.nestedType = nestedType;
if (aliases == null || aliases.length == 0) {
this.aliases = Collections.emptyList();
} else {
Expand Down Expand Up @@ -353,13 +359,12 @@ public boolean isCaseSensitive() {
}

/**
* Checks if this data type could be a nested structure.
* Checks if this data type uses a nested structure.
*
* @return true if it could be a nested structure; false otherwise
* @return true if it uses a nested structure; false otherwise
*/
public boolean isNested() {
return this == AggregateFunction || this == Array || this == Map || this == Nested || this == Tuple
|| this == Object || this == JSON;
return nestedType;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public class InputBasedPreparedStatement extends AbstractPreparedStatement imple
private final ZoneId timeZoneForDate;
private final ZoneId timeZoneForTs;

private final List<ClickHouseColumn> columns;
private final ClickHouseColumn[] columns;
private final ClickHouseValue[] values;
private final boolean[] flags;

Expand All @@ -59,12 +59,14 @@ protected InputBasedPreparedStatement(ClickHouseConnectionImpl connection, Click
timeZoneForTs = config.getUseTimeZone().toZoneId();
timeZoneForDate = config.isUseServerTimeZoneForDates() ? timeZoneForTs : null;

this.columns = columns;
int size = columns.size();
this.columns = new ClickHouseColumn[size];
this.values = new ClickHouseValue[size];
int i = 0;
values = new ClickHouseValue[size];
for (ClickHouseColumn col : columns) {
values[i++] = ClickHouseValues.newValue(config, col);
this.columns[i] = col;
this.values[i] = ClickHouseValues.newValue(config, col);
i++;
}
flags = new boolean[size];

Expand Down Expand Up @@ -309,8 +311,14 @@ public void addBatch() throws SQLException {
if (!flags[i]) {
throw SqlExceptionUtils.clientError(ClickHouseUtils.format("Missing value for parameter #%d", i + 1));
}
ClickHouseColumn col = columns[i];
ClickHouseValue val = values[i];
if (!col.isNestedType() && !col.isNullable() && (val == null || val.isNullOrEmpty())) {
throw SqlExceptionUtils.clientError(ClickHouseUtils.format(
"Cannot set null to non-nullable column #%d [%s]", i + 1, col));
}
try {
serializer.serialize(values[i], config, columns.get(i), stream);
serializer.serialize(val, config, col, stream);
} catch (IOException e) {
// should not happen
throw SqlExceptionUtils.handle(e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@ public void testReadWriteString() throws SQLException {
stmt.setObject(3, null);
stmt.setObject(4, new String[0]);
stmt.setObject(5, new String[0]);
Assert.assertThrows(RuntimeException.class, () -> stmt.execute());
Assert.assertThrows(SQLException.class, () -> stmt.execute());
}
try (PreparedStatement stmt = conn
.prepareStatement("insert into test_read_write_strings")) {
Expand Down
8 changes: 4 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,10 @@
<disruptor.version>3.4.4</disruptor.version>
<dnsjava.version>3.5.0</dnsjava.version>
<fastutil.version>8.5.8</fastutil.version>
<grpc.version>1.40.2</grpc.version>
<grpc.version>1.45.1</grpc.version>
<gson.version>2.9.0</gson.version>
<httpclient.version>4.5.13</httpclient.version>
<protobuf.version>3.17.3</protobuf.version>
<protobuf.version>3.19.2</protobuf.version>
<lz4.version>1.8.0</lz4.version>
<roaring-bitmap.version>0.9.25</roaring-bitmap.version>
<slf4j.version>2.0.0-alpha5</slf4j.version>
Expand All @@ -100,7 +100,7 @@
<mysql-driver.version>8.0.28</mysql-driver.version>
<postgresql-driver.version>42.3.3</postgresql-driver.version>

<repackaged.version>1.1.2</repackaged.version>
<repackaged.version>1.2.0</repackaged.version>

<assembly-plugin.version>3.3.0</assembly-plugin.version>
<compiler-plugin.version>3.8.1</compiler-plugin.version>
Expand Down Expand Up @@ -929,4 +929,4 @@
</build>
</profile>
</profiles>
</project>
</project>
6 changes: 3 additions & 3 deletions third-party-libraries/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,14 @@
</distributionManagement>

<properties>
<revision>1.1.2</revision>
<revision>1.2.0</revision>
<project.current.year>2022</project.current.year>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<grpc.version>1.40.2</grpc.version>
<grpc.version>1.45.1</grpc.version>
<gson.version>2.9.0</gson.version>
<opencensus.version>0.28.3</opencensus.version>
<roaring-bitmap.version>0.9.25</roaring-bitmap.version>
<roaring-bitmap.version>0.9.27</roaring-bitmap.version>
<assembly-plugin.version>3.3.0</assembly-plugin.version>
<deploy-plugin.version>3.0.0-M1</deploy-plugin.version>
<flatten-plugin.version>1.2.7</flatten-plugin.version>
Expand Down