use of org.apache.gora.filter.MapFieldValueFilter in project gora by apache.
the class DefaultFactoryTest method createHeadersFilter.
private MapFieldValueFilter<String, WebPage> createHeadersFilter() {
MapFieldValueFilter<String, WebPage> filter = new MapFieldValueFilter<>();
filter.setFieldName(WebPage.Field.HEADERS.toString());
filter.setMapKey(new Utf8("C.T"));
filter.getOperands().add("text/html");
return filter;
}
use of org.apache.gora.filter.MapFieldValueFilter in project gora by apache.
the class DefaultFactory method createFilter.
@Override
public org.apache.hadoop.hbase.filter.Filter createFilter(Filter<K, T> filter, HBaseStore<K, T> store) {
if (filter instanceof FilterList) {
FilterList<K, T> filterList = (FilterList<K, T>) filter;
org.apache.hadoop.hbase.filter.FilterList hbaseFilter = new org.apache.hadoop.hbase.filter.FilterList(Operator.valueOf(filterList.getOperator().name()));
for (Filter<K, T> rowFitler : filterList.getFilters()) {
FilterFactory<K, T> factory = getHbaseFitlerUtil().getFactory(rowFitler);
if (factory == null) {
LOG.warn("HBase remote filter factory not yet implemented for " + rowFitler.getClass().getCanonicalName());
return null;
}
org.apache.hadoop.hbase.filter.Filter hbaseRowFilter = factory.createFilter(rowFitler, store);
if (hbaseRowFilter != null) {
hbaseFilter.addFilter(hbaseRowFilter);
}
}
return hbaseFilter;
} else if (filter instanceof SingleFieldValueFilter) {
SingleFieldValueFilter<K, T> fieldFilter = (SingleFieldValueFilter<K, T>) filter;
HBaseColumn column = store.getMapping().getColumn(fieldFilter.getFieldName());
CompareOperator compareOp = getCompareOp(fieldFilter.getFilterOp());
byte[] family = column.getFamily();
byte[] qualifier = column.getQualifier();
byte[] value = HBaseByteInterface.toBytes(fieldFilter.getOperands().get(0));
SingleColumnValueFilter hbaseFilter = new SingleColumnValueFilter(family, qualifier, compareOp, value);
hbaseFilter.setFilterIfMissing(fieldFilter.isFilterIfMissing());
return hbaseFilter;
} else if (filter instanceof MapFieldValueFilter) {
MapFieldValueFilter<K, T> mapFilter = (MapFieldValueFilter<K, T>) filter;
HBaseColumn column = store.getMapping().getColumn(mapFilter.getFieldName());
CompareOperator compareOp = getCompareOp(mapFilter.getFilterOp());
byte[] family = column.getFamily();
byte[] qualifier = HBaseByteInterface.toBytes(mapFilter.getMapKey());
byte[] value = HBaseByteInterface.toBytes(mapFilter.getOperands().get(0));
SingleColumnValueFilter hbaseFilter = new SingleColumnValueFilter(family, qualifier, compareOp, value);
hbaseFilter.setFilterIfMissing(mapFilter.isFilterIfMissing());
return hbaseFilter;
} else {
LOG.warn("HBase remote filter not yet implemented for " + filter.getClass().getCanonicalName());
return null;
}
}
use of org.apache.gora.filter.MapFieldValueFilter in project gora by apache.
the class InfinispanQuery method build.
public void build() {
LOG.debug("build()");
FilterConditionContext context = null;
if (q != null) {
LOG.trace("Query already built; ignoring.");
return;
}
QueryBuilder qb = ((InfinispanStore<K, T>) dataStore).getClient().getQueryBuilder();
if (filter instanceof MapFieldValueFilter) {
MapFieldValueFilter mfilter = (MapFieldValueFilter) filter;
if (!(mfilter.getMapKey() instanceof Utf8))
throw new IllegalAccessError("Invalid map key, must be a string.");
if (mfilter.getOperands().size() > 1)
throw new IllegalAccessError("MapFieldValueFilter operand not supported.");
if (!(mfilter.getOperands().get(0) instanceof String))
throw new IllegalAccessError("Invalid operand, must be a string.");
String value = mfilter.getMapKey() + Support.DELIMITER + mfilter.getOperands().get(0).toString();
switch(mfilter.getFilterOp()) {
case EQUALS:
if (value.equals("*")) {
context = qb.having(mfilter.getFieldName()).like(value);
} else {
context = qb.having(mfilter.getFieldName()).eq(value);
}
if (!((MapFieldValueFilter) filter).isFilterIfMissing()) {
LOG.warn("Forcing isFilterMissing to true");
((MapFieldValueFilter) filter).setFilterIfMissing(true);
}
break;
case NOT_EQUALS:
if (value.equals("*")) {
context = qb.not().having(mfilter.getFieldName()).like(value);
} else {
context = qb.not().having(mfilter.getFieldName()).eq(value);
}
if (!((MapFieldValueFilter) filter).isFilterIfMissing()) {
LOG.warn("Forcing isFilterMissing to false");
((MapFieldValueFilter) filter).setFilterIfMissing(false);
}
break;
default:
throw new IllegalAccessError("FilterOp not supported..");
}
} else if (filter instanceof SingleFieldValueFilter) {
SingleFieldValueFilter sfilter = (SingleFieldValueFilter) filter;
if (sfilter.getOperands().size() > 1)
throw new IllegalAccessError("SingleFieldValueFilter operand not supported.");
Object value = sfilter.getOperands().get(0);
switch(sfilter.getFilterOp()) {
case EQUALS:
if (value.equals("*")) {
context = qb.having(sfilter.getFieldName()).like((String) value);
} else {
context = qb.having(sfilter.getFieldName()).eq(value);
}
break;
case NOT_EQUALS:
if (value.equals("*")) {
context = qb.not().having(sfilter.getFieldName()).like((String) value);
} else {
context = qb.not().having(sfilter.getFieldName()).eq(value);
}
break;
case LESS:
context = qb.having(sfilter.getFieldName()).lt(value);
break;
case LESS_OR_EQUAL:
context = qb.having(sfilter.getFieldName()).lte(value);
break;
case GREATER:
context = qb.having(sfilter.getFieldName()).gt(value);
break;
case GREATER_OR_EQUAL:
context = qb.having(sfilter.getFieldName()).gte(value);
break;
default:
throw new IllegalAccessError("FilterOp not supported..");
}
} else if (filter != null) {
throw new IllegalAccessError("Filter not supported.");
}
if (this.startKey == this.endKey && this.startKey != null) {
(context == null ? qb : context.and()).having(getPrimaryFieldName()).eq(this.startKey);
} else {
if (this.startKey != null && this.endKey != null)
context = (context == null ? qb : context.and()).having(getPrimaryFieldName()).between(this.startKey, this.endKey);
else if (this.startKey != null)
context = (context == null ? qb : context.and()).having(getPrimaryFieldName()).between(this.startKey, null);
else if (this.endKey != null)
(context == null ? qb : context.and()).having(getPrimaryFieldName()).between(null, this.endKey);
}
// if projection enabled, keep the primary field.
if (fields != null && fields.length > 0) {
String[] fieldsWithPrimary;
List<String> fieldsList = new ArrayList<>(Arrays.asList(fields));
if (!fieldsList.contains(getPrimaryFieldName())) {
fieldsWithPrimary = Arrays.copyOf(fields, fields.length + 1);
fieldsWithPrimary[fields.length] = getPrimaryFieldName();
} else {
fieldsWithPrimary = fieldsList.toArray(new String[] {});
}
qb.setProjection(fieldsWithPrimary);
}
qb.orderBy((getSortingField().equals("")) ? getPrimaryFieldName() : getSortingField(), isAscendant ? SortOrder.ASC : SortOrder.DESC);
if (this.getOffset() >= 0)
qb.startOffset(this.getOffset());
if (this.getLimit() > 0)
qb.maxResults((int) this.getLimit());
q = (RemoteQuery) qb.build();
if (location != null)
q.setLocation(location);
}
Aggregations