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

[Fix] adapt to lob-related table object type #113

Merged
merged 2 commits into from
Mar 18, 2024
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 @@ -141,19 +141,58 @@ public int getEncodedSize(ObObj obj) {
// 15 ObTableUInt32Type
// 16 ObTableUInt64Type

ObTableInvalidType(17) {
ObTableTinyTextType(17) {
public void decode(ByteBuf buf, ObObj obj) {
decodeWithUtf8(buf, obj);
}
},

ObTableTextType(18) {
public void decode(ByteBuf buf, ObObj obj) {
decodeWithUtf8(buf, obj);
}
},

ObTableMediumTextType(19) {
public void decode(ByteBuf buf, ObObj obj) {
decodeWithUtf8(buf, obj);
}
},

ObTableLongTextType(20) {
public void decode(ByteBuf buf, ObObj obj) {
decodeWithUtf8(buf, obj);
}
},

ObTableTinyBlobType(21) {
},

ObTableBlobType(22) {
},

ObTableMediumBlobType(23) {
},

ObTableLongBlobType(24) {
},

ObTableInvalidType(25) {
};

private int value;
private static Map<Integer, ObTableObjType> map = new HashMap<Integer, ObTableObjType>();
// mapping from value to enum
private static Map<Integer, ObTableObjType> valueMap = new HashMap<Integer, ObTableObjType>();
// mapping from ObTableObjType to ObObjType
private static Map<ObTableObjType, ObObjType> tableObjTypeMap = new HashMap<>();

ObTableObjType(int value) {
this.value = value;
}

static {
for (ObTableObjType type : ObTableObjType.values()) {
map.put(type.value, type);
valueMap.put(type.value, type);
}
}

Expand All @@ -164,7 +203,7 @@ public static ObTableObjType getTableObjType(ObObj obj) {
// only for GET operation default value
return ObTableNullType;
} else if (objType == ObObjType.ObTinyIntType) {
return ObTableObjType.ObTableTinyIntType;
return ObTableTinyIntType;
} else if (objType == ObObjType.ObSmallIntType) {
return ObTableObjType.ObTableSmallIntType;
} else if (objType == ObObjType.ObInt32Type) {
Expand Down Expand Up @@ -197,42 +236,44 @@ public static ObTableObjType getTableObjType(ObObj obj) {
+ objType.getClass().getName());
}

static {
tableObjTypeMap.put(ObTableNullType, ObObjType.ObNullType);
tableObjTypeMap.put(ObTableTinyIntType, ObObjType.ObTinyIntType);
tableObjTypeMap.put(ObTableSmallIntType, ObObjType.ObSmallIntType);
tableObjTypeMap.put(ObTableInt32Type, ObObjType.ObInt32Type);
tableObjTypeMap.put(ObTableInt64Type, ObObjType.ObInt64Type);
tableObjTypeMap.put(ObTableVarcharType, ObObjType.ObVarcharType);
tableObjTypeMap.put(ObTableVarbinaryType, ObObjType.ObVarcharType);
tableObjTypeMap.put(ObTableDoubleType, ObObjType.ObDoubleType);
tableObjTypeMap.put(ObTableFloatType, ObObjType.ObFloatType);
tableObjTypeMap.put(ObTableTimestampType, ObObjType.ObTimestampType);
tableObjTypeMap.put(ObTableDateTimeType, ObObjType.ObDateTimeType);
tableObjTypeMap.put(ObTableTinyTextType, ObObjType.ObTinyTextType);
tableObjTypeMap.put(ObTableTextType, ObObjType.ObTextType);
tableObjTypeMap.put(ObTableMediumTextType, ObObjType.ObMediumTextType);
tableObjTypeMap.put(ObTableLongTextType, ObObjType.ObLongTextType);
tableObjTypeMap.put(ObTableTinyBlobType, ObObjType.ObTinyTextType);
tableObjTypeMap.put(ObTableBlobType, ObObjType.ObTextType);
tableObjTypeMap.put(ObTableMediumBlobType, ObObjType.ObMediumTextType);
tableObjTypeMap.put(ObTableLongBlobType, ObObjType.ObLongTextType);
tableObjTypeMap.put(ObTableMinType, ObObjType.ObExtendType);
tableObjTypeMap.put(ObTableMaxType, ObObjType.ObExtendType);
}

public static ObObjType getObjType(ObTableObjType tableObjType) {
if (tableObjType == ObTableNullType) {
return ObObjType.ObNullType;
} else if (tableObjType == ObTableTinyIntType) {
return ObObjType.ObTinyIntType;
} else if (tableObjType == ObTableSmallIntType) {
return ObObjType.ObSmallIntType;
} else if (tableObjType == ObTableInt32Type) {
return ObObjType.ObInt32Type;
} else if (tableObjType == ObTableInt64Type) {
return ObObjType.ObInt64Type;
} else if (tableObjType == ObTableVarcharType) {
return ObObjType.ObVarcharType;
} else if (tableObjType == ObTableVarbinaryType) {
return ObObjType.ObVarcharType;
} else if (tableObjType == ObTableDoubleType) {
return ObObjType.ObDoubleType;
} else if (tableObjType == ObTableFloatType) {
return ObObjType.ObFloatType;
} else if (tableObjType == ObTableTimestampType) {
return ObObjType.ObTimestampType;
} else if (tableObjType == ObTableDateTimeType) {
return ObObjType.ObDateTimeType;
} else if (tableObjType == ObTableMinType || tableObjType == ObTableMaxType) {
return ObObjType.ObExtendType;
ObObjType objType = tableObjTypeMap.get(tableObjType);
if (objType == null) {
throw new IllegalArgumentException("cannot get ObTableObjType, invalid table obj type: "
+ tableObjType.getClass().getName());
}

throw new IllegalArgumentException("cannot get ObTableObjType, invalid table obj type: "
+ tableObjType.getClass().getName());
return objType;
}

/*
* Value of.
*/
public static ObTableObjType valueOf(int value) {
return map.get(value);
return valueMap.get(value);
}

/*
Expand Down Expand Up @@ -306,6 +347,14 @@ public int getEncodedSizeWithMeta(ObObj obj) {
return len;
}

public void decodeWithUtf8(ByteBuf buf, ObObj obj) {
ObObjType objType = getObjType(this);
ObObjMeta objMeta = objType.getDefaultObjMeta();
objMeta.setCsType(ObCollationType.CS_TYPE_UTF8MB4_GENERAL_CI);
obj.setMeta(objMeta);
obj.setValueFromTableObj(objType.decode(buf, objMeta.getCsType()));
}

public static int DEFAULT_TABLE_OBJ_TYPE_SIZE = 1;
public static int DEFAULT_TABLE_OBJ_META_SIZE = 4;
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,11 @@

import java.util.*;

import static com.alipay.oceanbase.rpc.util.Serialization.encodeObUniVersionHeader;
import static com.alipay.oceanbase.rpc.util.Serialization.getObUniVersionHeaderLength;

public class ObTableLSOperation extends AbstractPayload {

private List<ObTableTabletOp> tabletOperations = new ArrayList<ObTableTabletOp>();
private long lsId = INVALID_LS_ID; // i64

private String tableName;

private long tableId = Constants.OB_INVALID_ID;;
Expand Down Expand Up @@ -335,4 +333,8 @@ public long getLsId() {
return lsId;
}

public void setTableName(String tableName) {
this.tableName = tableName;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,7 @@ public void partitionExecute(ObTableSingleOpResult[] results,
ObTableLSOperation tableLsOp = new ObTableLSOperation();
tableLsOp.setLsId(lsId);
tableLsOp.setReturnOneResult(returnOneResult);
tableLsOp.setTableName(tableName);
// fetch the following parameters in first entry for routing
long tableId = 0;
long originPartId = 0;
Expand Down
47 changes: 38 additions & 9 deletions src/test/java/com/alipay/oceanbase/rpc/ObTableLsBatchTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,15 @@ public void testGet() throws Exception {
`c8` double not null,
`c9` timestamp(6) not null,
`c10` datetime(6) not null,
`c11` int default null
`c11` int default null,
`c12` tinytext DEFAULT NULL,
`c13` text DEFAULT NULL,
`c14` mediumtext DEFAULT NULL,
`c15` longtext DEFAULT NULL,
`c16` tinyblob DEFAULT NULL,
`c17` blob DEFAULT NULL,
`c18` mediumblob DEFAULT NULL,
`c19` longblob DEFAULT NULL
);
*/
@Test
Expand All @@ -176,13 +184,25 @@ public void testGetAllObjType() throws Exception {

// prepare data
Object values[][] = {
{(byte)1, (short)1, (int)1, 1L, "c5_val", "c6_val".getBytes(), 100.0f, 200.0d, c9Val, c10Val, null},
{(byte)2, (short)2, (int)2, 2L, "c5_val", "c6_val".getBytes(), 100.0f, 200.0d, c9Val, c10Val, null},
{(byte)3, (short)3, (int)3, 3L, "c5_val", "c6_val".getBytes(), 100.0f, 200.0d, c9Val, c10Val, null},
{(byte)4, (short)4, (int)4, 4L, "c5_val", "c6_val".getBytes(), 100.0f, 200.0d, c9Val, c10Val, null},
{(byte)5, (short)5, (int)5, 5L, "c5_val", "c6_val".getBytes(), 100.0f, 200.0d, c9Val, c10Val, null},
{(byte)6, (short)6, (int)6, 6L, "c5_val", "c6_val".getBytes(), 100.0f, 200.0d, c9Val, c10Val, null}
};
{(byte)1, (short)1, (int)1, 1L, "c5_val", "c6_val".getBytes(), 100.0f, 200.0d, c9Val, c10Val, null,
"c12_val", "c13_val", "c14_val", "c15_val", "c16_val".getBytes(), "c17_val".getBytes(),
"c18_val".getBytes(), "c19_val".getBytes()},
{(byte)2, (short)2, (int)2, 2L, "c5_val", "c6_val".getBytes(), 100.0f, 200.0d, c9Val, c10Val, null,
"c12_val", "c13_val", "c14_val", "c15_val", "c16_val".getBytes(), "c17_val".getBytes(),
"c18_val".getBytes(), "c19_val".getBytes()},
{(byte)3, (short)3, (int)3, 3L, "c5_val", "c6_val".getBytes(), 100.0f, 200.0d, c9Val, c10Val, null,
"c12_val", "c13_val", "c14_val", "c15_val", "c16_val".getBytes(), "c17_val".getBytes(),
"c18_val".getBytes(), "c19_val".getBytes()},
{(byte)4, (short)4, (int)4, 4L, "c5_val", "c6_val".getBytes(), 100.0f, 200.0d, c9Val, c10Val, null,
"c12_val", "c13_val", "c14_val", "c15_val", "c16_val".getBytes(), "c17_val".getBytes(),
"c18_val".getBytes(), "c19_val".getBytes()},
{(byte)5, (short)5, (int)5, 5L, "c5_val", "c6_val".getBytes(), 100.0f, 200.0d, c9Val, c10Val, null,
"c12_val", "c13_val", "c14_val", "c15_val", "c16_val".getBytes(), "c17_val".getBytes(),
"c18_val".getBytes(), "c19_val".getBytes()},
{(byte)6, (short)6, (int)6, 6L, "c5_val", "c6_val".getBytes(), 100.0f, 200.0d, c9Val, c10Val, null,
"c12_val", "c13_val", "c14_val", "c15_val", "c16_val".getBytes(), "c17_val".getBytes(),
"c18_val".getBytes(), "c19_val".getBytes()}
};

int rowCnt = values.length;

Expand Down Expand Up @@ -212,7 +232,8 @@ public void testGetAllObjType() throws Exception {
for (int i = 0; i < rowCnt; i++) {
Object[] curRow = values[i];
TableQuery query = query().setRowKey(row(colVal("c1", curRow[0])))
.select("c1", "c2", "c3", "c4", "c5", "c6", "c7", "c8", "c9", "c10", "c11");
.select("c1", "c2", "c3", "c4", "c5", "c6", "c7", "c8", "c9", "c10",
"c11", "c12", "c13", "c14", "c15", "c16", "c17", "c18", "c19");
batchOperation.addOperation(query);
}
BatchOperationResult res = batchOperation.execute();
Expand All @@ -235,6 +256,14 @@ public void testGetAllObjType() throws Exception {
{
// get columns idx, 1 means get c1
int columns[][] = {
{3, 8, 14, 11, 18, 5, 12, 6, 19, 10, 15, 7, 1, 4, 9, 13, 2, 16, 17},
{5, 15, 6, 10, 2, 12, 7, 17, 18, 11, 3, 8, 13, 1, 16, 4, 9, 14},
{13, 10, 5, 15, 1, 8, 11, 9, 7, 16, 4, 17, 6, 2, 12, 3, 14},
{14, 6, 9, 2, 5, 3, 15, 10, 12, 8, 11, 7, 1, 16, 4, 13},
{11, 3, 7, 12, 8, 10, 4, 6, 15, 2, 5, 1, 14, 9, 13},
{8, 12, 5, 14, 3, 7, 1, 11, 6, 9, 10, 2, 4, 13},
{10, 4, 13, 1, 8, 7, 5, 11, 6, 3, 12, 2, 9},
{9, 3, 10, 5, 7, 1, 8, 6, 11, 4, 12, 2},
{7, 3, 11, 5, 6, 2, 9, 1, 8, 4, 10},
{5, 2, 7, 9, 1, 8, 6, 3, 10, 4},
{5, 3, 1, 8, 6, 4, 7, 2, 9},
Expand Down
11 changes: 10 additions & 1 deletion src/test/resources/ci.sql
Original file line number Diff line number Diff line change
Expand Up @@ -444,8 +444,17 @@ CREATE TABLE IF NOT EXISTS `test_table_object` (
`c8` double not null,
`c9` timestamp(6) not null,
`c10` datetime(6) not null,
`c11` int default null
`c11` int default null,
`c12` tinytext DEFAULT NULL,
`c13` text DEFAULT NULL,
`c14` mediumtext DEFAULT NULL,
`c15` longtext DEFAULT NULL,
`c16` tinyblob DEFAULT NULL,
`c17` blob DEFAULT NULL,
`c18` mediumblob DEFAULT NULL,
`c19` longblob DEFAULT NULL
);

CREATE TABLE IF NOT EXISTS `test_put` (
`id` varchar(20) NOT NULL,
`c1` bigint DEFAULT NULL,
Expand Down
Loading