Package org.kiji.schema.layout.KijiTableLayout.LocalityGroupLayout

Examples of org.kiji.schema.layout.KijiTableLayout.LocalityGroupLayout.FamilyLayout


  @Test
  public void testAddColumn() throws Exception {
    final KijiTableLayout layout1 = KijiTableLayout.newLayout(getLayoutV1Desc());
    {
      final FamilyLayout fLayout1 = layout1.getFamilyMap().get("family_name");
      assertEquals(1, fLayout1.getId().getId());
      final ColumnLayout c1Layout1 = fLayout1.getColumnMap().get("column_name");
      assertEquals(1, c1Layout1.getId().getId());
    }

    final KijiTableLayout layout2 = KijiTableLayout.createUpdatedLayout(getLayoutV2Desc(), layout1);
    {
      final FamilyLayout fLayout2 = layout2.getFamilyMap().get("family_name");
      assertEquals(1, fLayout2.getId().getId());
      final ColumnLayout c1Layout2 = fLayout2.getColumnMap().get("column_name");
      assertEquals(1, c1Layout2.getId().getId());
      final ColumnLayout c2Layout2 = fLayout2.getColumnMap().get("second_column_name");
      assertEquals(2, c2Layout2.getId().getId());
    }

    final KijiTableLayout layout3 = KijiTableLayout.createUpdatedLayout(getLayoutV3Desc(), layout2);
    {
      final FamilyLayout fLayout3 = layout3.getFamilyMap().get("family_name");
      assertEquals(1, fLayout3.getId().getId());
      assertEquals(1, fLayout3.getColumnMap().size());
      final ColumnLayout c2Layout3 = fLayout3.getColumnMap().get("second_column_name");
      assertEquals(2, c2Layout3.getId().getId());
    }

    final KijiTableLayout layout4 = KijiTableLayout.createUpdatedLayout(getLayoutV4Desc(), layout3);
    {
      final FamilyLayout fLayout4 = layout4.getFamilyMap().get("family_name");
      assertEquals(1, fLayout4.getId().getId());
      assertEquals(2, fLayout4.getColumnMap().size());
      final ColumnLayout c2Layout4 = fLayout4.getColumnMap().get("second_column_name");
      assertEquals(2, c2Layout4.getId().getId());
      final ColumnLayout c3Layout4 = fLayout4.getColumnMap().get("third_column_name");
      assertEquals(1, c3Layout4.getId().getId());
    }
  }
View Full Code Here


      final KijiCellDecoder<T> decoder = decoderProvider.getDecoder(column);

      return new QualifiedColumnDecoder<T>(column, decoder);
    }

    final FamilyLayout family = layout.getFamilyMap().get(column.getFamily());

    if (family.isMapType()) {
      return new MapFamilyDecoder<T>(translator, decoderProvider.<T>getDecoder(column));
    } else {
      return new GroupFamilyDecoder<T>(translator, decoderProvider);
    }
  }
View Full Code Here

    mRefLayout = KijiTableLayout.newLayout(mRefLayoutDesc);
  }

  @Test
  public void testReference() throws Exception {
    final FamilyLayout fLayout = mRefLayout.getFamilyMap().get("family_name");
    assertEquals(1, fLayout.getId().getId());
    final ColumnLayout cLayout = fLayout.getColumnMap().get("column_name");
    assertEquals(1, cLayout.getId().getId());
  }
View Full Code Here

                            .build()))
                    .build()))
            .build()))
        .build();
    final KijiTableLayout layout2 = KijiTableLayout.createUpdatedLayout(desc2, mRefLayout);
    final FamilyLayout fLayout2 = layout2.getFamilyMap().get("family_name");
    assertEquals(1, fLayout2.getColumnMap().size());
    assertNull(fLayout2.getColumnMap().get("column_name"));
    assertNotNull(fLayout2.getColumnMap().get("renamed_column_name"));
    assertEquals(1, fLayout2.getColumnMap().get("renamed_column_name").getId().getId());
  }
View Full Code Here

            .build()))
        .build();
    final KijiTableLayout layout2 = KijiTableLayout.createUpdatedLayout(desc2, mRefLayout);
    assertEquals(1, layout2.getFamilies().size());
    assertNull(layout2.getFamilyMap().get("family_name"));
    final FamilyLayout fLayout2 = layout2.getFamilyMap().get("renamed_family_name");
    assertEquals(1, fLayout2.getColumns().size());
    assertEquals(1, fLayout2.getColumnMap().size());
    final ColumnLayout cLayout2 = fLayout2.getColumnMap().get("column_name");
    assertNotNull(cLayout2);
  }
View Full Code Here

  /** {@inheritDoc} */
  @Override
  public void deleteFamily(EntityId entityId, String family, long upToTimestamp)
      throws IOException {
    final HBaseKijiTableWriter.WriterLayoutCapsule capsule = mWriterLayoutCapsule;
    final FamilyLayout familyLayout = capsule.getLayout().getFamilyMap().get(family);
    if (null == familyLayout) {
      throw new NoSuchColumnException(String.format("Family '%s' not found.", family));
    }

    if (familyLayout.getLocalityGroup().getFamilyMap().size() > 1) {
      // There are multiple families within the locality group, so we need to be clever.
      if (familyLayout.isGroupType()) {
        deleteGroupFamily(entityId, familyLayout, upToTimestamp);
      } else if (familyLayout.isMapType()) {
        deleteMapFamily(entityId, familyLayout, upToTimestamp);
      } else {
        throw new RuntimeException("Internal error: family is neither map-type nor group-type.");
      }
      return;
View Full Code Here

  }

  /** {@inheritDoc} */
  @Override
  public <T> Iterator<KijiCell<T>> iterator(final String family) {
    final FamilyLayout familyLayout = mLayout.getFamilyMap().get(family);
    Preconditions.checkArgument(familyLayout != null, "Column %s has no data request.", family);
    Preconditions.checkState(familyLayout.isMapType(),
        "iterator(String family) is only enabled on map type column families."
            + " The column family [%s], is a group type column family."
            + " Please use the iterator(String family, String qualifier) method.", family);

    return iterator(family, null);
View Full Code Here

   * @param columnName Column to reports the raw specification record of.
   * @return the raw specification record for the specified column.
   * @throws NoSuchColumnException if the column does not exist.
   */
  public CellSchema getCellSchema(KijiColumnName columnName) throws NoSuchColumnException {
    final FamilyLayout fLayout = mFamilyMap.get(columnName.getFamily());
    if (fLayout == null) {
      throw new NoSuchColumnException(String.format(
          "Table '%s' has no family '%s'.", getName(), columnName.getFamily()));
    }
    if (fLayout.isMapType()) {
      return CellSchema.newBuilder(fLayout.getDesc().getMapSchema()).build();
    }

    // Group-type family:
    Preconditions.checkArgument(columnName.isFullyQualified(),
        String.format("Cannot get CellFormat for entire group-type family: '%s'.", columnName));
    final FamilyLayout.ColumnLayout cLayout =
        fLayout.getColumnMap().get(columnName.getQualifier());
    if (cLayout == null) {
      throw new NoSuchColumnException(String.format(
          "Table '%s' has no column '%s'.", getName(), columnName));
    }
    return CellSchema.newBuilder(cLayout.getDesc().getColumnSchema()).build();
View Full Code Here

   *
   * @param column Column name.
   * @return whether the specified column exists.
   */
  public boolean exists(KijiColumnName column) {
    final FamilyLayout fLayout = mFamilyMap.get(column.getFamily());
    if (fLayout == null) {
      // Family does not exist:
      return false;
    }

    if (fLayout.isMapType()) {
      // This is a map-type family, we don't need to validate the qualifier:
      return true;
    }

    // This is a group-type family:
    if (!column.isFullyQualified()) {
      // No column qualifier, the group-type family exists:
      return true;
    }

    // Validate the qualifier:
    return fLayout.getColumnMap().containsKey(column.getQualifier());
  }
View Full Code Here

        if (isRename && (reference == null)) {
          throw new InvalidLayoutException(String.format(
              "Invalid rename: no reference locality group '%s' for family '%s'.",
              getName(), refFName));
        }
        final FamilyLayout refFLayout =
            (reference != null) ? reference.getFamilyMap().get(refFName) : null;
        if (isRename && (refFLayout == null)) {
          throw new InvalidLayoutException(String.format(
              "Invalid rename: cannot find reference family '%s' in locality group '%s'.",
              refFName, getName()));
        }

        final ColumnId refFId = refFIdMap.remove(refFName);

        if (familyDesc.getDelete()) {
          if (refFId == null) {
            throw new InvalidLayoutException(String.format(
                "Deleted family '%s' unknown in reference locality group '%s'.",
                refFName, getName()));
          }
          itFamilyDesc.remove();
          continue;
        }

        final FamilyLayout fLayout = new FamilyLayout(familyDesc, refFLayout);
        families.add(fLayout);
        for (String familyName : fLayout.getNames()) {
          Preconditions.checkState(familyMap.put(familyName, fLayout) == null,
              "Duplicate family name: " + familyName);
        }
        if (fLayout.getId() != null) {
          final String previous = idMap.put(fLayout.getId(), fLayout.getName());
          Preconditions.checkState(previous == null,
              String.format("Duplicate family ID '%s' associated to '%s' and '%s'.",
                  fLayout.getId(), fLayout.getName(), previous));
        } else {
          unassigned.add(fLayout);
        }
      }

      if (!refFIdMap.isEmpty()) {
        throw new InvalidLayoutException(String.format(
            "Descriptor for locality group '%s' is missing families: %s",
            lgDesc.getName(), Joiner.on(",").join(refFIdMap.keySet())));
      }

      mFamilies = ImmutableList.copyOf(families);
      mFamilyMap = ImmutableMap.copyOf(familyMap);

      // Assign IDs to families:
      int nextFamilyId = 1;
      for (FamilyLayout fLayout : unassigned) {
        Preconditions.checkState(fLayout.getId() == null);
        while (true) {
          final ColumnId fId = new ColumnId(nextFamilyId);
          nextFamilyId += 1;
          if (!idMap.containsKey(fId)) {
            fLayout.setId(fId);
            idMap.put(fId, fLayout.getName());
            break;
          }
        }
      }
View Full Code Here

TOP

Related Classes of org.kiji.schema.layout.KijiTableLayout.LocalityGroupLayout.FamilyLayout

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.