Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compatible with TiDB mater (v6.5.0) (#2598) #2603

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,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 @@ -110,7 +110,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
15 changes: 8 additions & 7 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,15 +19,16 @@
import com.pingcap.tikv.codec.CodecDataInput;
import com.pingcap.tikv.codec.CodecDataOutput;
import com.pingcap.tikv.exception.CodecException;
import com.pingcap.tikv.types.Converter;
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 @@ -69,16 +70,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 @@ -29,7 +29,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 @@ -93,13 +93,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();
}

/**
Expand Down