HBaseScanConfigBuilder { @SuppressWarnings("unchecked") public <T> HBaseScanConfig<T> getScanConfig(Criteria<T> criteria) { Map<List<String>, IndexMapper<?>> indexMap = mappers.get(criteria.clazz()); HBaseScanConfig<T> hBaseScanConfig = null; if (indexMap != null) { hBaseScanConfig = new HBaseScanConfig<>(); IndexMapper<T> indexMapper = null; List<Criteria.Field> nonIndexedFields = new ArrayList<>(); List<Criteria.Field> indexedFields = new ArrayList<>(); List<Criteria.Field> fieldRestrictions = criteria.fieldRestrictions(); if (!fieldRestrictions.isEmpty()) { Map<String, Criteria.Field> queryFieldMap = new HashMap<>(); for (Criteria.Field field : fieldRestrictions) { queryFieldMap.put(field.getName(), field); } Map.Entry<List<String>, IndexMapper<?>> bestEntry = bestMatch(indexMap, queryFieldMap.keySet()); if (bestEntry != null) { LOG.debug("Found bestEntry {} for fieldRestrictions {}", bestEntry, fieldRestrictions); indexMapper = (IndexMapper<T>) bestEntry.getValue(); hBaseScanConfig.setMapper(indexMapper); for (String indexedFieldName : bestEntry.getKey()) { Criteria.Field field; if ((field = queryFieldMap.remove(indexedFieldName)) != null) { indexedFields.add(field); } else { break; } } hBaseScanConfig.setIndexedFieldValue(fieldsValue(indexedFields)); nonIndexedFields.addAll(queryFieldMap.values()); } } if (indexMapper == null) { if ((indexMapper = (IndexMapper<T>) indexMap.get(DEFAULT_INDEX_FIELD_NAMES)) == null) { return null; } hBaseScanConfig.setMapper(indexMapper); nonIndexedFields.addAll(fieldRestrictions); } LOG.debug("nonIndexedFields {}", nonIndexedFields); for (Criteria.Field field : nonIndexedFields) { List<byte[]> CfCqCv = indexMapper.mapMemberValue(field.getName(), field.getValue()); if (CfCqCv != null) { SingleColumnValueFilter filter = new SingleColumnValueFilter(CfCqCv.get(0), CfCqCv.get(1), CompareFilter.CompareOp.EQUAL, CfCqCv.get(2)); filter.setFilterIfMissing(true); hBaseScanConfig.addFilter(filter); } else { return null; } } hBaseScanConfig.setStartTs(criteria.startTs()); hBaseScanConfig.setEndTs(criteria.endTs()); hBaseScanConfig.setNumRows(criteria.numRows()); } return hBaseScanConfig; }  void addMappers(Class<T> clazz, List<? extends IndexMapper<T>> indexMappers); @SuppressWarnings("unchecked") HBaseScanConfig<T> getScanConfig(Criteria<T> criteria);  }
@Test public void testGetScanConfig() throws Exception { final List<Criteria.Field> fr = new ArrayList<>(); fr.add(new CriteriaImpl.FieldImpl("notifierName", "test_notifier")); fr.add(new CriteriaImpl.FieldImpl("status", "NEW")); final List<byte[]> nnList = Arrays.asList("s".getBytes(CHARSET), "qs".getBytes(CHARSET), "NEW".getBytes(CHARSET)); new Expectations() { { mockNotificationCriteria.clazz(); times = 1; result = Notification.class; mockNotificationCriteria.fieldRestrictions(); times = 1; result = fr; mockIndexMapper.getIndexedFieldNames(); times = 1; result = Arrays.asList("notifierName"); mockNotificationCriteria.numRows(); times = 1; result = 5; mockIndexMapper.mapMemberValue("status", "NEW"); times = 1; result = nnList; } }; hBaseScanConfigBuilder = new HBaseScanConfigBuilder(); hBaseScanConfigBuilder.addMappers(Notification.class, Arrays.asList(mockIndexMapper)); Criteria<Notification> eventCriteria = new CriteriaImpl<>(Notification.class); HBaseScanConfig<Notification> notificationScanConfig = hBaseScanConfigBuilder.getScanConfig(mockNotificationCriteria); System.out.println(notificationScanConfig); assertEquals(mockIndexMapper, notificationScanConfig.getMapper()); assertArrayEquals("test_notifier|0".getBytes(CHARSET), notificationScanConfig.getStartRow()); assertArrayEquals(("test_notifier|"+Long.MAX_VALUE).getBytes(CHARSET), notificationScanConfig.getStopRow()); assertEquals(2, notificationScanConfig.filterList().getFilters().size()); Filter firstFilter = notificationScanConfig.filterList().getFilters().get(0); assertEquals(SingleColumnValueFilter.class, firstFilter.getClass()); Filter secondFilter = notificationScanConfig.filterList().getFilters().get(1); assertEquals(PageFilter.class, secondFilter.getClass()); }