tasks) {
return getHandleIterator(dagRequest, tasks, session);
}
diff --git a/src/main/java/org/tikv/common/codec/Codec.java b/src/main/java/org/tikv/common/codec/Codec.java
index 642b6fc8c70..933bd312211 100644
--- a/src/main/java/org/tikv/common/codec/Codec.java
+++ b/src/main/java/org/tikv/common/codec/Codec.java
@@ -32,10 +32,18 @@
import org.joda.time.LocalDate;
import org.joda.time.LocalDateTime;
import org.tikv.common.ExtendedDateTime;
+import org.tikv.common.exception.CodecException;
import org.tikv.common.exception.ConvertOverflowException;
import org.tikv.common.exception.InvalidCodecFormatException;
import org.tikv.common.exception.TypeException;
import org.tikv.common.exception.UnsupportedSyntaxException;
+import org.tikv.common.types.BytesType;
+import org.tikv.common.types.DataType;
+import org.tikv.common.types.DecimalType;
+import org.tikv.common.types.IntegerType;
+import org.tikv.common.types.JsonType;
+import org.tikv.common.types.RealType;
+import org.tikv.common.types.TimeType;
public class Codec {
@@ -57,6 +65,41 @@ public static boolean isNullFlag(int flag) {
return flag == NULL_FLAG;
}
+ public static Object decodeOne(byte[] colData) {
+ if (colData.length <= 1) {
+ throw new CodecException("invalid encoded column data, length <=1");
+ }
+ int flag = colData[0];
+ DataType tp;
+ switch (flag) {
+ case INT_FLAG:
+ case UINT_FLAG:
+ case VARINT_FLAG:
+ case UVARINT_FLAG:
+ tp = IntegerType.BIGINT;
+ break;
+ case FLOATING_FLAG:
+ tp = RealType.DOUBLE;
+ break;
+ case BYTES_FLAG:
+ case COMPACT_BYTES_FLAG:
+ tp = BytesType.TEXT;
+ break;
+ case DECIMAL_FLAG:
+ tp = DecimalType.DECIMAL;
+ break;
+ case DURATION_FLAG:
+ tp = TimeType.TIME;
+ break;
+ case JSON_FLAG:
+ tp = JsonType.JSON;
+ break;
+ default:
+ throw new CodecException("Unknown type");
+ }
+ return tp.decode(new CodecDataInput(colData));
+ }
+
public static class IntegerCodec {
private static long flipSignBit(long v) {
@@ -603,10 +646,10 @@ public static void writeDateTimeProto(
* Read datetime from packed Long encoded as unsigned var-len integer converting into specified
* timezone
*
- * @see DateTimeCodec#fromPackedLong(long, DateTimeZone)
* @param cdi codec buffer input
* @param tz timezone to interpret datetime parts
* @return decoded ExtendedDateTime using provided timezone
+ * @see DateTimeCodec#fromPackedLong(long, DateTimeZone)
*/
public static ExtendedDateTime readFromUVarInt(CodecDataInput cdi, DateTimeZone tz) {
return DateTimeCodec.fromPackedLong(IntegerCodec.readUVarLong(cdi), tz);
@@ -615,10 +658,10 @@ public static ExtendedDateTime readFromUVarInt(CodecDataInput cdi, DateTimeZone
/**
* Read datetime from packed Long as unsigned fixed-len integer
*
- * @see DateTimeCodec#fromPackedLong(long, DateTimeZone)
* @param cdi codec buffer input
* @param tz timezone to interpret datetime parts
* @return decoded ExtendedDateTime using provided timezone
+ * @see DateTimeCodec#fromPackedLong(long, DateTimeZone)
*/
public static ExtendedDateTime readFromUInt(CodecDataInput cdi, DateTimeZone tz) {
return DateTimeCodec.fromPackedLong(IntegerCodec.readULong(cdi), tz);
@@ -731,9 +774,9 @@ public static void writeDateProto(CodecDataOutput cdo, Date date, DateTimeZone t
* Read date from packed Long encoded as unsigned var-len integer converting into specified
* timezone
*
- * @see DateCodec#fromPackedLong(long)
* @param cdi codec buffer input
* @return decoded DateTime using provided timezone
+ * @see DateCodec#fromPackedLong(long)
*/
public static LocalDate readFromUVarInt(CodecDataInput cdi) {
return DateCodec.fromPackedLong(IntegerCodec.readUVarLong(cdi));
@@ -742,9 +785,9 @@ public static LocalDate readFromUVarInt(CodecDataInput cdi) {
/**
* Read date from packed Long as unsigned fixed-len integer
*
- * @see DateCodec#fromPackedLong(long)
* @param cdi codec buffer input
* @return decoded DateTime using provided timezone
+ * @see DateCodec#fromPackedLong(long)
*/
public static LocalDate readFromUInt(CodecDataInput cdi) {
return DateCodec.fromPackedLong(IntegerCodec.readULong(cdi));
diff --git a/src/main/java/org/tikv/common/codec/CodecDataInput.java b/src/main/java/org/tikv/common/codec/CodecDataInput.java
index 3035c5fbf15..f128579c0a9 100644
--- a/src/main/java/org/tikv/common/codec/CodecDataInput.java
+++ b/src/main/java/org/tikv/common/codec/CodecDataInput.java
@@ -17,9 +17,23 @@
package org.tikv.common.codec;
+import static org.tikv.common.codec.Codec.BYTES_FLAG;
+import static org.tikv.common.codec.Codec.COMPACT_BYTES_FLAG;
+import static org.tikv.common.codec.Codec.DECIMAL_FLAG;
+import static org.tikv.common.codec.Codec.DURATION_FLAG;
+import static org.tikv.common.codec.Codec.FLOATING_FLAG;
+import static org.tikv.common.codec.Codec.INT_FLAG;
+import static org.tikv.common.codec.Codec.NULL_FLAG;
+import static org.tikv.common.codec.Codec.UINT_FLAG;
+
import com.google.protobuf.ByteString;
-import java.io.*;
+import java.io.ByteArrayInputStream;
+import java.io.DataInput;
+import java.io.DataInputStream;
+import java.io.IOException;
+import java.io.InputStream;
import javax.annotation.Nonnull;
+import org.tikv.common.exception.CodecException;
public class CodecDataInput implements DataInput {
protected final DataInputStream inputStream;
@@ -191,6 +205,48 @@ public String readUTF() {
}
}
+ /**
+ * peek the first encoded value and return its length
+ *
+ * @return first encoded value
+ */
+ public int cutOne() {
+ if (available() < 1) {
+ throw new CodecException("invalid encoded key");
+ }
+ int flag = readByte();
+ int a1 = this.available();
+
+ switch (flag) {
+ case NULL_FLAG:
+ case INT_FLAG:
+ case UINT_FLAG:
+ case FLOATING_FLAG:
+ case DURATION_FLAG:
+ Codec.RealCodec.readDouble(this);
+ break;
+ case BYTES_FLAG:
+ Codec.BytesCodec.readBytes(this);
+ break;
+ case COMPACT_BYTES_FLAG:
+ Codec.BytesCodec.readCompactBytes(this);
+ break;
+ case DECIMAL_FLAG:
+ Codec.DecimalCodec.readDecimal(this);
+ break;
+ // case VARINT_FLAG:
+ // l = peekVarint(b);
+ // case UVARINT_FLAG:
+ // l = peekUvarint(b);
+ // case JSON_FLAG:
+ // l = json.PeekBytesAsJSON(b);
+ default:
+ throw new CodecException("invalid encoded key flag " + flag);
+ }
+ int a2 = this.available();
+ return a1 - a2 + 1;
+ }
+
public int peekByte() {
mark(currentPos());
int b = readByte() & 0xFF;
diff --git a/src/main/java/org/tikv/common/codec/TableCodec.java b/src/main/java/org/tikv/common/codec/TableCodec.java
index c0d141d94d2..ec334e6cec3 100644
--- a/src/main/java/org/tikv/common/codec/TableCodec.java
+++ b/src/main/java/org/tikv/common/codec/TableCodec.java
@@ -19,6 +19,9 @@
import java.util.List;
import org.tikv.common.exception.CodecException;
+import org.tikv.common.handle.CommonHandle;
+import org.tikv.common.handle.Handle;
+import org.tikv.common.handle.IntHandle;
import org.tikv.common.meta.TiColumnInfo;
import org.tikv.common.meta.TiTableInfo;
import org.tikv.common.row.Row;
@@ -42,7 +45,7 @@ public static byte[] encodeRow(
return TableCodecV1.encodeRow(columnInfos, values, isPkHandle);
}
- public static Object[] decodeObjects(byte[] value, Long handle, TiTableInfo tableInfo) {
+ public static Object[] decodeObjects(byte[] value, Handle handle, TiTableInfo tableInfo) {
if (value.length == 0) {
throw new CodecException("Decode fails: value length is zero");
}
@@ -52,7 +55,7 @@ public static Object[] decodeObjects(byte[] value, Long handle, TiTableInfo tabl
return TableCodecV1.decodeObjects(value, handle, tableInfo);
}
- public static Row decodeRow(byte[] value, Long handle, TiTableInfo tableInfo) {
+ public static Row decodeRow(byte[] value, Handle handle, TiTableInfo tableInfo) {
if (value.length == 0) {
throw new CodecException("Decode fails: value length is zero");
}
@@ -62,7 +65,10 @@ public static Row decodeRow(byte[] value, Long handle, TiTableInfo tableInfo) {
return TableCodecV1.decodeRow(value, handle, tableInfo);
}
- public static long decodeHandle(byte[] value) {
- return new CodecDataInput(value).readLong();
+ public static Handle decodeHandle(byte[] value, boolean isCommonHandle) {
+ if (isCommonHandle) {
+ return new CommonHandle(value);
+ }
+ return new IntHandle(new CodecDataInput(value).readLong());
}
}
diff --git a/src/main/java/org/tikv/common/codec/TableCodecV1.java b/src/main/java/org/tikv/common/codec/TableCodecV1.java
index b0a1811c054..4a5928126b1 100644
--- a/src/main/java/org/tikv/common/codec/TableCodecV1.java
+++ b/src/main/java/org/tikv/common/codec/TableCodecV1.java
@@ -20,6 +20,7 @@
import java.util.HashMap;
import java.util.List;
import org.tikv.common.codec.Codec.IntegerCodec;
+import org.tikv.common.handle.Handle;
import org.tikv.common.meta.TiColumnInfo;
import org.tikv.common.meta.TiTableInfo;
import org.tikv.common.row.ObjectRowImpl;
@@ -51,7 +52,7 @@ protected static byte[] encodeRow(
return cdo.toBytes();
}
- protected static Object[] decodeObjects(byte[] value, Long handle, TiTableInfo tableInfo) {
+ protected static Object[] decodeObjects(byte[] value, Handle handle, TiTableInfo tableInfo) {
if (handle == null && tableInfo.isPkHandle()) {
throw new IllegalArgumentException("when pk is handle, handle cannot be null");
}
@@ -85,7 +86,7 @@ protected static Object[] decodeObjects(byte[] value, Long handle, TiTableInfo t
return res;
}
- protected static Row decodeRow(byte[] value, Long handle, TiTableInfo tableInfo) {
+ protected static Row decodeRow(byte[] value, Handle handle, TiTableInfo tableInfo) {
return ObjectRowImpl.create(decodeObjects(value, handle, tableInfo));
}
}
diff --git a/src/main/java/org/tikv/common/codec/TableCodecV2.java b/src/main/java/org/tikv/common/codec/TableCodecV2.java
index 1d90737fc43..ef0dd2b12ea 100644
--- a/src/main/java/org/tikv/common/codec/TableCodecV2.java
+++ b/src/main/java/org/tikv/common/codec/TableCodecV2.java
@@ -17,80 +17,104 @@
package org.tikv.common.codec;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
+import org.tikv.common.handle.Handle;
import org.tikv.common.meta.TiColumnInfo;
+import org.tikv.common.meta.TiIndexColumn;
+import org.tikv.common.meta.TiIndexInfo;
import org.tikv.common.meta.TiTableInfo;
import org.tikv.common.row.ObjectRowImpl;
import org.tikv.common.row.Row;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+
public class TableCodecV2 {
- /**
- * New Row Format: Reference
- * https://github.com/pingcap/tidb/blob/952d1d7541a8e86be0af58f5b7e3d5e982bab34e/docs/design/2018-07-19-row-format.md
- *
- * - version, flag, numOfNotNullCols, numOfNullCols, notNullCols, nullCols, notNullOffsets,
- * notNullValues
- */
- protected static byte[] encodeRow(
- List columnInfos, Object[] values, boolean isPkHandle) {
- RowEncoderV2 encoder = new RowEncoderV2();
- List columnInfoList = new ArrayList<>();
- List