Skip to content

Commit

Permalink
Switch to explicitly specifying index conditions in query
Browse files Browse the repository at this point in the history
  • Loading branch information
ghelmling committed Jan 27, 2010
1 parent 03b1966 commit 510079b
Show file tree
Hide file tree
Showing 11 changed files with 41 additions and 27 deletions.
1 change: 1 addition & 0 deletions src/java/meetup/beeno/Criteria.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import meetup.beeno.filter.WhileMatchFilter;
import meetup.beeno.mapping.EntityInfo;
import meetup.beeno.mapping.FieldMapping;
import meetup.beeno.mapping.MappingException;
import meetup.beeno.util.IOUtil;
import meetup.beeno.util.PBUtil;

Expand Down
1 change: 1 addition & 0 deletions src/java/meetup/beeno/EntityService.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import meetup.beeno.mapping.EntityMetadata;
import meetup.beeno.mapping.FieldMapping;
import meetup.beeno.mapping.IndexMapping;
import meetup.beeno.mapping.MappingException;
import meetup.beeno.util.HUtil;
import meetup.beeno.util.PBUtil;

Expand Down
19 changes: 5 additions & 14 deletions src/java/meetup/beeno/Query.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import meetup.beeno.mapping.EntityInfo;
import meetup.beeno.mapping.EntityMetadata;
import meetup.beeno.mapping.MappingException;

import org.apache.hadoop.hbase.client.Result;
import org.apache.hadoop.hbase.client.ResultScanner;
Expand Down Expand Up @@ -74,19 +75,9 @@ public List<T> execute() throws HBaseException {
ResultScanner scanner = null;
int processCnt = 0;
try {
scanner = getStrategy().createScanner(this.entityInfo, this.opts, baseFilter);
scanner = getStrategy(baseFilter).createScanner();
for (Result res : scanner) {
processCnt++;
// re-apply the basic criteria filter to exclude the start row, if it doesn't
// match but was allowed for indexing purposes
// FIXME: GH - hack to work around secondary index filtering issues
/*
if (baseFilter.filterRowKey(res.getRow()) || baseFilter.filterRow(res)) {
if (log.isDebugEnabled())
log.debug("Skipping row: "+Bytes.toString(res.getRow()));
continue;
}
*/
T entity = this.service.createFromRow(res);
if (entity != null)
entities.add( entity );
Expand Down Expand Up @@ -114,12 +105,12 @@ public T executeSingle() throws HBaseException {
return null;
}

protected QueryStrategy getStrategy() {
protected QueryStrategy getStrategy(Filter baseFilter) {
QueryStrategy strat = null;
if (this.opts.shouldUseIndex() && !this.indexCriteria.isEmpty())
strat = new ScanByIndex();
strat = new ScanByIndex(this.entityInfo, this.opts, this.indexCriteria, baseFilter);
else
strat = new ScanNoIndex();
strat = new ScanNoIndex(this.entityInfo, this.opts, baseFilter);

log.debug("Using strategy impl.: "+strat.getClass().getSimpleName());
return strat;
Expand Down
3 changes: 1 addition & 2 deletions src/java/meetup/beeno/QueryStrategy.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
*/
public interface QueryStrategy {

ResultScanner createScanner(EntityInfo info, QueryOpts opts, Filter baseFilter)
throws QueryException;
ResultScanner createScanner() throws QueryException;

}
16 changes: 14 additions & 2 deletions src/java/meetup/beeno/ScanByIndex.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,24 @@
*/
public class ScanByIndex implements QueryStrategy {
private static Logger log = Logger.getLogger(ScanByIndex.class);

private final EntityInfo info;
private final QueryOpts opts;
private final Criteria indexConditions;
private final Filter baseFilter;

public ScanByIndex( EntityInfo info, QueryOpts opts, Criteria indexConditions, Filter baseFilter ) {
this.info = info;
this.opts = opts;
this.indexConditions = indexConditions;
this.baseFilter = baseFilter;
}

/* (non-Javadoc)
* @see com.meetup.db.hbase.QueryStrategy#createScanner(com.meetup.db.hbase.EntityMetadata.EntityInfo, org.apache.hadoop.hbase.filter.RowFilterInterface)
*/
@Override
public ResultScanner createScanner( EntityInfo info, QueryOpts opts, Filter baseFilter )
public ResultScanner createScanner()
throws QueryException {

ResultScanner scanner = null;
Expand All @@ -46,7 +58,7 @@ public ResultScanner createScanner( EntityInfo info, QueryOpts opts, Filter base

try {
table = HUtil.getTable(info.getTablename());
Criteria.PropertyExpression indexedExpr = selectIndexedExpression(info, opts.getCriteria().getExpressions());
Criteria.PropertyExpression indexedExpr = selectIndexedExpression(info, indexConditions.getExpressions());
if (indexedExpr != null) {
log.debug("Using indexed expression: "+indexedExpr);
IndexMapping idx = info.getFirstPropertyIndex(indexedExpr.getProperty());
Expand Down
14 changes: 10 additions & 4 deletions src/java/meetup/beeno/ScanNoIndex.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,24 @@
public class ScanNoIndex implements QueryStrategy {
private static Logger log = Logger.getLogger(ScanNoIndex.class);

public ScanNoIndex() {
private final EntityInfo info;
private final QueryOpts opts;
private final Filter baseFilter;

public ScanNoIndex( EntityInfo entityInfo, QueryOpts opts, Filter baseFilter ) {
this.info = entityInfo;
this.opts = opts;
this.baseFilter = baseFilter;
}

@Override
public ResultScanner createScanner( EntityInfo entityInfo, QueryOpts opts, Filter baseFilter )
throws QueryException {
public ResultScanner createScanner() throws QueryException {
ResultScanner scanner = null;

Scan scan = new Scan();
HTable table = null;
try {
table = HUtil.getTable(entityInfo.getTablename());
table = HUtil.getTable(info.getTablename());

scan.setFilter(baseFilter);
log.debug("Using filter: "+baseFilter);
Expand Down
1 change: 0 additions & 1 deletion src/java/meetup/beeno/mapping/EntityMetadata.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import meetup.beeno.HBaseEntity;
import meetup.beeno.HProperty;
import meetup.beeno.HRowKey;
import meetup.beeno.MappingException;

import org.apache.hadoop.hbase.client.HTable;
import org.apache.hadoop.hbase.client.HTablePool;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
package meetup.beeno;
package meetup.beeno.mapping;

import meetup.beeno.HBaseException;

public class MappingException extends HBaseException {

Expand Down
3 changes: 2 additions & 1 deletion test/jython/dbtest/hbase/test_entity_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
import java.lang
from java.util import ArrayList, HashSet, HashMap
from org.apache.hadoop.hbase.client import HTablePool
from meetup.beeno import EntityMetadata, EntityService, HBaseException, MappingException
from meetup.beeno import EntityService, HBaseException
from meetup.beeno import TestEntities
from meetup.beeno.mapping import EntityMetadata, MappingException
from meetup.beeno.util import HUtil
from dbtest.hbase import HBaseContext

Expand Down
3 changes: 2 additions & 1 deletion test/jython/dbtest/hbase/test_entity_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@

from jyunit.util import *

from meetup.beeno import EntityMetadata, HBaseException, MappingException
from meetup.beeno import HBaseException
from meetup.beeno import TestEntities
from meetup.beeno.mapping import EntityMetadata, MappingException

import java.lang

Expand Down
3 changes: 2 additions & 1 deletion test/jython/dbtest/hbase/test_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@

import db.hbase
from org.apache.hadoop.hbase.client import HTablePool
from meetup.beeno import EntityMetadata, EntityService, Query, Criteria, HBaseException
from meetup.beeno import EntityService, Query, Criteria, HBaseException
from meetup.beeno.util import HUtil
from meetup.beeno import TestEntities
from meetup.beeno.mapping import EntityMetadata
from dbtest.hbase import HBaseContext

hc = HBaseContext()
Expand Down

0 comments on commit 510079b

Please sign in to comment.