Skip to content

Commit b789c7b

Browse files
shiyuhang0ti-chi-bot
authored andcommitted
This is an automated cherry-pick of pingcap#2740
Signed-off-by: ti-chi-bot <ti-community-prow-bot@tidb.io>
1 parent 13251eb commit b789c7b

2 files changed

Lines changed: 50 additions & 0 deletions

File tree

core/src/test/scala/org/apache/spark/sql/IssueTestSuite.scala

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,47 @@ import org.apache.spark.sql.functions.{col, sum}
2121

2222
class IssueTestSuite extends BaseTiSparkTest {
2323

24+
<<<<<<< HEAD
25+
=======
26+
test("test tiflash overflow in unsigned bigint") {
27+
if (!enableTiFlashTest) {
28+
cancel("tiflash test not enabled")
29+
}
30+
val dbTable = "tispark_test.tiflash_overflow"
31+
tidbStmt.execute(s"drop table if exists $dbTable")
32+
tidbStmt.execute(
33+
s"CREATE TABLE $dbTable (`a` bigint(20) UNSIGNED NOT NULL,`b` bigint(20) UNSIGNED NOT NULL)")
34+
tidbStmt.execute(s"insert into $dbTable values(16717361816800086255, 16717361816800086255)")
35+
tidbStmt.execute(s"ALTER TABLE $dbTable SET TIFLASH REPLICA 1")
36+
37+
Thread.sleep(5 * 1000)
38+
39+
val prev = spark.conf.getOption(TiConfigConst.ISOLATION_READ_ENGINES)
40+
try {
41+
spark.conf
42+
.set(TiConfigConst.ISOLATION_READ_ENGINES, TiConfigConst.TIFLASH_STORAGE_ENGINE)
43+
val df = spark.sql(s"select * from $dbTable")
44+
val row = Row(BigDecimal("16717361816800086255"), BigDecimal("16717361816800086255"))
45+
checkAnswer(df, Seq(row))
46+
} finally {
47+
spark.conf.set(
48+
TiConfigConst.ISOLATION_READ_ENGINES,
49+
prev.getOrElse(TiConfigConst.DEFAULT_STORAGE_ENGINES))
50+
}
51+
}
52+
53+
test("test issue 2649") {
54+
val dbTable = "tispark_test.mutil_uniq"
55+
tidbStmt.execute(s"drop table if exists $dbTable")
56+
tidbStmt.execute(
57+
s"CREATE TABLE $dbTable (`a` int(5) NOT NULL,`b` int(5) NOT NULL,UNIQUE KEY `idx_ab` (`a`,`b`))")
58+
tidbStmt.execute(s"insert into $dbTable values(0, 0),(1,1)")
59+
val df = spark.sql(s"select * from $dbTable where a=1")
60+
val row1 = Row(1, 1)
61+
checkAnswer(df, Seq(row1))
62+
}
63+
64+
>>>>>>> 044630939 (Fix TiFlash overflow (#2740))
2465
//https://github.com/pingcap/tispark/issues/2268
2566
test("show rowid in commonhandle") {
2667
spark.sqlContext.setConf(TiConfigConst.SHOW_ROWID, "true")

tikv-client/src/main/java/com/pingcap/tikv/columnar/TiBlockColumnVector.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,18 @@
1717

1818
import static com.pingcap.tikv.util.MemoryUtil.EMPTY_BYTE_BUFFER_DIRECT;
1919

20+
<<<<<<< HEAD
2021
import com.pingcap.tikv.ExtendedDateTime;
22+
=======
23+
import com.google.common.primitives.UnsignedLong;
24+
>>>>>>> 044630939 (Fix TiFlash overflow (#2740))
2125
import com.pingcap.tikv.codec.Codec.DateCodec;
2226
import com.pingcap.tikv.codec.Codec.DateTimeCodec;
2327
import com.pingcap.tikv.columnar.datatypes.CHType;
2428
import com.pingcap.tikv.types.AbstractDateTimeType;
2529
import com.pingcap.tikv.types.BytesType;
2630
import com.pingcap.tikv.types.DateType;
31+
import com.pingcap.tikv.types.DecimalType;
2732
import com.pingcap.tikv.util.MemoryUtil;
2833
import java.math.BigDecimal;
2934
import java.nio.ByteBuffer;
@@ -236,6 +241,10 @@ public double getDouble(int rowId) {
236241
@Override
237242
public BigDecimal getDecimal(int rowId, int precision, int scale) {
238243
long rowIdAddr = (long) rowId * fixedLength + dataAddr;
244+
// avoid unsigned long overflow here
245+
if (type == DecimalType.BIG_INT_DECIMAL) {
246+
return new BigDecimal(UnsignedLong.fromLongBits(this.getLong(rowId)).bigIntegerValue());
247+
}
239248
if (fixedLength == 4) {
240249
return MemoryUtil.getDecimal32(rowIdAddr, scale);
241250
} else if (fixedLength == 8) {

0 commit comments

Comments
 (0)