Exemplo n.º 1
0
 private Cell6<Integer, String, Integer, Integer, Integer, Float> getSearchTable() {
   Cell6<Integer, String, Integer, Integer, Integer, Float> searchTable =
       new Cell6<Integer, String, Integer, Integer, Integer, Float>(
           SortedBytesInteger.getInstance(),
           SortedBytesString.getInstance(),
           SortedBytesUnsignedShort.getInstance(),
           SortedBytesUnsignedShort.getInstance(),
           SortedBytesInteger.getInstance(),
           SortedBytesFloat.getInstance());
   return searchTable;
 }
Exemplo n.º 2
0
  public byte[] cookBytes(
      StringBuilder key, Iterable<Text> values, byte[] existingData, Field fld, char dataTypeChar)
      throws IOException {

    byte[] finalData = null;
    String fieldName = null;
    boolean compressed = false;
    boolean repeatable = false;
    boolean analyzed = false;

    if (null != fld) {
      fieldName = fld.name;
      compressed = fld.isCompressed;
      repeatable = fld.isRepeatable;
      analyzed = fld.isAnalyzed;
    }

    switch (dataTypeChar) {
      case 't':
        finalData = IndexFieldString.cook(values, existingData, repeatable, compressed);
        break;

      case 'e':

        /** Skip multi phrases which are only sighted once. */
        int keyLen = key.length();
        boolean skipSingle = false;
        if (keyLen > 1) {
          skipSingle = (key.charAt(keyLen - 1) == '*');
          if (skipSingle) key = key.delete(keyLen - 2, keyLen);
        }

        finalData =
            (repeatable)
                ? indexTextBitset(skipSingle, existingData, values, analyzed, fieldName, compressed)
                : indexTextSet(skipSingle, existingData, values, analyzed, fieldName);
        break;

      case 'i':
        finalData = IndexFieldInteger.cook(values, existingData, repeatable, compressed);
        break;

      case 'f':
        finalData = IndexFieldFloat.cook(values, existingData, repeatable, compressed);
        break;

      case 'd':
        finalData = IndexFieldDouble.cook(values, existingData, repeatable, compressed);
        break;

      case 'l':
        finalData = IndexFieldLong.cook(values, existingData, repeatable, compressed);
        break;

      case 's':
        finalData = IndexFieldShort.cook(values, existingData, repeatable, compressed);
        break;

      case 'b':
        finalData = IndexFieldBoolean.cook(values, existingData, repeatable, compressed);
        break;

      case 'c':
        finalData = IndexFieldByte.cook(values, existingData, repeatable, compressed);
        break;

      default:
        {
          List<String> mergeKeys = new ArrayList<String>();
          for (Text mergeKey : values) {
            mergeKeys.add(mergeKey.toString());
          }
          finalData = SortedBytesString.getInstance().toBytes(mergeKeys);
          break;
        }
    }
    return finalData;
  }
Exemplo n.º 3
0
  public void testAddOnEmptySet() throws Exception {

    Cell3<String, Integer, Long> tc =
        new Cell3<String, Integer, Long>(
            SortedBytesString.getInstance(),
            SortedBytesInteger.getInstance(),
            SortedBytesLong.getInstance());

    tc.put("entry100", 0, 1111L);
    tc.put("entry100", 0, 1111L);
    tc.put("entry100", 0, 2222L);
    tc.put("entry100", 0, 3333L);
    tc.put("entry100", 0, 4444L);
    tc.put("entry100", 0, 5555L);
    tc.put("entry100", 1, 4444L);
    tc.put("entry100", 1, 4444L);
    tc.put("entry100", 1, 4444L);

    tc.put("entry101", 2, 9999L);
    tc.sort(new CellComparator.LongComparator<Integer>());

    Set<String> uniqueKeys = tc.getMap().keySet();

    // Test Parsing
    Cell3<String, Integer, Long> tcNewParsing =
        new Cell3<String, Integer, Long>(
            SortedBytesString.getInstance(),
            SortedBytesInteger.getInstance(),
            SortedBytesLong.getInstance());

    tcNewParsing.parseElements(tc.toBytes());
    assertEquals(2, tcNewParsing.getMap().size());

    for (String key : tcNewParsing.getMap().keySet()) {
      assertTrue(uniqueKeys.contains(key));
    }

    Iterator<Cell2<Integer, Long>> valItr = tcNewParsing.getMap().values().iterator();
    Cell2<Integer, Long> value = valItr.next();
    Collection<Integer> allKeys = value.keySet();
    Collection<Long> allVals = value.values();

    assertEquals(9, allKeys.size());
    assertTrue("[0, 0, 0, 0, 1, 1, 1, 0, 0]".equals(allKeys.toString()));
    assertEquals("[1111, 1111, 2222, 3333, 4444, 4444, 4444, 4444, 5555]", allVals.toString());

    value = valItr.next();
    value.parseElements();
    allKeys = value.keySet();
    allVals = value.values();

    assertEquals(1, allKeys.size());
    assertTrue("[2]".equals(allKeys.toString()));
    assertEquals("[9999]", allVals.toString());

    // Find Matching
    Cell3<String, Integer, Long> tcNewFinding =
        new Cell3<String, Integer, Long>(
            SortedBytesString.getInstance(),
            SortedBytesInteger.getInstance(),
            SortedBytesLong.getInstance());
    tcNewFinding.data = tc.toBytes();

    Collection<Cell2<Integer, Long>> all = tcNewFinding.values("entry100");
    for (Cell2<Integer, Long> cell2 : all) {
      cell2.parseElements();
      StringBuilder sb = new StringBuilder();
      for (CellKeyValue<Integer, Long> kv : cell2.getMap()) {
        sb.append(kv.key.toString() + "-" + kv.value.toString() + "|");
      }
      assertEquals(
          "0-1111|0-1111|0-2222|0-3333|1-4444|1-4444|1-4444|0-4444|0-5555|", sb.toString());
    }
  }