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

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


      if (flayout.isMapType()) {
        // If the family is map-type, get the CellSchema for all values in the family.
        final CellSchema cellSchema = flayout.getDesc().getMapSchema();

        FamilyLayout refFamilyLayout = null;
        if (refLGLayout != null) {
          // If there is a matching reference LG, check for the existence of this family.
          final String refFamilyName = refLGLayout.getFamilyIdNameMap().get(familyId);
          if (refFamilyName != null) {
            refFamilyLayout = refLGLayout.getFamilyMap().get(refFamilyName);
          }
        }

        if (refFamilyLayout != null) {
          if (refFamilyLayout.isMapType()) {
            // If the FamilyLayout from both table layouts are map type, compare their CellSchemas.
            final CellSchema refCellSchema = refFamilyLayout.getDesc().getMapSchema();

            incompatabilityMessages.addAll(addColumnNamestoIncompatibilityMessages(
                flayout.getName(), null, validateCellSchema(refCellSchema, cellSchema)));
          } else if (refFamilyLayout.isGroupType()) {
            // If the FamilyLayout changed from group-type to map-type between table layout versions
            // that is an incompatible change.
            incompatabilityMessages.add(String.format(
                "Family: %s changed from group-type to map-type.", refFamilyLayout.getName()));
          } else {
            throw new InternalKijiError(String.format(
                "Family: %s is neither map-type nor group-type.", refFamilyLayout.getName()));
          }
        } else {
          // If the reference FamilyLayout is null this indicates a new family, which is inherently
          // compatible, but we still have to validate that the new readers and writers are
          // internally compatible.
          incompatabilityMessages.addAll(addColumnNamestoIncompatibilityMessages(
              flayout.getName(), null, validateCellSchema(null, cellSchema)));
        }
      } else if (flayout.isGroupType()) {
        // Check for a matching family from the reference layout.
        FamilyLayout refFamilyLayout = null;
        if (refLGLayout != null) {
          final String refFamilyName = refLGLayout.getFamilyIdNameMap().get(familyId);
          if (refFamilyName != null) {
            refFamilyLayout = refLGLayout.getFamilyMap().get(refFamilyName);
          }
        }

        if (refFamilyLayout != null) {
          if (refFamilyLayout.isGroupType()) {
            // If there is a matching reference family and it is the same family type, iterate
            // through the columns checking schema compatibility.  Only checks columns from the new
            // layout because removed columns are inherently valid.
            for (ColumnLayout columnLayout : flayout.getColumns()) {
              final CellSchema cellSchema = columnLayout.getDesc().getColumnSchema();

              final String refColumnName =
                  refFamilyLayout.getColumnIdNameMap().get(columnLayout.getId());
              ColumnLayout refColumnLayout = null;
              if (refColumnName != null) {
                // If there is a column from the reference layout with the same column ID, get its
                // layout.
                refColumnLayout = refFamilyLayout.getColumnMap().get(refColumnName);
              }
              // If there is a column from the reference layout with the same column ID, get its
              // CellSchema.
              final CellSchema refCellSchema =
                  (refColumnLayout == null) ? null : refColumnLayout.getDesc().getColumnSchema();

              // If there is no matching column, refCellSchema will be null and this will only test
              // that the new reader and writer schemas are internally compatible.
              incompatabilityMessages.addAll(addColumnNamestoIncompatibilityMessages(
                  flayout.getName(),
                  columnLayout.getName(),
                  validateCellSchema(refCellSchema, cellSchema)));
            }
          } else if (refFamilyLayout.isMapType()) {
            // If the FamilyLayout changed from map-type to group-type between table layout versions
            // that is an incompatible change.
            incompatabilityMessages.add(String.format(
                "Family: %s changed from map-type to group-type.", refFamilyLayout.getName()));
          } else {
            throw new InternalKijiError(String.format(
                "Family: %s is neither map-type nor group-type.", refFamilyLayout.getName()));
          }
        } else {
          // If the reference FamilyLayout is null this indicates a new family, which is inherently
          // compatible, but we still have to validate that the new readers and writers are
          // internally compatible.
View Full Code Here


          String.format("No locality group for Cassandra table %s in Kiji table %s.",
              localityGroupTable, mLayout.getName()));
    }

    final ColumnId familyID = ColumnId.fromByteArray(cassandraColumnName.getFamily());
    final FamilyLayout family =
        localityGroup.getFamilyMap().get(localityGroup.getFamilyIdNameMap().get(familyID));
    if (family == null) {
      throw new NoSuchColumnException(String.format(
          "No family with ID %s in locality group %s of table %s.",
          familyID.getId(), localityGroup.getName(), mLayout.getName()));
    }

    final KijiColumnName kijiColumnName;
    if (family.isGroupType()) {
      // Group type family.
      final ColumnId qualifierID = ColumnId.fromByteArray(cassandraColumnName.getQualifier());
      final ColumnLayout qualifier =
          family.getColumnMap().get(family.getColumnIdNameMap().get(qualifierID));
      if (qualifier == null) {
        throw new NoSuchColumnException(String.format(
            "No column with ID %s in family %s of table %s.",
            qualifierID.getId(), family.getName(), mLayout.getName()));
      }
      kijiColumnName = KijiColumnName.create(family.getName(), qualifier.getName());
    } else {
      // Map type family.
      assert(family.isMapType());
      kijiColumnName =
          KijiColumnName.create(
              family.getName(),
              Bytes.toString(cassandraColumnName.getQualifier()));
    }
    LOG.debug("Translated Kiji column {}.", kijiColumnName);
    return kijiColumnName;
  }
View Full Code Here

      final KijiColumnName kijiColumnName
  ) throws NoSuchColumnException {
    final String familyName = kijiColumnName.getFamily();
    final String qualifierName = kijiColumnName.getQualifier();

    final FamilyLayout family = mLayout.getFamilyMap().get(familyName);
    if (family == null) {
      throw new NoSuchColumnException(kijiColumnName.toString());
    }

    final ColumnId familyID = family.getId();

    final byte[] familyBytes = familyID.toByteArray();

    if (qualifierName == null) {
      // Unqualified column
      return new CassandraColumnName(familyBytes, null);
    } else if (family.isGroupType()) {
      // Group type family.
      final ColumnId qualifierID = family.getColumnIdNameMap().inverse().get(qualifierName);
      final byte[] qualifierBytes = qualifierID.toByteArray();
      return new CassandraColumnName(familyBytes, qualifierBytes);
    } else {
      // Map type family.
      assert family.isMapType();
      final byte[] qualifierBytes = Bytes.toBytes(qualifierName);
      return new CassandraColumnName(familyBytes, qualifierBytes);
    }
  }
View Full Code Here

    synchronized (mMonitor) {
      Preconditions.checkState(mState == State.OPEN,
          "Cannot write to BufferedWriter instance in state %s.", mState);
      final KijiURI tableURI = mTable.getURI();

      final FamilyLayout familyLayout = mCapsule.getLayout().getFamilyMap().get(family);
      if (familyLayout == null) {
        throw new IllegalArgumentException(
            String.format("Unknown family '%s' in table %s.", family, tableURI));
      }

      final CassandraTableName table =
          CassandraTableName.getLocalityGroupTableName(
              tableURI,
              familyLayout.getLocalityGroup().getId());

      // In Cassandra Kiji, a write to HConstants.LATEST_TIMESTAMP should be a write with the
      // current system time.
      final long version;
      if (timestamp == HConstants.LATEST_TIMESTAMP) {
        version = System.currentTimeMillis();
      } else {
        version = timestamp;
      }

      int ttl = familyLayout.getLocalityGroup().getDesc().getTtlSeconds();

      final KijiColumnName columnName = KijiColumnName.create(family, qualifier);
      final CassandraColumnName cassandraColumn =
          mCapsule.getColumnNameTranslator().toCassandraColumnName(columnName);
View Full Code Here

      final String qualifier
  ) throws IOException {
    final KijiURI tableURI = mTable.getURI();
    synchronized (mMonitor) {
      final KijiTableLayout layout = mCapsule.getLayout();
      final FamilyLayout familyLayout = layout.getFamilyMap().get(family);
      if (familyLayout == null) {
        throw new IllegalArgumentException(
            String.format("Unknown family '%s' in table %s.", family, tableURI));
      }

      final CassandraTableName table =
          CassandraTableName.getLocalityGroupTableName(
              tableURI,
              familyLayout.getLocalityGroup().getId());

      final CassandraColumnName column =
          mCapsule
              .getColumnNameTranslator()
              .toCassandraColumnName(KijiColumnName.create(family, qualifier));
View Full Code Here

  ) throws IOException {

    final KijiURI tableURI = mTable.getURI();
    synchronized (mMonitor) {
      final KijiTableLayout layout = mCapsule.getLayout();
      final FamilyLayout familyLayout = layout.getFamilyMap().get(family);
      if (familyLayout == null) {
        throw new IllegalArgumentException(
            String.format("Unknown family '%s' in table %s.", family, tableURI));
      }

      final CassandraColumnName column =
          mCapsule
              .getColumnNameTranslator()
              .toCassandraColumnName(KijiColumnName.create(family, qualifier));

      final CassandraTableName table =
          CassandraTableName.getLocalityGroupTableName(
              tableURI,
              familyLayout.getLocalityGroup().getId());

      final Statement delete =
          CQLUtils.getCellDeleteStatement(
              layout,
              table,
View Full Code Here

          if (column.isFullyQualified()) {
            Preconditions.checkState(
                getData.getCells(column.getFamily(), column.getQualifier()).isEmpty(),
                "Fell back to a get of a non-empty row.");
          } else {
            final FamilyLayout family = table.getLayout().getFamilyMap().get(column.getFamily());

            if (family.isMapType()) {
              Preconditions.checkState(getData.getCells(columnRequest.getFamily()).isEmpty(),
                  "Fell back to a get of a non-empty row.");
            } else {
              for (final String qualifier : family.getColumnMap().keySet()) {
                Preconditions.checkState(
                    getData.getCells(columnRequest.getFamily(), qualifier).isEmpty(),
                    "Fell back to a get of a non-empty row.");
              }
            }
View Full Code Here

      PrintStream printStream)
      throws IOException {

    // Unpack and print result for the map type families.
    for (Entry<FamilyLayout, List<String>> entry : mapTypeFamilies.entrySet()) {
      final FamilyLayout family = entry.getKey();
      if (family.getDesc().getMapSchema().getType() == SchemaType.COUNTER) {

        // If this map family of counters has no qualifiers, print entire family.
        if (entry.getValue().isEmpty()) {
          for (String key : row.getQualifiers(family.getName())) {
            KijiCell<Long> counter = row.getMostRecentCell(family.getName(), key);
            if (null != counter) {
              printCell(row.getEntityId(), counter, printStream);
            }
          }
        // If this map family of counters has been qualified, print only the given columns.
        } else {
          for (String key : entry.getValue()) {
            KijiCell<Long> counter = row.getMostRecentCell(family.getName(), key);
            if (null != counter) {
              printCell(row.getEntityId(), counter, printStream);
            }
          }
        }
      } else {
        // If this map family of non-counters has no qualifiers, print entire family.
        if (entry.getValue().isEmpty()) {
          NavigableMap<String, NavigableMap<Long, Object>> keyTimeseriesMap =
              row.getValues(family.getName());
          for (String key : keyTimeseriesMap.keySet()) {
            for (Entry<Long, Object> timestampedCell : keyTimeseriesMap.get(key).entrySet()) {
              long timestamp = timestampedCell.getKey();
              printCell(row.getEntityId(), timestamp, family.getName(), key,
                  timestampedCell.getValue(), printStream);
            }
          }
        // If this map family of non-counters has been qualified, print only the given columns.
        } else {
          for (String key : entry.getValue()) {
            NavigableMap<Long, Object> timeseriesMap =
                row.getValues(family.getName(), key);
            for (Entry<Long, Object> timestampedCell : timeseriesMap.entrySet()) {
              long timestamp = timestampedCell.getKey();
              printCell(
                  row.getEntityId(), timestamp, family.getName(), key, timestampedCell.getValue(),
                  printStream);
            }
          }
        }
      }
View Full Code Here

          familyMap.put(family, new ArrayList<String>());
        }
      }
    } else {
      for (KijiColumnName rawColumn : rawColumnNames) {
        final FamilyLayout family = layout.getFamilyMap().get(rawColumn.getFamily());
        if (null == family) {
          throw new RuntimeException(String.format(
              "No family '%s' in table '%s'.", rawColumn.getFamily(), layout.getName()));
        }
        if (family.isMapType()) {
          addColumn(family, rawColumn.getQualifier(), familyMap);
        }
      }
    }
    return familyMap;
View Full Code Here

          familyMap.put(family, Lists.newArrayList(family.getColumns()));
        }
      }
    } else {
      for (KijiColumnName rawColumn : rawColumnNames) {
        final FamilyLayout family = layout.getFamilyMap().get(rawColumn.getFamily());
        if (null == family) {
          throw new RuntimeException(String.format(
              "No family '%s' in table '%s'.", rawColumn.getFamily(), layout.getName()));
        }
        if (family.isGroupType()) {
          // We'll include it.  Is it fully qualified?
          if (!rawColumn.isFullyQualified()) {
            // User specified a group-type family, but no qualifier.  Include all qualifiers.
            for (ColumnLayout column : family.getColumns()) {
              addColumn(family, column, familyMap);
            }
          } else {
            final ColumnLayout column = family.getColumnMap().get(rawColumn.getQualifier());
            if (null == column) {
              throw new RuntimeException(String.format(
                  "No column '%s' in table '%s'.", rawColumn, layout.getName()));
            }
            addColumn(family, column, familyMap);
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.