Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesRTaylor committed Feb 4, 2014
2 parents 0b469d4 + d40c506 commit bc21d8e
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ protected QueryPlan compile(SelectStatement select, Scan scan, boolean asSubquer
// TODO: do this normalization outside of this so as it's not repeated by the optimizer
select = StatementNormalizer.normalize(select, resolver);
StatementContext context = new StatementContext(statement, resolver, binds, scan);

context.setScanHints(select.getHint());

if (select.getFrom().size() == 1)
return compileSingleQuery(context, select, binds, parallelIteratorFactory);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
import org.apache.phoenix.jdbc.PhoenixConnection;
import org.apache.phoenix.jdbc.PhoenixStatement;
import org.apache.phoenix.parse.HintNode;
import org.apache.phoenix.parse.HintNode.Hint;
import org.apache.phoenix.query.KeyRange;
import org.apache.phoenix.query.QueryConstants;
import org.apache.phoenix.query.QueryServices;
Expand Down Expand Up @@ -140,6 +142,12 @@ public ScanRanges getScanRanges() {
return this.scanRanges;
}

public void setScanHints(HintNode hints) {
if (hints.hasHint(Hint.NO_CACHE)) {
scan.setCacheBlocks(false);
}
}

public void setScanRanges(ScanRanges scanRanges) {
setScanRanges(scanRanges, null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ public enum Hint {
* the data table when optimizing.
*/
USE_INDEX_OVER_DATA_TABLE,
/**
* Avoid caching any HBase blocks loaded by this query.
*/
NO_CACHE,
};

private final Map<Hint,String> hints;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.fail;

import java.sql.Connection;
Expand Down Expand Up @@ -1282,5 +1283,16 @@ public void testInvalidNextValueFor() throws Exception {
}
}
}


@Test
public void testNoCachingHint() throws Exception {
List<Object> binds = Collections.emptyList();
Scan scan = compileQuery("select val from ptsdb", binds);
assertTrue(scan.getCacheBlocks());
scan = compileQuery("select /*+ NO_CACHE */ val from ptsdb", binds);
assertFalse(scan.getCacheBlocks());
scan = compileQuery("select /*+ NO_CACHE */ p1.val from ptsdb p1 inner join ptsdb p2 on p1.inst = p2.inst", binds);
assertFalse(scan.getCacheBlocks());
}

}

0 comments on commit bc21d8e

Please sign in to comment.