diff --git a/java/dingo-sdk/src/main/java/io/dingodb/sdk/common/codec/DingoKeyValueCodec.java b/java/dingo-sdk/src/main/java/io/dingodb/sdk/common/codec/DingoKeyValueCodec.java index 223b1d74a..b80ffdbe3 100644 --- a/java/dingo-sdk/src/main/java/io/dingodb/sdk/common/codec/DingoKeyValueCodec.java +++ b/java/dingo-sdk/src/main/java/io/dingodb/sdk/common/codec/DingoKeyValueCodec.java @@ -16,20 +16,22 @@ package io.dingodb.sdk.common.codec; +import io.dingodb.sdk.common.DingoCommonId; import io.dingodb.sdk.common.KeyValue; import io.dingodb.sdk.common.serial.RecordDecoder; import io.dingodb.sdk.common.serial.RecordEncoder; import io.dingodb.sdk.common.serial.schema.DingoSchema; import io.dingodb.sdk.common.table.Column; import io.dingodb.sdk.common.table.Table; +import io.dingodb.sdk.common.utils.Optional; import org.checkerframework.checker.nullness.qual.NonNull; -import java.io.IOException; import java.util.List; public class DingoKeyValueCodec implements KeyValueCodec { - private List schemas; + private final long id; + private final List schemas; RecordEncoder re; RecordDecoder rd; @@ -39,16 +41,25 @@ public DingoKeyValueCodec(long id, List schemas) { public DingoKeyValueCodec(int schemaVersion, long id, List schemas) { this.schemas = schemas; + this.id = id; re = new RecordEncoder(schemaVersion, schemas, id); rd = new RecordDecoder(schemaVersion, schemas, id); } + public static DingoKeyValueCodec of(Table table) { + return of( + table.getVersion(), + Optional.mapOrGet(table.id(), DingoCommonId::entityId, () -> 0L), + table.getColumns() + ); + } + public static DingoKeyValueCodec of(long id, Table table) { - return of(table.getVersion(), id, table.getColumns()); + return of(table.getVersion(), id, table); } public static DingoKeyValueCodec of(long id, List columns) { - return new DingoKeyValueCodec(1, id, CodecUtils.createSchemaForColumns(columns)); + return of(1, id, columns); } public static DingoKeyValueCodec of(int schemaVersion,long id, Table table) { @@ -94,6 +105,10 @@ public byte[] encodeMaxKeyPrefix() { return re.encodeMaxKeyPrefix(); } + public byte[] resetPrefix(byte[] key) { + return re.resetKeyPrefix(key, id); + } + @Override public byte[] resetPrefix(byte[] key, long prefix) { return re.resetKeyPrefix(key, prefix); diff --git a/java/dingo-sdk/src/main/java/io/dingodb/sdk/common/codec/KeyValueCodec.java b/java/dingo-sdk/src/main/java/io/dingodb/sdk/common/codec/KeyValueCodec.java index 1ae2b00ff..23839e550 100644 --- a/java/dingo-sdk/src/main/java/io/dingodb/sdk/common/codec/KeyValueCodec.java +++ b/java/dingo-sdk/src/main/java/io/dingodb/sdk/common/codec/KeyValueCodec.java @@ -28,6 +28,10 @@ public interface KeyValueCodec { byte[] encodeKey(Object[] record); + default byte[] encodeKeyPrefix(Object[] record) { + return encodeKeyPrefix(record, record.length); + } + byte[] encodeKeyPrefix(Object[] record, int columnCount); byte[] encodeMinKeyPrefix(); diff --git a/java/dingo-sdk/src/main/java/io/dingodb/sdk/common/partition/Partition.java b/java/dingo-sdk/src/main/java/io/dingodb/sdk/common/partition/Partition.java index 9f9005f96..7c488a3a8 100644 --- a/java/dingo-sdk/src/main/java/io/dingodb/sdk/common/partition/Partition.java +++ b/java/dingo-sdk/src/main/java/io/dingodb/sdk/common/partition/Partition.java @@ -20,8 +20,13 @@ public interface Partition { + @Deprecated String getFuncName(); + default String getStrategy() { + return getFuncName(); + } + List getCols(); List getDetails(); diff --git a/java/dingo-sdk/src/main/java/io/dingodb/sdk/common/partition/PartitionDetail.java b/java/dingo-sdk/src/main/java/io/dingodb/sdk/common/partition/PartitionDetail.java index 097d59d7f..22b1c9e0c 100644 --- a/java/dingo-sdk/src/main/java/io/dingodb/sdk/common/partition/PartitionDetail.java +++ b/java/dingo-sdk/src/main/java/io/dingodb/sdk/common/partition/PartitionDetail.java @@ -16,11 +16,21 @@ package io.dingodb.sdk.common.partition; +import io.dingodb.sdk.common.DingoCommonId; + public interface PartitionDetail { - String getPartName(); + default DingoCommonId id() { + return null; + } + + default String getPartName() { + return null; + } - String getOperator(); + default String getOperator() { + return null; + } Object[] getOperand(); } diff --git a/java/dingo-sdk/src/main/java/io/dingodb/sdk/common/serial/RecordEncoder.java b/java/dingo-sdk/src/main/java/io/dingodb/sdk/common/serial/RecordEncoder.java index 3abe89ec5..b12358b98 100644 --- a/java/dingo-sdk/src/main/java/io/dingodb/sdk/common/serial/RecordEncoder.java +++ b/java/dingo-sdk/src/main/java/io/dingodb/sdk/common/serial/RecordEncoder.java @@ -55,6 +55,13 @@ private void encodeTag(Buf buf) { buf.reverseWrite((byte) 0); } + private void encodeReverseTag(Buf buf) { + buf.reverseWrite(Config.CODEC_VERSION); + buf.reverseWrite((byte) 0); + buf.reverseWrite((byte) 0); + buf.reverseWrite((byte) 0); + } + private void encodeSchemaVersion(Buf buf) { buf.writeInt(schemaVersion); } diff --git a/java/dingo-sdk/src/main/java/io/dingodb/sdk/common/table/Column.java b/java/dingo-sdk/src/main/java/io/dingodb/sdk/common/table/Column.java index 41ea6c324..2f285011f 100644 --- a/java/dingo-sdk/src/main/java/io/dingodb/sdk/common/table/Column.java +++ b/java/dingo-sdk/src/main/java/io/dingodb/sdk/common/table/Column.java @@ -18,6 +18,11 @@ public interface Column { + int DEFAULT_PRECISION = -1; + int DEFAULT_SCALE = Integer.MIN_VALUE; + int DISABLE = 1; + int HIDDEN = 1 << 1; + String getName(); String getType(); @@ -36,10 +41,24 @@ public interface Column { boolean isAutoIncrement(); - int getState(); - String getComment(); + default int getState() { + return DISABLE; + } + + default int getCreateVersion() { + return 1; + } + + default int getUpdateVersion() { + return 1; + } + + default int getDeleteVersion() { + return -1; + } + default boolean isPrimary() { return getPrimary() > -1; } diff --git a/java/dingo-sdk/src/main/java/io/dingodb/sdk/common/table/ColumnDefinition.java b/java/dingo-sdk/src/main/java/io/dingodb/sdk/common/table/ColumnDefinition.java index 2459d9524..183e49420 100644 --- a/java/dingo-sdk/src/main/java/io/dingodb/sdk/common/table/ColumnDefinition.java +++ b/java/dingo-sdk/src/main/java/io/dingodb/sdk/common/table/ColumnDefinition.java @@ -16,26 +16,27 @@ package io.dingodb.sdk.common.table; +import lombok.AllArgsConstructor; import lombok.Builder; import lombok.EqualsAndHashCode; +import lombok.Getter; import lombok.Setter; import lombok.ToString; +@Getter @Builder @ToString @EqualsAndHashCode +@AllArgsConstructor public class ColumnDefinition implements Column { - public static final int DEFAULT_PRECISION = -1; - public static final int DEFAULT_SCALE = Integer.MIN_VALUE; - private String name; private String type; private String elementType; @Builder.Default - private int precision = DEFAULT_PRECISION; + private int precision = Column.DEFAULT_PRECISION; @Builder.Default - private int scale = DEFAULT_SCALE; + private int scale = Column.DEFAULT_SCALE; @Builder.Default private boolean nullable = true; @Builder.Default @@ -48,6 +49,9 @@ public class ColumnDefinition implements Column { @Setter private String comment; + private int createVersion; + private int updateVersion; + private int deleteVersion; @Deprecated public ColumnDefinition( @@ -81,45 +85,11 @@ public String getName() { return name.toUpperCase(); } - @Override - public String getType() { - return type; - } - - @Override - public String getElementType() { - return elementType; - } - - @Override - public int getPrecision() { - return precision; - } - - @Override - public int getScale() { - return scale; - } - - @Override - public boolean isNullable() { - return nullable; - } - @Override public int getPrimary() { return primary < 0 ? -1 : primary; } - @Override - public String getDefaultValue() { - return defaultValue; - } - - @Override - public boolean isAutoIncrement() { - return isAutoIncrement; - } @Override public int getState() { diff --git a/java/dingo-sdk/src/main/java/io/dingodb/sdk/common/table/Table.java b/java/dingo-sdk/src/main/java/io/dingodb/sdk/common/table/Table.java index 4cb4d2213..7638e67b3 100644 --- a/java/dingo-sdk/src/main/java/io/dingodb/sdk/common/table/Table.java +++ b/java/dingo-sdk/src/main/java/io/dingodb/sdk/common/table/Table.java @@ -16,7 +16,7 @@ package io.dingodb.sdk.common.table; -import io.dingodb.common.Common; +import io.dingodb.sdk.common.DingoCommonId; import io.dingodb.sdk.common.index.IndexParameter; import io.dingodb.sdk.common.partition.Partition; @@ -27,6 +27,10 @@ public interface Table { + default DingoCommonId id() { + return null; + } + String getName(); List getColumns(); diff --git a/proto/meta.proto b/proto/meta.proto index 7b611d24c..cb8d3d2df 100644 --- a/proto/meta.proto +++ b/proto/meta.proto @@ -80,6 +80,10 @@ message ColumnDefinition { int32 state = 20; string comment = 30; + + uint32 create_version = 51; + uint32 update_version = 52; + uint32 delete_version = 53; } // Information about Index.