Package org.kiji.schema.layout

Examples of org.kiji.schema.layout.KijiTableLayout


    final TableLayoutDesc newTableLayoutDesc = TableLayoutDesc.newBuilder(mLayoutDesc).build();
    assertEquals(3, (int) newTableLayoutDesc.getLocalityGroups().get(0).getMaxVersions());
    newTableLayoutDesc.getLocalityGroups().get(0).setMaxVersions(1);
    newTableLayoutDesc.setReferenceLayout(getLayout("table").getDesc().getLayoutId());

    final KijiTableLayout newTableLayout = getKiji().modifyTableLayout(newTableLayoutDesc);
    assertEquals(
        newTableLayout.getLocalityGroupMap().get("default").getDesc().getMaxVersions(),
        getLayout("table").getLocalityGroupMap().get("default").getDesc().getMaxVersions());
  }
View Full Code Here


    lock.lock();
    try {
      final NavigableMap<Long, KijiTableLayout> layoutMap =
          metaTable.getTimedTableLayoutVersions(mTableURI.getTable(), Integer.MAX_VALUE);

      final KijiTableLayout currentLayout = layoutMap.lastEntry().getValue();
      final TableLayoutDesc update = mLayoutUpdate.apply(currentLayout);
      if (!Objects.equal(currentLayout.getDesc().getLayoutId(), update.getReferenceLayout())) {
        throw new InvalidLayoutException(String.format(
            "Reference layout ID %s does not match current layout ID %s.",
            update.getReferenceLayout(), currentLayout.getDesc().getLayoutId()));
      }

      final TableLayoutUpdateValidator validator = new TableLayoutUpdateValidator(mKiji);
      final KijiTableLayout updatedLayout =
          KijiTableLayout.createUpdatedLayout(update , currentLayout);
      validateCassandraTableLayout(updatedLayout.getDesc());
      validator.validate(currentLayout, updatedLayout);

      final TableLayoutTracker layoutTracker =
          new TableLayoutTracker(mZKClient, mTableURI, mLayoutUpdateHandler).start();
      try {
View Full Code Here

            .setSchemaFormat(SchemaFormat.UID));

    // Fetch all the layout history:
    final List<KijiTableLayout> layouts =
        getTableLayoutVersions(tableName, HConstants.ALL_VERSIONS);
    final KijiTableLayout currentLayout = layouts.isEmpty() ? null : layouts.get(0);
    final KijiTableLayout tableLayout = KijiTableLayout.createUpdatedLayout(update, currentLayout);

    Preconditions.checkArgument(tableName.equals(tableLayout.getName()));

    // Set of all the former layout IDs:
    final Set<String> layoutIDs = Sets.newHashSet();
    for (KijiTableLayout layout : layouts) {
      layoutIDs.add(layout.getDesc().getLayoutId());
    }

    final String refLayoutIdStr = update.getReferenceLayout();

    final boolean hasCurrentLayout = (null != currentLayout);
    final boolean hasRefLayoutId = (null != refLayoutIdStr);
    if (hasCurrentLayout && !hasRefLayoutId) {
      throw new IOException(String.format(
          "Layout for table '%s' does not specify reference layout ID.", tableName));
    }
    if (!hasCurrentLayout && hasRefLayoutId) {
      throw new IOException(String.format(
          "Initial layout for table '%s' must not specify reference layout ID.", tableName));
    }

    final String layoutId = tableLayout.getDesc().getLayoutId();

    if (layoutIDs.contains(layoutId)) {
      throw new InvalidLayoutException(tableLayout,
          String.format("Layout ID '%s' already exists", layoutId));
    }

    //String metaTableName = mMetaTableName;

    Preconditions.checkNotNull(mUpdateTableLayoutStatement);
    // TODO: This should do a "check-and-put" to match the HBase implementation.
    mAdmin.execute(
        mUpdateTableLayoutStatement.bind(
            tableName,
            new Date(),
            layoutId,
            ByteBuffer.wrap(mCellEncoder.encode(tableLayout.getDesc())),
            ByteBuffer.wrap(mCellEncoder.encode(update)))
    );

    // Flush the writer schema for the Avro table layout first so other readers can see it.
    mSchemaTable.flush();
View Full Code Here

    // Convert result into a map from timestamps to values
    final NavigableMap<Long, KijiTableLayout> timedValues = Maps.newTreeMap();
    for (Row row: rows) {
      ByteBuffer blob = row.getBytes(QUALIFIER_LAYOUT);
      byte[] bytes = ByteUtils.toBytes(blob);
      KijiTableLayout layout = KijiTableLayout.newLayout(decodeTableLayoutDesc(bytes));

      Long timestamp = row.getDate(QUALIFIER_TIME).getTime();
      Preconditions.checkState(timedValues.put(timestamp, layout) == null);
    }
    return timedValues;
View Full Code Here

  /** {@inheritDoc} */
  @Override
  protected int run(List<String> nonFlagArgs) throws Exception {
    final KijiColumnName column = mColumnURI.getColumns().get(0);
    final KijiTableLayout layout = mTable.getLayout();
    final CellSchema cellSchema = layout.getCellSchema(column);

    final EntityId entityId =
        ToolUtils.createEntityIdFromUserInputs(mEntityId, layout);

    final KijiTableWriter writer = mTable.openTableWriter();
    try {
      if (cellSchema.getType() == SchemaType.COUNTER) {
        if (-1 == mTimestamp) {
          try {
            long value = Long.parseLong(mJsonValue);
            writer.put(entityId, column.getFamily(), column.getQualifier(), value);
          } catch (NumberFormatException nfe) {
            LOG.error("Could not parse value flag to a long: " + nfe.getMessage());
            return FAILURE;
          }
        } else {
          LOG.error("Counters do not support writing to a specific timestamp."
              + "  Remove the \"timestamp\" flag.");
          return FAILURE;
        }
      } else {
        // Get writer schema.
        // Otherwise, set writer Schema in mSchema in preparation to write an Avro record.
        if (null != mSchemaFlag) {
          try {
            LOG.debug("Schema is " + mSchemaFlag);
            mSchema = new Schema.Parser().parse(mSchemaFlag);
          } catch (AvroRuntimeException are) {
            LOG.error("Could not parse writer schema: " + are.toString());
            return FAILURE;
          }
        } else {
          try {
            mSchema = layout.getSchema(column);
          } catch (Exception e) {
            LOG.error(e.getMessage());
            return FAILURE;
          }
        }
View Full Code Here

  /** {@inheritDoc} */
  @Override
  public void deleteRow(final EntityId entityId) throws IOException {
    synchronized (mMonitor) {
      final KijiTableLayout layout = mCapsule.getLayout();
      final CassandraKijiTable tableURI = mTable;
      for (LocalityGroupLayout localityGroup : layout.getLocalityGroups()) {
        final ColumnId localityGroupId = localityGroup.getId();
        final CassandraTableName table =
            CassandraTableName.getLocalityGroupTableName(tableURI.getURI(), localityGroupId);

        final Statement delete =
View Full Code Here

      final String family,
      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));
      }
View Full Code Here

      final long timestamp
  ) 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));
      }
View Full Code Here

        final TableLayoutDesc layoutUpdate =
            TableLayoutDesc.newBuilder(table.getLayout().getDesc()).build();
        layoutUpdate.setReferenceLayout(layoutUpdate.getLayoutId());
        layoutUpdate.setLayoutId("2");

        final KijiTableLayout newLayout = kiji.modifyTableLayout(layoutUpdate);

      } finally {
        table.release();
      }
View Full Code Here

  private Kiji mKiji;

  @Before
  public final void setupTestLayoutConsumer() throws Exception {
    // Get the test table layouts.
    final KijiTableLayout layout = KijiTableLayout.newLayout(
        KijiTableLayouts.getLayout(KijiTableLayouts.COUNTER_TEST));

    // Populate the environment.
    mKiji = new InstanceBuilder(getKiji())
        .withTable("user", layout)
View Full Code Here

TOP

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

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.