Skip to content

Commit 97c560f

Browse files
committed
adapt fulltext query
1 parent 0c4cdf2 commit 97c560f

File tree

3 files changed

+19
-9
lines changed

3 files changed

+19
-9
lines changed

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

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,10 @@ public class ObTableQuery extends AbstractPayload {
6868
protected long maxResultSize = -1;
6969
protected ObHTableFilter hTableFilter;
7070

71-
protected static final byte[] HTABLE_DUMMY_BYTES = new byte[] { 0x01, 0x00 };
72-
protected boolean isHbaseQuery = false;
73-
protected List<String> scanRangeColumns = new LinkedList<String>();
71+
private static final byte[] HTABLE_DUMMY_BYTES = new byte[] { 0x01, 0x00 };
72+
private boolean isHbaseQuery = false;
73+
private boolean isFTSQuery = true;
74+
private List<String> scanRangeColumns = new LinkedList<String>();
7475

7576
protected List<ObTableAggregationSingle> aggregations = new LinkedList<>();
7677

@@ -561,18 +562,21 @@ public void setObKVParams(ObKVParams obKVParams) {
561562
}
562563

563564
public void setSearchText(String searchText) {
564-
if (isHbaseQuery) {
565+
if (this.isHbaseQuery) {
565566
throw new FeatureNotSupportedException("Hbase query not support full text search currently");
566567
}
567-
if (obKVParams == null) {
568+
if (this.obKVParams == null) {
568569
obKVParams = new ObKVParams();
569570
}
570571
ObFTSParams ftsParams = (ObFTSParams)obKVParams.getObParams(ObKVParamsBase.paramType.FTS);
571572
ftsParams.setSearchText(searchText);
572-
obKVParams.setObParamsBase(ftsParams);
573+
this.obKVParams.setObParamsBase(ftsParams);
574+
this.isFTSQuery = true;
573575
}
574576

575577
public ObKVParams getObKVParams() {
576578
return obKVParams;
577579
}
580+
581+
public boolean isFTSQuery() { return isFTSQuery; }
578582
}

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

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

164168
// 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)