Skip to content

Commit

Permalink
Fix column mismatch (#2785) (#2786)
Browse files Browse the repository at this point in the history
* This is an automated cherry-pick of #2785

Signed-off-by: ti-chi-bot <[email protected]>

* Update IssueTestSuite.scala

* Update IssueTestSuite.scala

---------

Signed-off-by: ti-chi-bot <[email protected]>
Co-authored-by: shi yuhang <[email protected]>
  • Loading branch information
ti-chi-bot and shiyuhang0 committed Jul 25, 2024
1 parent 4cae586 commit ac3b26a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
12 changes: 12 additions & 0 deletions core/src/test/scala/org/apache/spark/sql/IssueTestSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,18 @@ import org.apache.spark.sql.functions.{col, sum}

class IssueTestSuite extends BaseTiSparkTest {

test("test column mismatch, issue 2750") {
val dbTable = "tispark_test.column_mismatch"
tidbStmt.execute(s"drop table if exists $dbTable")
tidbStmt.execute(
s"CREATE TABLE $dbTable (`CI_NO` varchar(64) NOT NULL, `AC_DT` bigint(20) NOT NULL, `YM_DT` bigint(20) NOT NULL,`SYS_TYPE` varchar(20) NOT NULL, PRIMARY KEY (`CI_NO`,`AC_DT`,`YM_DT`,`SYS_TYPE`) /*T![clustered_index] CLUSTERED */, KEY `IDX_FLOW_01` (`CI_NO`,`AC_DT`))")
tidbStmt.execute(s"insert into $dbTable values('1',1,1,'1')")
spark.sql(s"select ci_no,ac_dt from $dbTable").explain()
spark.sqlContext.setConf(TiConfigConst.USE_INDEX_SCAN_FIRST, "true")
spark.sql(s"select * from $dbTable").show()
spark.sqlContext.setConf(TiConfigConst.USE_INDEX_SCAN_FIRST, "false")
}

test("test tiflash overflow in unsigned bigint") {
if (!enableTiFlashTest) {
cancel("tiflash test not enabled")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,14 @@ private void addIndexReaderIndexRangeScanExecutorCols(
+ columnInfo.getName());
}
}
if (tableInfo.isCommonHandle()) {
for (TiIndexColumn col : tableInfo.getPrimaryKey().getIndexColumns()) {
TiColumnInfo columnInfo = tableInfo.getColumn(col.getName());
// add primary columns to columns:
// https://github.com/pingcap/tidb/blob/ddcaadbb856f0890e91e4c77991f0d2aa5aa93d0/pkg/planner/core/planbuilder.go#L1515
indexScanBuilder.addColumns(ColumnInfo.newBuilder(columnInfo.toProto(tableInfo)));
}
}
}

private void addIndexColsToScanBuilder(
Expand Down

0 comments on commit ac3b26a

Please sign in to comment.