Skip to content

Commit 1c642ac

Browse files
committed
Merge branch 'main' into fix_settings_mutability
2 parents 26e9fcf + 9653c9e commit 1c642ac

File tree

19 files changed

+1980
-254
lines changed

19 files changed

+1980
-254
lines changed

client-v2/src/main/java/com/clickhouse/client/api/data_formats/ClickHouseBinaryFormatReader.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,12 @@
1111
import java.math.BigInteger;
1212
import java.net.Inet4Address;
1313
import java.net.Inet6Address;
14-
import java.time.*;
14+
import java.time.Duration;
15+
import java.time.Instant;
16+
import java.time.LocalDate;
17+
import java.time.LocalDateTime;
18+
import java.time.OffsetDateTime;
19+
import java.time.ZonedDateTime;
1520
import java.time.temporal.TemporalAmount;
1621
import java.util.List;
1722
import java.util.Map;

client-v2/src/main/java/com/clickhouse/client/api/data_formats/internal/AbstractBinaryFormatReader.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ public boolean readToPOJO(Map<String, POJOFieldDeserializer> deserializers, Obje
135135
* It is still internal method and should be used with care.
136136
* Usually this method is called to read next record into internal object and affects hasNext() method.
137137
* So after calling this one:
138-
* - hasNext(), next() should not be called
138+
* - hasNext(), next() and get methods cannot be called
139139
* - stream should be read with readRecord() method fully
140140
*
141141
* @param record

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import com.clickhouse.client.api.ClientException;
1111
import com.clickhouse.client.api.DataTypeUtils;
1212
import com.clickhouse.client.api.ServerException;
13-
import com.clickhouse.client.api.command.CommandResponse;
1413
import com.clickhouse.client.api.command.CommandSettings;
1514
import com.clickhouse.client.api.data_formats.ClickHouseBinaryFormatReader;
1615
import com.clickhouse.client.api.data_formats.internal.BinaryStreamReader;
@@ -44,7 +43,6 @@
4443
import org.testng.annotations.BeforeMethod;
4544
import org.testng.annotations.DataProvider;
4645
import org.testng.annotations.Test;
47-
import org.testng.util.Strings;
4846

4947
import java.io.BufferedReader;
5048
import java.io.BufferedWriter;

examples/jdbc/src/main/java/com/clickhouse/examples/jdbc/Basic.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,20 @@ static void insertDateWithPreparedStatement(String url, Properties properties) t
5959
pstmt.setString(3, "Alice");//Set the third parameter to "Alice"
6060
pstmt.setObject(4, Collections.singletonMap("key1", "value1"));
6161
pstmt.addBatch();//Add the current parameters to the batch
62+
pstmt.executeBatch();//Execute the batch
6263

6364
pstmt.setObject(1, ZonedDateTime.now());
6465
pstmt.setInt(2, 2);//Set the second parameter to 2
6566
pstmt.setString(3, "Bob");//Set the third parameter to "Bob"
6667
pstmt.setObject(4, Collections.singletonMap("key2", "value2"));
6768
pstmt.addBatch();//Add the current parameters to the batch
6869

70+
pstmt.setObject(1, ZonedDateTime.now());
71+
pstmt.setInt(2, 2);//Set the second parameter to 2
72+
pstmt.setString(3, "Chris");//Set the third parameter to "Chris"
73+
pstmt.setObject(4, Collections.singletonMap("key3", "value3"));
74+
pstmt.addBatch();//Add the current parameters to the batch
75+
6976
pstmt.executeBatch();//Execute the batch
7077
}
7178
}

jdbc-v2/src/main/antlr4/com/clickhouse/jdbc/internal/ClickHouseParser.g4

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ query
4141

4242
// CTE statement
4343
ctes
44-
: LPAREN? WITH (cteUnboundCol COMMA)* namedQuery (COMMA namedQuery)* RPAREN?
44+
: LPAREN? WITH cteUnboundCol? (COMMA cteUnboundCol)* COMMA? namedQuery (COMMA namedQuery)* RPAREN?
4545
;
4646

4747
namedQuery
@@ -55,6 +55,8 @@ columnAliases
5555
cteUnboundCol
5656
: (literal AS identifier) # CteUnboundColLiteral
5757
| (QUERY AS identifier) # CteUnboundColParam
58+
| LPAREN columnExpr RPAREN AS identifier # CteUnboundColExpr
59+
| LPAREN ctes? selectStmt RPAREN AS identifier # CteUnboundNestedSelect
5860
;
5961

6062
// ALTER statement
@@ -438,6 +440,11 @@ fromClause
438440
: FROM joinExpr
439441
| FROM identifier LPAREN QUERY RPAREN
440442
| FROM ctes
443+
| FROM identifier LPAREN viewParam (COMMA viewParam)? RPAREN
444+
;
445+
446+
viewParam
447+
: identifier EQ_SINGLE (literal | QUERY)
441448
;
442449

443450
arrayJoinClause
@@ -937,6 +944,7 @@ columnExpr
937944
| LBRACKET columnExprList? RBRACKET # ColumnExprArray
938945
| columnIdentifier # ColumnExprIdentifier
939946
| QUERY (CAST_OP identifier)? # ColumnExprParam
947+
| columnExpr REGEXP literal # ColumnExprRegexp
940948
;
941949

942950
columnArgList

jdbc-v2/src/main/java/com/clickhouse/jdbc/ConnectionImpl.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,10 @@ public void setDefaultQuerySettings(QuerySettings settings) {
130130
this.defaultQuerySettings = settings;
131131
}
132132

133+
public Calendar getDefaultCalendar() {
134+
return defaultCalendar;
135+
}
136+
133137
public String getServerVersion() throws SQLException {
134138
GenericRecord result = client.queryAll("SELECT version() as server_version").stream()
135139
.findFirst().orElseThrow(() -> new SQLException("Failed to retrieve server version.", ExceptionUtils.SQL_STATE_CLIENT_ERROR));

jdbc-v2/src/main/java/com/clickhouse/jdbc/PreparedStatementImpl.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -332,15 +332,23 @@ public long[] executeLargeBatch() throws SQLException {
332332
}
333333

334334
private List<Integer> executeBatchImpl() throws SQLException {
335+
List<Integer> results;
335336
if (insertStmtWithValues) {
336-
return executeInsertBatch();
337+
results = executeInsertBatch();
337338
} else {
338-
List<Integer> results = new ArrayList<>();
339+
results = new ArrayList<>();
339340
for (String sql : batch) {
340341
results.add((int) executeUpdateImpl(sql, localSettings));
341342
}
342-
return results;
343343
}
344+
clearBatch();
345+
return results;
346+
}
347+
348+
@Override
349+
public void clearBatch() throws SQLException {
350+
super.clearBatch(); /// clear super#batch
351+
batchValues.clear();
344352
}
345353

346354
private List<Integer> executeInsertBatch() throws SQLException {

jdbc-v2/src/main/java/com/clickhouse/jdbc/ResultSetImpl.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939

4040
public class ResultSetImpl implements ResultSet, JdbcV2Wrapper {
4141
private static final Logger log = LoggerFactory.getLogger(ResultSetImpl.class);
42-
private ResultSetMetaData metaData;
42+
private ResultSetMetaDataImpl metaData;
4343
protected ClickHouseBinaryFormatReader reader;
4444
private QueryResponse response;
4545
private boolean closed;
@@ -49,9 +49,9 @@ public class ResultSetImpl implements ResultSet, JdbcV2Wrapper {
4949

5050
private final FeatureManager featureManager;
5151

52-
private static final int AFTER_LAST = -1;
53-
private static final int BEFORE_FIRST = 0;
54-
private static final int FIRST_ROW = 1;
52+
public static final int AFTER_LAST = -1;
53+
public static final int BEFORE_FIRST = 0;
54+
public static final int FIRST_ROW = 1;
5555
private int rowPos;
5656

5757
private int fetchSize;

jdbc-v2/src/main/java/com/clickhouse/jdbc/StatementImpl.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,7 @@ private List<Integer> executeBatchImpl() throws SQLException {
416416
for (String sql : batch) {
417417
results.add(executeUpdate(sql));
418418
}
419+
clearBatch();
419420
return results;
420421
}
421422

0 commit comments

Comments
 (0)