File tree Expand file tree Collapse file tree 2 files changed +33
-0
lines changed
core/src/test/scala/org/apache/spark/sql
tikv-client/src/main/java/com/pingcap/tikv/columnar Expand file tree Collapse file tree 2 files changed +33
-0
lines changed Original file line number Diff line number Diff line change @@ -22,6 +22,33 @@ import org.apache.spark.sql.functions.{col, sum}
2222
2323class IssueTestSuite extends BaseTiSparkTest {
2424
25+ test(" test tiflash overflow in unsigned bigint" ) {
26+ if (! enableTiFlashTest) {
27+ cancel(" tiflash test not enabled" )
28+ }
29+ val dbTable = " tispark_test.tiflash_overflow"
30+ tidbStmt.execute(s " drop table if exists $dbTable" )
31+ tidbStmt.execute(
32+ s " CREATE TABLE $dbTable (`a` bigint(20) UNSIGNED NOT NULL,`b` bigint(20) UNSIGNED NOT NULL) " )
33+ tidbStmt.execute(s " insert into $dbTable values(16717361816800086255, 16717361816800086255) " )
34+ tidbStmt.execute(s " ALTER TABLE $dbTable SET TIFLASH REPLICA 1 " )
35+
36+ Thread .sleep(5 * 1000 )
37+
38+ val prev = spark.conf.getOption(TiConfigConst .ISOLATION_READ_ENGINES )
39+ try {
40+ spark.conf
41+ .set(TiConfigConst .ISOLATION_READ_ENGINES , TiConfigConst .TIFLASH_STORAGE_ENGINE )
42+ val df = spark.sql(s " select * from $dbTable" )
43+ val row = Row (BigDecimal (" 16717361816800086255" ), BigDecimal (" 16717361816800086255" ))
44+ checkAnswer(df, Seq (row))
45+ } finally {
46+ spark.conf.set(
47+ TiConfigConst .ISOLATION_READ_ENGINES ,
48+ prev.getOrElse(TiConfigConst .DEFAULT_STORAGE_ENGINES ))
49+ }
50+ }
51+
2552 test(" test issue 2649" ) {
2653 val dbTable = " tispark_test.mutil_uniq"
2754 tidbStmt.execute(s " drop table if exists $dbTable" )
Original file line number Diff line number Diff line change 1818
1919import static com .pingcap .tikv .util .MemoryUtil .EMPTY_BYTE_BUFFER_DIRECT ;
2020
21+ import com .google .common .primitives .UnsignedLong ;
2122import com .pingcap .tikv .codec .Codec .DateCodec ;
2223import com .pingcap .tikv .codec .Codec .DateTimeCodec ;
2324import com .pingcap .tikv .codec .ExtendedDateTime ;
2425import com .pingcap .tikv .columnar .datatypes .CHType ;
2526import com .pingcap .tikv .types .AbstractDateTimeType ;
2627import com .pingcap .tikv .types .BytesType ;
2728import com .pingcap .tikv .types .DateType ;
29+ import com .pingcap .tikv .types .DecimalType ;
2830import com .pingcap .tikv .util .MemoryUtil ;
2931import java .math .BigDecimal ;
3032import java .nio .ByteBuffer ;
@@ -240,6 +242,10 @@ public double getDouble(int rowId) {
240242 @ Override
241243 public BigDecimal getDecimal (int rowId , int precision , int scale ) {
242244 long rowIdAddr = (long ) rowId * fixedLength + dataAddr ;
245+ // avoid unsigned long overflow here
246+ if (type == DecimalType .BIG_INT_DECIMAL ) {
247+ return new BigDecimal (UnsignedLong .fromLongBits (this .getLong (rowId )).bigIntegerValue ());
248+ }
243249 if (fixedLength == 4 ) {
244250 return MemoryUtil .getDecimal32 (rowIdAddr , scale );
245251 } else if (fixedLength == 8 ) {
You can’t perform that action at this time.
0 commit comments