Skip to content

Commit b494b20

Browse files
committed
adapt fulltext query
1 parent 07ec674 commit b494b20

File tree

3 files changed

+16
-6
lines changed

3 files changed

+16
-6
lines changed

src/main/java/com/alipay/oceanbase/rpc/protocol/payload/impl/execute/query/ObTableQuery.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ public class ObTableQuery extends AbstractPayload {
6969

7070
private static final byte[] HTABLE_DUMMY_BYTES = new byte[] { 0x01, 0x00 };
7171
private boolean isHbaseQuery = false;
72+
private boolean isFTSQuery = true;
7273
private List<String> scanRangeColumns = new LinkedList<String>();
7374

7475
private List<ObTableAggregationSingle> aggregations = new LinkedList<>();
@@ -552,18 +553,21 @@ public void setObKVParams(ObKVParams obKVParams) {
552553
}
553554

554555
public void setSearchText(String searchText) {
555-
if (isHbaseQuery) {
556+
if (this.isHbaseQuery) {
556557
throw new FeatureNotSupportedException("Hbase query not support full text search currently");
557558
}
558-
if (obKVParams == null) {
559+
if (this.obKVParams == null) {
559560
obKVParams = new ObKVParams();
560561
}
561562
ObFTSParams ftsParams = (ObFTSParams)obKVParams.getObParams(ObKVParamsBase.paramType.FTS);
562563
ftsParams.setSearchText(searchText);
563-
obKVParams.setObParamsBase(ftsParams);
564+
this.obKVParams.setObParamsBase(ftsParams);
565+
this.isFTSQuery = true;
564566
}
565567

566568
public ObKVParams getObKVParams() {
567569
return obKVParams;
568570
}
571+
572+
public boolean isFTSQuery() { return isFTSQuery; }
569573
}

src/main/java/com/alipay/oceanbase/rpc/table/ObTableClientQueryImpl.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,10 @@ private AbstractQueryStreamResult commonExecute(InitQueryResultCallback<Abstract
160160
// fill a whole range if no range is added explicitly.
161161
if (tableQuery.getKeyRanges().isEmpty()) {
162162
tableQuery.addKeyRange(ObNewRange.getWholeRange());
163+
} else if (tableQuery.isFTSQuery()) {
164+
// Currently, fulltext query only support scan all partitions
165+
tableQuery.getKeyRanges().clear();
166+
tableQuery.addKeyRange(ObNewRange.getWholeRange());
163167
}
164168

165169
// init partitionObTables

src/test/java/com/alipay/oceanbase/rpc/ObTableFullTextIndexTest.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public class ObTableFullTextIndexTest {
2727
ObTableClient client;
2828
String tableName = "tbl1";
2929
String ttlTableName = "ttl_tbl1";
30-
String createTableSQL = "CREATE TABLE IF NOT EXISTS tbl1(id INT, c2 INT, txt text, PRIMARY KEY (id), FULLTEXT INDEX full_idx1_tbl1(txt));";
30+
String createTableSQL = "CREATE TABLE IF NOT EXISTS tbl1(id INT, c2 INT, txt text, PRIMARY KEY (id), FULLTEXT INDEX full_idx1_tbl1(txt)) partition by key(id) partitions 3;";
3131
String createTTLTableSQL = "CREATE TABLE IF NOT EXISTS ttl_tbl1(id INT, c2 INT, txt text, expired_ts timestamp(6), PRIMARY KEY (id), FULLTEXT INDEX full_idx1_tbl1(txt)) TTL(expired_ts + INTERVAL 10 SECOND);;";
3232
String truncateTableSQL = "truncate table tbl1;";
3333
String truncateTTLTableSQL = "truncate table ttl_tbl1;";
@@ -326,11 +326,13 @@ public void testTTLInsert() throws Exception {
326326
}
327327

328328
@Test
329-
public void testFtsQuery() throws Exception {
329+
public void testFTSQuery() throws Exception {
330330
try {
331+
client.addRowKeyElement(tableName, new String[] {"id"});
332+
331333
//sync query
332334
QueryResultSet resultSet = client.query(tableName)
333-
.setSearchText("native")
335+
.setSearchText("oceanbase")
334336
.indexName("full_idx1_tbl1")
335337
.execute();
336338
while(resultSet.next()) {

0 commit comments

Comments
 (0)