Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
shiyuhang0 committed Apr 2, 2024
1 parent df1dc00 commit 5ba39ae
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,17 @@ import org.tikv.common.exception.TiBatchWriteException

class BatchWriteDataTypeSuite extends BaseBatchWriteTest("test_data_type", "test") {

test("Test date type pr 2779") {
val dbtable1 = "test.test_date1"
val dbtable2 = "test.test_date2"
jdbcUpdate(s"drop table if exists $dbtable1")
jdbcUpdate(s"drop table if exists $dbtable2")
jdbcUpdate(s"create table $dbtable1 (dt date)")
jdbcUpdate(s"create table $dbtable2 (dt date)")
jdbcUpdate(s"insert into $dbtable2 values ('2020-01-01')")
spark.sql(s"insert into $dbtable1 select * from $dbtable2").show()
}

test("Test Read different types") {
jdbcUpdate(s"""
|create table $dbtable(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import com.pingcap.tikv.codec.ExtendedDateTime;
import com.pingcap.tikv.meta.TiColumnInfo.InternalTypeHolder;
import java.sql.Timestamp;
import java.time.Instant;
import org.joda.time.DateTimeZone;
import org.joda.time.LocalDate;
import org.tikv.common.exception.ConvertNotSupportException;
Expand Down Expand Up @@ -130,6 +131,8 @@ java.sql.Timestamp convertToMysqlDateTime(Object value) throws ConvertNotSupport
result = new java.sql.Timestamp(((java.sql.Date) value).getTime());
} else if (value instanceof java.sql.Timestamp) {
result = (java.sql.Timestamp) value;
} else if (value instanceof Instant) {
result = java.sql.Timestamp.from((Instant) value);
} else {
throw new ConvertNotSupportException(value.getClass().getName(), this.getClass().getName());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ private java.sql.Date convertToMysqlDate(Object value) throws ConvertNotSupportE
result = (java.sql.Date) value;
} else if (value instanceof java.sql.Timestamp) {
result = new java.sql.Date(((java.sql.Timestamp) value).getTime());
} else if (value instanceof java.time.LocalDate) {
result = java.sql.Date.valueOf(((java.time.LocalDate) value).toString());
} else {
throw new ConvertNotSupportException(value.getClass().getName(), this.getClass().getName());
}
Expand Down Expand Up @@ -119,4 +121,10 @@ protected Date decodeNotNullForBatchWrite(int flag, CodecDataInput cdi) {
}
return new Date(date.toDate().getTime());
}

public static void main(String[] args) {
java.time.LocalDate localDate = java.time.LocalDate.now();
System.out.println(localDate);
System.out.println(localDate.toString());
}
}

0 comments on commit 5ba39ae

Please sign in to comment.