Skip to content

Commit

Permalink
This is an automated cherry-pick of pingcap#2598
Browse files Browse the repository at this point in the history
Signed-off-by: ti-chi-bot <ti-community-prow-bot@tidb.io>
  • Loading branch information
shiyuhang0 authored and ti-chi-bot committed Dec 9, 2022
1 parent 6db125a commit 52fd7b7
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class AutoIncrementSuite extends BaseBatchWriteTest("test_datasource_auto_increm
val schema = StructType(List(StructField("j", LongType)))

jdbcUpdate(
s"create table $dbtable(i int NOT NULL AUTO_INCREMENT, j int NOT NULL, primary key (i)) SHARD_ROW_ID_BITS=4")
s"create table $dbtable(i int NOT NULL AUTO_INCREMENT, j int NOT NULL, primary key (i)/*T![clustered_index] NONCLUSTERED */) SHARD_ROW_ID_BITS=4")

val tiTableInfo = ti.tiSession.getCatalog.getTable(dbPrefix + database, table)
assert(!tiTableInfo.isPkHandle)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,9 @@ case class IndexInfo(
isUnique: Boolean) {

def toString(isClusteredIndex: Boolean): String = {
val clusteredIndexStr = if (isClusteredIndex) " /*T![clustered_index] CLUSTERED */" else ""
val clusteredIndexStr =
if (isClusteredIndex) " /*T![clustered_index] CLUSTERED */"
else "/*T![clustered_index] NONCLUSTERED */"
val indexColumnString = indexColumns.mkString("(", ",", ")")
if (isPrimary) {
s"PRIMARY KEY $indexColumnString$clusteredIndexStr"
Expand Down
18 changes: 12 additions & 6 deletions tikv-client/src/main/java/com/pingcap/tikv/key/CommonHandle.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,22 @@
import com.pingcap.tikv.codec.Codec;
import com.pingcap.tikv.codec.CodecDataInput;
import com.pingcap.tikv.codec.CodecDataOutput;
<<<<<<< HEAD:tikv-client/src/main/java/com/pingcap/tikv/key/CommonHandle.java
import com.pingcap.tikv.exception.CodecException;
import com.pingcap.tikv.types.Converter;
=======
import com.pingcap.tikv.key.Key;
>>>>>>> 47d082c7c (Compatible with TiDB mater (v6.5.0) (#2598)):tikv-client/src/main/java/com/pingcap/tikv/handle/CommonHandle.java
import com.pingcap.tikv.types.DataType;
import com.pingcap.tikv.types.MySQLType;
import com.pingcap.tikv.util.FastByteComparisons;
import java.sql.Date;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.TimeZone;
import java.util.stream.Collectors;
import org.joda.time.Days;
import org.joda.time.LocalDate;
Expand Down Expand Up @@ -70,16 +76,16 @@ public static CommonHandle newCommonHandle(
// When indexScan or tableScan, it will pass `Long` object.
// It's a compromise here since we don't have a good way to make them consistent.
if (data[i] instanceof Date) {
days = Days.daysBetween(new LocalDate(0), new LocalDate(data[i])).getDays();
days = Days.daysBetween(new LocalDate(1970, 1, 1), new LocalDate(data[i])).getDays();
} else {
days = (long) data[i];
}

// Convert to UTC days for row key.
if (Converter.getLocalTimezone().getOffset(0) < 0) {
days += 1;
}
dataTypes[i].encode(cdo, DataType.EncodeType.KEY, new Date((days) * MS_OF_ONE_DAY));
SimpleDateFormat utcFmt = new SimpleDateFormat("yyyy-MM-dd");
utcFmt.setTimeZone(TimeZone.getTimeZone("UTC"));

dataTypes[i].encode(
cdo, DataType.EncodeType.KEY, Date.valueOf(utcFmt.format(days * MS_OF_ONE_DAY)));
} else {
if (prefixLengthes[i] > 0 && data[i] instanceof String) {
String source = (String) data[i];
Expand Down
11 changes: 3 additions & 8 deletions tikv-client/src/main/java/com/pingcap/tikv/types/DateType.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
import org.joda.time.LocalDate;

public class DateType extends AbstractDateTimeType {
private static final LocalDate EPOCH = new LocalDate(0);
private static final LocalDate EPOCH = new LocalDate(1970, 1, 1);
public static final DateType DATE = new DateType(MySQLType.TypeDate);
public static final MySQLType[] subTypes = new MySQLType[] {MySQLType.TypeDate};

Expand Down Expand Up @@ -94,13 +94,8 @@ public String getName() {
}

public int getDays(LocalDate d) {
// count how many days from EPOCH
int days = Days.daysBetween(EPOCH, d).getDays();
// if the timezone has negative offset, minus one day.
if (getTimezone().getOffset(0) < 0) {
days -= 1;
}
return days;
// count how many days from EPOCH (UTC)
return Days.daysBetween(EPOCH, d).getDays();
}

/** {@inheritDoc} */
Expand Down

0 comments on commit 52fd7b7

Please sign in to comment.