Skip to content

Commit a917c91

Browse files
guojn1rock-git
authored andcommitted
[feature][dingo-sdk] Add codecVersion to tableDefinition
1 parent f1459ae commit a917c91

File tree

6 files changed

+22
-9
lines changed

6 files changed

+22
-9
lines changed

java/dingo-sdk/src/main/java/io/dingodb/sdk/common/codec/DingoKeyValueCodec.java

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,16 @@ public DingoKeyValueCodec(int schemaVersion, long id, List<DingoSchema> schemas)
4646
rd = new RecordDecoder(schemaVersion, schemas, id);
4747
}
4848

49+
public DingoKeyValueCodec(int codecVersion, int schemaVersion, long id, List<DingoSchema> schemas) {
50+
this.schemas = schemas;
51+
this.id = id;
52+
re = new RecordEncoder(codecVersion, schemaVersion, schemas, id);
53+
rd = new RecordDecoder(schemaVersion, schemas, id);
54+
}
55+
4956
public static DingoKeyValueCodec of(Table table) {
5057
return of(
58+
table.getCodecVersion(),
5159
table.getVersion(),
5260
Optional.mapOrGet(table.id(), DingoCommonId::entityId, () -> 0L),
5361
table.getColumns()
@@ -58,16 +66,16 @@ public static DingoKeyValueCodec of(long id, Table table) {
5866
return of(table.getVersion(), id, table);
5967
}
6068

61-
public static DingoKeyValueCodec of(long id, List<Column> columns) {
62-
return of(1, id, columns);
69+
public static DingoKeyValueCodec of(int codecVersion, long id, List<Column> columns) {
70+
return of(codecVersion, 1, id, columns);
6371
}
6472

6573
public static DingoKeyValueCodec of(int schemaVersion,long id, Table table) {
66-
return of(schemaVersion, id, table.getColumns());
74+
return of(table.getCodecVersion(), schemaVersion, id, table.getColumns());
6775
}
6876

69-
public static DingoKeyValueCodec of(int schemaVersion, long id, List<Column> columns) {
70-
return new DingoKeyValueCodec(schemaVersion, id, CodecUtils.createSchemaForColumns(columns));
77+
public static DingoKeyValueCodec of(int codecVersion, int schemaVersion, long id, List<Column> columns) {
78+
return new DingoKeyValueCodec(codecVersion, schemaVersion, id, CodecUtils.createSchemaForColumns(columns));
7179
}
7280

7381
@Override

java/dingo-sdk/src/main/java/io/dingodb/sdk/common/table/Table.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ default DingoCommonId id() {
5959

6060
String getCollate();
6161

62+
default int getCodecVersion() {
63+
return 2;
64+
}
65+
6266
default String getTableType() {
6367
return "BASE TABLE";
6468
}

java/dingo-sdk/src/main/java/io/dingodb/sdk/common/table/TableDefinition.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,5 +53,6 @@ public class TableDefinition implements Table {
5353
private String rowFormat;
5454
private long createTime;
5555
private long updateTime;
56+
private int codecVersion;
5657

5758
}

java/dingo-sdk/src/main/java/io/dingodb/sdk/common/utils/EntityConversion.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ public static Partition mapping(long id, Meta.TableDefinition tableDefinition, L
160160
if (partition.getPartitionsCount() < 1) {
161161
return null;
162162
}
163-
DingoKeyValueCodec codec = DingoKeyValueCodec.of(id, columns);
163+
DingoKeyValueCodec codec = DingoKeyValueCodec.of(tableDefinition.getCodecVersion(), id, columns);
164164
List<PartitionDetail> details = partition.getPartitionsList().stream()
165165
.map(Meta.Partition::getRange)
166166
.map(Common.Range::getStartKey)
@@ -863,7 +863,7 @@ public static Meta.PartitionRule calcRange(
863863
DingoCommonId tableId1 = mapping(tableId);
864864
List<Column> keyColumns = table.getKeyColumns();
865865
keyColumns.sort(Comparator.comparingInt(Column::getPrimary));
866-
KeyValueCodec codec = DingoKeyValueCodec.of(tableId1.entityId(), keyColumns);
866+
KeyValueCodec codec = DingoKeyValueCodec.of(table.getCodecVersion(), tableId1.entityId(), keyColumns);
867867
byte[] minKeyPrefix = codec.encodeMinKeyPrefix();
868868
byte[] maxKeyPrefix = codec.encodeMaxKeyPrefix();
869869
Meta.PartitionRule.Builder builder = Meta.PartitionRule.newBuilder();

java/dingo-sdk/src/main/java/io/dingodb/sdk/service/meta/MetaServiceClient.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@ public void addDistribution(String tableName, PartitionDetail partitionDetail) {
426426
);
427427
Table table = mapping(definitionWithId);
428428
DingoCommonId tableId = mapping(definitionWithId.getTableId());
429-
DingoKeyValueCodec codec = DingoKeyValueCodec.of(tableId.entityId(), table.getKeyColumns());
429+
DingoKeyValueCodec codec = DingoKeyValueCodec.of(table.getCodecVersion(), tableId.entityId(), table.getKeyColumns());
430430
try {
431431
byte[] key = codec.encodeKeyPrefix(partitionDetail.getOperand(), partitionDetail.getOperand().length);
432432
RangeDistribution distribution = getRangeDistribution(tableName, new ComparableByteArray(key, POS));

0 commit comments

Comments
 (0)