コード例 #1
0
 /** Create a filter that will match a given family, qualifier, and cells per qualifier. */
 private RowFilter createColumnSpecFilter(SingleColumnValueFilter filter) throws IOException {
   return RowFilter.newBuilder()
       .setChain(
           Chain.newBuilder()
               .addFilters(
                   RowFilter.newBuilder()
                       .setFamilyNameRegexFilter(
                           Bytes.toString(quoteRegularExpression(filter.getFamily()))))
               .addFilters(
                   RowFilter.newBuilder()
                       .setColumnQualifierRegexFilter(
                           ByteStringer.wrap(quoteRegularExpression(filter.getQualifier()))))
               .addFilters(createVersionLimitFilter(filter)))
       .build();
 }
コード例 #2
0
 private void handleScvf(SingleColumnValueFilter scvf) {
   ValuePartition vp = null;
   if (scvf instanceof SingleColumnValuePartitionFilter) {
     vp = ((SingleColumnValuePartitionFilter) scvf).getValuePartition();
   }
   Column column = new Column(scvf.getFamily(), scvf.getQualifier(), vp);
   Pair<Value, Value> pair = colWithOperators.get(column);
   if (pair == null) {
     pair = new Pair<Value, Value>();
     // The first operator should be set here
     pair.setFirst(new Value(scvf.getOperator(), scvf.getComparator().getValue(), scvf));
     colWithOperators.put(column, pair);
   } else {
     if (pair.getFirst() != null && pair.getSecond() == null) {
       // TODO As Anoop said we may have to check the Value type also..
       // We can not compare and validate this way. btw "a" and "K".
       // Only in case of Numeric col type we can have this check.
       byte[] curBoundValue = scvf.getComparator().getValue();
       byte[] prevBoundValue = pair.getFirst().getValue();
       int result = Bytes.compareTo(prevBoundValue, curBoundValue);
       CompareOp curBoundOperator = scvf.getOperator();
       CompareOp prevBoundOperator = pair.getFirst().getOperator();
       switch (curBoundOperator) {
         case GREATER:
         case GREATER_OR_EQUAL:
           if (prevBoundOperator == CompareOp.GREATER
               || prevBoundOperator == CompareOp.GREATER_OR_EQUAL) {
             LOG.warn("Wrong usage.  It should be < > || > <.  Cannot be > >");
             if (result > 1) {
               pair.setFirst(new Value(curBoundOperator, curBoundValue, scvf));
             }
             pair.setSecond(null);
           } else if (prevBoundOperator == CompareOp.LESS
               || prevBoundOperator == CompareOp.LESS_OR_EQUAL) {
             if (result < 1) {
               LOG.warn("Possible wrong usage as there cannot be a value < 10 and  > 20");
               pair.setFirst(null);
               pair.setSecond(null);
             } else {
               pair.setSecond(new Value(curBoundOperator, curBoundValue, scvf));
             }
           } else if (prevBoundOperator == CompareOp.EQUAL) {
             LOG.warn("Use the equal operator and ignore the current one");
             pair.setSecond(null);
           }
           break;
         case LESS:
         case LESS_OR_EQUAL:
           if (prevBoundOperator == CompareOp.LESS
               || prevBoundOperator == CompareOp.LESS_OR_EQUAL) {
             LOG.warn("Wrong usage.  It should be < > || > <.  Cannot be > >");
             if (result < 1) {
               pair.setFirst(new Value(curBoundOperator, curBoundValue, scvf));
             }
             pair.setSecond(null);
           } else if (prevBoundOperator == CompareOp.GREATER
               || prevBoundOperator == CompareOp.GREATER_OR_EQUAL) {
             if (result > 1) {
               LOG.warn("Possible wrong usage as there cannot be a value < 10 and  > 20");
               pair.setFirst(null);
               pair.setSecond(null);
             } else {
               pair.setSecond(new Value(curBoundOperator, curBoundValue, scvf));
             }
           } else if (prevBoundOperator == CompareOp.EQUAL) {
             LOG.warn("Use the EQUAL operator only  and ignore the current one.");
             pair.setSecond(null);
           }
           break;
         case EQUAL:
           // For equal condition give priority to equals only..
           // If the prevOperator is also == and the current is also ==
           // take the second one.(Currently)
           if (prevBoundOperator == CompareOp.LESS
               || prevBoundOperator == CompareOp.LESS_OR_EQUAL
               || prevBoundOperator == CompareOp.EQUAL
               || prevBoundOperator == CompareOp.GREATER
               || prevBoundOperator == CompareOp.GREATER_OR_EQUAL) {
             pair.setFirst(new Value(curBoundOperator, curBoundValue, scvf));
             pair.setSecond(null);
           }
           break;
         case NOT_EQUAL:
         case NO_OP:
           // Need to check this
           break;
       }
     } else {
       LOG.warn(
           "Am getting an extra comparison coming for the same col family."
               + "I cannot have 3 conditions on the same column");
       pair.setFirst(null);
       pair.setSecond(null);
     }
   }
 }
コード例 #3
0
 private void handleScvfOfOR(SingleColumnValueFilter scvf) {
   ValuePartition vp = null;
   if (scvf instanceof SingleColumnValuePartitionFilter) {
     vp = ((SingleColumnValuePartitionFilter) scvf).getValuePartition();
   }
   Column key = new Column(scvf.getFamily(), scvf.getQualifier(), vp);
   if (colWithOperatorsOfOR.get(key) == null) {
     List<Value> valueList = new ArrayList<FilterGroupingWorker.Value>(1);
     valueList.add(new Value(scvf.getOperator(), scvf.getComparator().getValue(), scvf));
     colWithOperatorsOfOR.put(key, valueList);
   } else {
     List<Value> valueList = colWithOperatorsOfOR.get(key);
     Iterator<Value> valueListItr = valueList.iterator();
     CompareOp operator = scvf.getOperator();
     byte[] value = scvf.getComparator().getValue();
     Value prevValueObj = null;
     while (valueListItr.hasNext()) {
       prevValueObj = valueListItr.next();
       // TODO As Anoop said we may have to check the Value type also..
       // We can not compare and validate this way. btw "a" and "K".
       // Only in case of Numeric col type we can have this check.
       byte[] prevValue = prevValueObj.getValue();
       int result = Bytes.compareTo(prevValue, value);
       CompareOp prevOperator = prevValueObj.getOperator();
       switch (operator) {
         case GREATER:
           if (prevOperator == CompareOp.GREATER || prevOperator == CompareOp.GREATER_OR_EQUAL) {
             if (result > 0) {
               valueListItr.remove();
             } else {
               // Already you found less or equal value than present value means present filter
               // will
               // return subset of previous filter. No need to add it to list.
               return;
             }
           } else if (prevOperator == CompareOp.LESS || prevOperator == CompareOp.LESS_OR_EQUAL) {
             // Need to handle conditions like previous is c1<5 and current c1>2. In these cases we
             // can change this condition into three parts c1<2,c1>=2 AND C1=<5 ,c1>5 and add to
             // list.
           } else if (prevOperator == CompareOp.EQUAL) {
             if (result > 0) {
               valueListItr.remove();
             } else if (result == 0) {
               // remove this entry and convert GREATER to GREATER_OR_EQUAL
               valueListItr.remove();
               SingleColumnValueFilter newScvf = null;
               if (vp == null) {
                 newScvf =
                     new SingleColumnValueFilter(
                         scvf.getFamily(),
                         scvf.getQualifier(),
                         CompareOp.GREATER_OR_EQUAL,
                         scvf.getComparator());
               } else {
                 newScvf =
                     new SingleColumnValuePartitionFilter(
                         scvf.getFamily(),
                         scvf.getQualifier(),
                         CompareOp.GREATER_OR_EQUAL,
                         scvf.getComparator(),
                         vp);
               }
               Value newValue = new Value(CompareOp.GREATER_OR_EQUAL, prevValue, newScvf);
               valueList.add(newValue);
               return;
             }
           }
           break;
         case GREATER_OR_EQUAL:
           if (prevOperator == CompareOp.GREATER || prevOperator == CompareOp.GREATER_OR_EQUAL) {
             if (result >= 0) {
               valueListItr.remove();
             } else {
               // Already you found less value than present value means present filter will
               // return subset of previous filter. No need to add it to list.
               return;
             }
           } else if (prevOperator == CompareOp.LESS || prevOperator == CompareOp.LESS_OR_EQUAL) {
             // Need to handle conditions like previous is c1<5 and current c1>2. In these cases we
             // can change this condition into three parts c1<2,c1>=2 AND C1=<5 ,c1>5 and add to
             // list.
           } else if (prevOperator == CompareOp.EQUAL) {
             if (result >= 0) {
               valueListItr.remove();
             }
           }
           break;
         case LESS:
           if (prevOperator == CompareOp.LESS || prevOperator == CompareOp.LESS_OR_EQUAL) {
             if (result < 0) {
               valueListItr.remove();
             } else {
               // Already you found less or equal value than present value means present filter
               // will
               // return subset of previous filter. No need to add it to list.
               return;
             }
           } else if (prevOperator == CompareOp.GREATER
               || prevOperator == CompareOp.GREATER_OR_EQUAL) {
             // Need to handle conditions like previous is c1<5 and current c1>2. In these cases we
             // can change this condition into three parts c1<2,c1>=2 AND C1=<5 ,c1>5 and add to
             // list.
           } else if (prevOperator == CompareOp.EQUAL) {
             if (result < 0) {
               valueListItr.remove();
             } else if (result == 0) {
               // remove this entry and convert LESS to LESS_OR_EQUAL
               valueListItr.remove();
               SingleColumnValueFilter newScvf = null;
               if (vp == null) {
                 newScvf =
                     new SingleColumnValueFilter(
                         scvf.getFamily(),
                         scvf.getQualifier(),
                         CompareOp.LESS_OR_EQUAL,
                         scvf.getComparator());
               } else {
                 newScvf =
                     new SingleColumnValuePartitionFilter(
                         scvf.getFamily(),
                         scvf.getQualifier(),
                         CompareOp.LESS_OR_EQUAL,
                         scvf.getComparator(),
                         vp);
               }
               Value newValue = new Value(CompareOp.LESS_OR_EQUAL, prevValue, newScvf);
               valueList.add(newValue);
               return;
             }
           }
           break;
         case LESS_OR_EQUAL:
           if (prevOperator == CompareOp.LESS || prevOperator == CompareOp.LESS_OR_EQUAL) {
             if (result <= 0) {
               valueListItr.remove();
             } else {
               // Already you found less or equal value than present value means present filter
               // will
               // return subset of previous filter. No need to add it to list.
               return;
             }
           } else if (prevOperator == CompareOp.GREATER
               || prevOperator == CompareOp.GREATER_OR_EQUAL) {
             // Need to handle conditions like previous is c1<5 and current c1>2. In these cases we
             // can change this condition into three parts c1<2,c1>=2 AND C1=<5 ,c1>5 and add to
             // list.
           } else if (prevOperator == CompareOp.EQUAL) {
             // If we dont want to do conversion we can add into first if condition.
             if (result <= 0) {
               valueListItr.remove();
             } else if (result == 0) {
               // remove this entry and convert GREATER to GREATER_OR_EQUAL
             }
           }
           break;
         case EQUAL:
           if (prevOperator == CompareOp.GREATER) {
             if (result < 0) {
               return;
             } else if (result == 0) {
               valueListItr.remove();
               SingleColumnValueFilter newScvf = null;
               if (vp == null) {
                 newScvf =
                     new SingleColumnValueFilter(
                         scvf.getFamily(),
                         scvf.getQualifier(),
                         CompareOp.GREATER_OR_EQUAL,
                         scvf.getComparator());
               } else {
                 newScvf =
                     new SingleColumnValuePartitionFilter(
                         scvf.getFamily(),
                         scvf.getQualifier(),
                         CompareOp.GREATER_OR_EQUAL,
                         scvf.getComparator(),
                         vp);
               }
               Value newValue = new Value(CompareOp.GREATER_OR_EQUAL, prevValue, newScvf);
               valueList.add(newValue);
               return;
             }
           } else if (prevOperator == CompareOp.GREATER_OR_EQUAL) {
             if (result <= 0) {
               return;
             }
           } else if (prevOperator == CompareOp.LESS) {
             if (result > 0) {
               return;
             } else if (result == 0) {
               valueListItr.remove();
               SingleColumnValueFilter newScvf = null;
               if (vp == null) {
                 newScvf =
                     new SingleColumnValueFilter(
                         scvf.getFamily(),
                         scvf.getQualifier(),
                         CompareOp.LESS_OR_EQUAL,
                         scvf.getComparator());
               } else {
                 newScvf =
                     new SingleColumnValuePartitionFilter(
                         scvf.getFamily(),
                         scvf.getQualifier(),
                         CompareOp.LESS_OR_EQUAL,
                         scvf.getComparator(),
                         vp);
               }
               Value newValue = new Value(CompareOp.LESS_OR_EQUAL, prevValue, newScvf);
               valueList.add(newValue);
               return;
             }
           } else if (prevOperator == CompareOp.LESS_OR_EQUAL) {
             if (result >= 0) {
               return;
             }
           } else if (prevOperator == CompareOp.EQUAL) {
             if (result == 0) {
               // Already same filter exists with same condiftion.
               return;
             }
           }
           break;
         case NOT_EQUAL:
         case NO_OP:
           // Need to check this
           break;
       }
     }
     valueList.add(new Value(scvf.getOperator(), scvf.getComparator().getValue(), scvf));
   }
 }
コード例 #4
0
 public FilterModel(Filter filter) {
   String typeName = filter.getClass().getSimpleName();
   FilterType type = FilterType.valueOf(typeName);
   this.type = typeName;
   switch (type) {
     case ColumnCountGetFilter:
       this.limit = ((ColumnCountGetFilter) filter).getLimit();
       break;
     case ColumnPaginationFilter:
       this.limit = ((ColumnPaginationFilter) filter).getLimit();
       this.offset = ((ColumnPaginationFilter) filter).getOffset();
       break;
     case ColumnPrefixFilter:
       this.value = Base64.encodeBytes(((ColumnPrefixFilter) filter).getPrefix());
       break;
     case ColumnRangeFilter:
       this.minColumn = Base64.encodeBytes(((ColumnRangeFilter) filter).getMinColumn());
       this.minColumnInclusive = ((ColumnRangeFilter) filter).getMinColumnInclusive();
       this.maxColumn = Base64.encodeBytes(((ColumnRangeFilter) filter).getMaxColumn());
       this.maxColumnInclusive = ((ColumnRangeFilter) filter).getMaxColumnInclusive();
       break;
     case DependentColumnFilter:
       {
         DependentColumnFilter dcf = (DependentColumnFilter) filter;
         this.family = Base64.encodeBytes(dcf.getFamily());
         byte[] qualifier = dcf.getQualifier();
         if (qualifier != null) {
           this.qualifier = Base64.encodeBytes(qualifier);
         }
         this.op = dcf.getOperator().toString();
         this.comparator = new WritableByteArrayComparableModel(dcf.getComparator());
         this.dropDependentColumn = dcf.dropDependentColumn();
       }
       break;
     case FilterList:
       this.op = ((FilterList) filter).getOperator().toString();
       this.filters = new ArrayList<FilterModel>();
       for (Filter child : ((FilterList) filter).getFilters()) {
         this.filters.add(new FilterModel(child));
       }
       break;
     case FirstKeyOnlyFilter:
     case KeyOnlyFilter:
       break;
     case InclusiveStopFilter:
       this.value = Base64.encodeBytes(((InclusiveStopFilter) filter).getStopRowKey());
       break;
     case MultipleColumnPrefixFilter:
       this.prefixes = new ArrayList<String>();
       for (byte[] prefix : ((MultipleColumnPrefixFilter) filter).getPrefix()) {
         this.prefixes.add(Base64.encodeBytes(prefix));
       }
       break;
     case PageFilter:
       this.value = Long.toString(((PageFilter) filter).getPageSize());
       break;
     case PrefixFilter:
       this.value = Base64.encodeBytes(((PrefixFilter) filter).getPrefix());
       break;
     case FamilyFilter:
     case QualifierFilter:
     case RowFilter:
     case ValueFilter:
       this.op = ((CompareFilter) filter).getOperator().toString();
       this.comparator =
           new WritableByteArrayComparableModel(((CompareFilter) filter).getComparator());
       break;
     case RandomRowFilter:
       this.chance = ((RandomRowFilter) filter).getChance();
       break;
     case SingleColumnValueExcludeFilter:
     case SingleColumnValueFilter:
       {
         SingleColumnValueFilter scvf = (SingleColumnValueFilter) filter;
         this.family = Base64.encodeBytes(scvf.getFamily());
         byte[] qualifier = scvf.getQualifier();
         if (qualifier != null) {
           this.qualifier = Base64.encodeBytes(qualifier);
         }
         this.op = scvf.getOperator().toString();
         this.comparator = new WritableByteArrayComparableModel(scvf.getComparator());
         if (scvf.getFilterIfMissing()) {
           this.ifMissing = true;
         }
         if (scvf.getLatestVersionOnly()) {
           this.latestVersion = true;
         }
       }
       break;
     case SkipFilter:
       this.filters = new ArrayList<FilterModel>();
       this.filters.add(new FilterModel(((SkipFilter) filter).getFilter()));
       break;
     case TimestampsFilter:
       this.timestamps = ((TimestampsFilter) filter).getTimestamps();
       break;
     case WhileMatchFilter:
       this.filters = new ArrayList<FilterModel>();
       this.filters.add(new FilterModel(((WhileMatchFilter) filter).getFilter()));
       break;
     default:
       throw new RuntimeException("unhandled filter type " + type);
   }
 }