Skip to content

Commit

Permalink
add test case for index with calc col (#109)
Browse files Browse the repository at this point in the history
* add test case for index with calc col

* add test case for set scan order when query

* add test case for set scan order when query

* modify case

* modify case

* add queryWithScanOrder to CI test

* remove queryWithScanOrder in ci test
  • Loading branch information
GroundWu authored Apr 1, 2024
1 parent 51ee6ba commit a2536ca
Show file tree
Hide file tree
Showing 3 changed files with 470 additions and 0 deletions.
48 changes: 48 additions & 0 deletions src/test/java/com/alipay/oceanbase/rpc/ObTableClientTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import com.alipay.oceanbase.rpc.property.Property;
import com.alipay.oceanbase.rpc.protocol.payload.ObPayload;
import com.alipay.oceanbase.rpc.protocol.payload.ResultCodes;
import com.alipay.oceanbase.rpc.protocol.payload.impl.ObObj;
import com.alipay.oceanbase.rpc.protocol.payload.impl.execute.aggregation.ObTableAggregation;
import com.alipay.oceanbase.rpc.protocol.payload.impl.execute.aggregation.ObTableAggregationResult;
import com.alipay.oceanbase.rpc.protocol.payload.impl.execute.mutate.ObTableQueryAndMutateRequest;
Expand Down Expand Up @@ -2525,4 +2526,51 @@ public void testQueryWithEmptyTable() throws Exception {
Assert.assertEquals("table name is null", ((IllegalArgumentException) e).getMessage());
}
}

@Test
public void testQueryWithScanOrder() throws Exception {
String tableName = "test_query_scan_order";
((ObTableClient) client).addRowKeyElement(tableName, new String[]{"c1"});
try {
client.insert(tableName, new Object[] { 0, 1 }, new String[] { "c3" },
new Object[] { 2 });
client.insert(tableName, new Object[] { 0, 2 }, new String[] { "c3" },
new Object[] { 1 });
// Forward
Object[] start = {0, ObObj.getMin()};
Object[] end = {1, ObObj.getMax()};
QueryResultSet resultSet = client.query(tableName).indexName("idx")
.setScanRangeColumns("c1", "c3")
.addScanRange(start, end)
.scanOrder(true)
.select("c1", "c2", "c3")
.execute();
Assert.assertEquals(2, resultSet.cacheSize());
int pre_value = 0;
while(resultSet.next()) {
Map<String, Object> valueMap = resultSet.getRow();
Assert.assertTrue(pre_value < (int)valueMap.get("c3") );
pre_value = (int)valueMap.get("c3");
}
// Reverse
QueryResultSet resultSet2 = client.query(tableName).indexName("idx")
.setScanRangeColumns("c1", "c3")
.addScanRange(start, end)
.scanOrder(false)
.select("c1", "c2", "c3")
.execute();
Assert.assertEquals(2, resultSet2.cacheSize());
pre_value = 3;
while(resultSet2.next()) {
Map<String, Object> valueMap = resultSet2.getRow();
Assert.assertTrue(pre_value > (int)valueMap.get("c3") );
pre_value = (int)valueMap.get("c3");
}
} catch (Exception e) {
e.printStackTrace();
} finally {
client.delete(tableName, new Object[] { 0, 1 });
client.delete(tableName, new Object[] { 0, 2 });
}
}
}
Loading

0 comments on commit a2536ca

Please sign in to comment.