This is an automated email from the ASF dual-hosted git repository.
zstan pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/ignite-3.git
The following commit(s) were added to refs/heads/main by this push:
new e0c1930a75 IGNITE-16778 Sql. Support timestamp through jdbc (#1951)
e0c1930a75 is described below
commit e0c1930a7574eb0aa219c20cd30ee623dcb3e05b
Author: Evgeniy Stanilovskiy <[email protected]>
AuthorDate: Wed Apr 19 15:21:45 2023 +0300
IGNITE-16778 Sql. Support timestamp through jdbc (#1951)
---
.../client/proto/ClientBinaryTupleUtils.java | 16 ++++++++
.../client/io/netty/NettyClientMessageHandler.java | 3 +-
.../apache/ignite/jdbc/ItJdbcBatchSelfTest.java | 43 ++++++++++++++++++++++
3 files changed, 60 insertions(+), 2 deletions(-)
diff --git
a/modules/client-common/src/main/java/org/apache/ignite/internal/client/proto/ClientBinaryTupleUtils.java
b/modules/client-common/src/main/java/org/apache/ignite/internal/client/proto/ClientBinaryTupleUtils.java
index 9550a1bb12..279b1f048d 100644
---
a/modules/client-common/src/main/java/org/apache/ignite/internal/client/proto/ClientBinaryTupleUtils.java
+++
b/modules/client-common/src/main/java/org/apache/ignite/internal/client/proto/ClientBinaryTupleUtils.java
@@ -40,6 +40,9 @@ import static
org.apache.ignite.lang.ErrorGroups.Client.PROTOCOL_ERR;
import java.math.BigDecimal;
import java.math.BigInteger;
+import java.sql.Date;
+import java.sql.Time;
+import java.sql.Timestamp;
import java.time.Duration;
import java.time.Instant;
import java.time.LocalDate;
@@ -192,6 +195,19 @@ public class ClientBinaryTupleUtils {
} else if (obj instanceof Instant) {
appendTypeAndScale(builder, TIMESTAMP);
builder.appendTimestamp((Instant) obj);
+ } else if (obj instanceof Timestamp) {
+ appendTypeAndScale(builder, DATETIME);
+ Timestamp timeStamp = (Timestamp) obj;
+ LocalDateTime localDateTime = timeStamp.toLocalDateTime();
+ builder.appendDateTime(localDateTime);
+ } else if (obj instanceof Date) {
+ appendTypeAndScale(builder, DATE);
+ Date date = (Date) obj;
+ builder.appendDate(date.toLocalDate());
+ } else if (obj instanceof Time) {
+ appendTypeAndScale(builder, TIME);
+ Time time = (Time) obj;
+ builder.appendTime(time.toLocalTime());
} else if (obj instanceof BigInteger) {
appendTypeAndScale(builder, NUMBER);
builder.appendNumber((BigInteger) obj);
diff --git
a/modules/client/src/main/java/org/apache/ignite/internal/client/io/netty/NettyClientMessageHandler.java
b/modules/client/src/main/java/org/apache/ignite/internal/client/io/netty/NettyClientMessageHandler.java
index b62c9fbbdc..cb8eebf91c 100644
---
a/modules/client/src/main/java/org/apache/ignite/internal/client/io/netty/NettyClientMessageHandler.java
+++
b/modules/client/src/main/java/org/apache/ignite/internal/client/io/netty/NettyClientMessageHandler.java
@@ -22,7 +22,6 @@ import static
org.apache.ignite.internal.client.io.netty.NettyClientConnection.A
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
-import java.io.IOException;
/**
* Netty client message handler.
@@ -30,7 +29,7 @@ import java.io.IOException;
public class NettyClientMessageHandler extends ChannelInboundHandlerAdapter {
/** {@inheritDoc} */
@Override
- public void channelRead(ChannelHandlerContext ctx, Object msg) throws
IOException {
+ public void channelRead(ChannelHandlerContext ctx, Object msg) {
ctx.channel().attr(ATTR_CONN).get().onMessage((ByteBuf) msg);
}
diff --git
a/modules/jdbc/src/integrationTest/java/org/apache/ignite/jdbc/ItJdbcBatchSelfTest.java
b/modules/jdbc/src/integrationTest/java/org/apache/ignite/jdbc/ItJdbcBatchSelfTest.java
index 5634af9127..883c176e41 100644
---
a/modules/jdbc/src/integrationTest/java/org/apache/ignite/jdbc/ItJdbcBatchSelfTest.java
+++
b/modules/jdbc/src/integrationTest/java/org/apache/ignite/jdbc/ItJdbcBatchSelfTest.java
@@ -28,10 +28,15 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
import java.sql.BatchUpdateException;
+import java.sql.Date;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
+import java.sql.Time;
+import java.sql.Timestamp;
+import java.time.LocalDate;
+import java.time.LocalTime;
import java.util.Arrays;
import org.apache.ignite.internal.jdbc.proto.IgniteQueryErrorCode;
import org.apache.ignite.internal.jdbc.proto.SqlStateCode;
@@ -397,6 +402,44 @@ public class ItJdbcBatchSelfTest extends
AbstractJdbcSelfTest {
assertEquals(0, updates.length, "Returned update counts array should
have no elements for empty batch.");
}
+ @Test
+ public void testDataTypes() throws SQLException {
+ Statement stmt0 = conn.createStatement();
+
+ stmt0.executeUpdate("CREATE TABLE timetypes (tt_id int, "
+ + "tt_date date, "
+ + "tt_time time, "
+ + "tt_timestamp timestamp, "
+ + "PRIMARY KEY (tt_id));");
+
+ PreparedStatement prepStmt = conn.prepareStatement(
+ "INSERT INTO timetypes(tt_id, tt_date, tt_time, tt_timestamp)"
+ + " VALUES (?, ?, ?, ?)");
+
+ Date date = Date.valueOf(LocalDate.now());
+ Time time = Time.valueOf(LocalTime.now());
+ Timestamp ts = new Timestamp(System.currentTimeMillis());
+
+ int idx = 1;
+ prepStmt.setLong(idx++, 1);
+ prepStmt.setDate(idx++, date);
+ prepStmt.setTime(idx++, time);
+ prepStmt.setTimestamp(idx, ts);
+ prepStmt.addBatch();
+
+ prepStmt.executeBatch();
+ prepStmt.close();
+
+ ResultSet res = stmt0.executeQuery("SELECT * FROM timetypes");
+ res.next();
+ assertEquals(date, res.getDate(2));
+ assertEquals(time, res.getTime(3));
+ assertEquals(ts, res.getTimestamp(4));
+
+ stmt0.execute("DROP TABLE timetypes");
+ stmt0.close();
+ }
+
@Test
public void testBatchPrepared() throws SQLException {
final int batchSize = 10;