Package org.kiji.schema.avro

Examples of org.kiji.schema.avro.CellSchema


    final Kiji kiji = getKiji();
    final long writerUID = kiji.getSchemaTable().getOrCreateSchemaId(STRING_SCHEMA);

    // Setup table layout with pre-registered writer schemas.
    final TableLayoutDesc layoutDesc = KijiTableLayouts.getLayout(KijiTableLayouts.FULL_FEATURED);
    final CellSchema cellSchema = layoutDesc
            .getLocalityGroups().get(0)
            .getFamilies().get(0)
            .getColumns().get(0)
            .getColumnSchema();
    cellSchema.setWriters(Lists.newArrayList(AvroSchema.newBuilder().setUid(writerUID).build()));
    cellSchema.setType(SchemaType.AVRO);
    cellSchema.setAvroValidationPolicy(AvroValidationPolicy.STRICT);
    layoutDesc.setVersion("layout-1.3");
    kiji.createTable(layoutDesc);

    final KijiTable table = kiji.openTable("user");
    try {
View Full Code Here


  /** Tests writer schema compatibility with a LONG reader schema. */
  @Test
  public void testReaderSchemaLong() throws Exception {
    final Kiji kiji = getKiji();
    final TableLayoutDesc desc = KijiTableLayouts.getLayout(LAYOUT_DEVELOPER);
    final CellSchema cellSchema = desc.getLocalityGroups().get(0)
        .getFamilies().get(0)
        .getColumns().get(0)
        .getColumnSchema();
    cellSchema.setReaders(Lists.newArrayList(
        AvroSchema.newBuilder()
            .setUid(kiji.getSchemaTable().getOrCreateSchemaId(SCHEMA_LONG))
            .build()));

    kiji.createTable(desc);
View Full Code Here

  /** Tests writer schema compatibility with record schemas. */
  @Test
  public void testReaderSchemaTestRecord2() throws Exception {
    final Kiji kiji = getKiji();
    final TableLayoutDesc desc = KijiTableLayouts.getLayout(LAYOUT_DEVELOPER);
    final CellSchema cellSchema = desc.getLocalityGroups().get(0)
        .getFamilies().get(0)
        .getColumns().get(0)
        .getColumnSchema();
    cellSchema.setReaders(Lists.newArrayList(
        AvroSchema.newBuilder()
            .setUid(kiji.getSchemaTable().getOrCreateSchemaId(INT_TEXT_RECORD1))
            .build()));

    kiji.createTable(desc);
View Full Code Here

   * @return a new schema decoder.
   * @throws IOException on I/O error.
   */
  private static SchemaDecoder createSchemaDecoder(KijiTableLayout layout,
      BoundColumnReaderSpec spec) throws IOException {
    final CellSchema cellSchema = layout.getCellSchema(spec.getColumn());

    switch (cellSchema.getStorage()) {
      case HASH: {
        return new SchemaHashDecoder(layout.getSchemaTable());
      }
      case UID: {
        return new SchemaIdDecoder(layout.getSchemaTable());
View Full Code Here

   */
  private static Schema getReaderSchema(KijiTableLayout layout, BoundColumnReaderSpec spec)
      throws IOException {
    switch (spec.getColumnReaderSpec().getAvroReaderSchemaType()) {
      case DEFAULT: {
        final CellSchema cellSchema = layout.getCellSchema(spec.getColumn());
        final SchemaTableAvroResolver resolver =
            new SchemaTableAvroResolver(layout.getSchemaTable());
        return resolver.apply(cellSchema.getDefaultReader());
      }
      case EXPLICIT: return spec.getColumnReaderSpec().getAvroReaderSchema();
      case WRITER: return null;
      default: throw new InternalKijiError(
          "Unknown AvroReaderSchemaType: " + spec.getColumnReaderSpec().getAvroReaderSchemaType());
View Full Code Here

   * Returns the underlying CellSchema Avro record, creating it if necessary.
   * @return the underlying CellSchema Avro record, creating it if necessary.
   */
  private CellSchema getOrCreateCellSchema() {
    if (null == mCellSchema) {
      mCellSchema = new CellSchema();
    }
    return mCellSchema;
  }
View Full Code Here

      try {
        final KijiTableWriter writer = table.openTableWriter();
        try {
          for (KijiColumnName column : mCellURI.getColumns()) {
            try {
              final CellSchema cellSchema = table.getLayout().getCellSchema(column);
              if (cellSchema.getType() != SchemaType.COUNTER) {
                LOG.error("Can't increment non counter-type column '{}'", column);
                return FAILURE;
              }
              final EntityId entityId =
                  ToolUtils.createEntityIdFromUserInputs(mEntityId, table.getLayout());
View Full Code Here

      // this family in the reference layout if present.
      final ColumnId familyId = flayout.getId();

      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.
          for (ColumnLayout columnLayout : flayout.getColumns()) {
            final CellSchema cellSchema = columnLayout.getDesc().getColumnSchema();
            incompatabilityMessages.addAll(addColumnNamestoIncompatibilityMessages(
                flayout.getName(), columnLayout.getName(), validateCellSchema(null, cellSchema)));
          }
        }
View Full Code Here

          }
        }

        if (this.isMapType()) {
          // Force validation of schema:
          final CellSchema referenceSchema =
              (null != reference) ? reference.getDesc().getMapSchema() : null;
          validateCellSchema(mLayoutVersion, mDesc.getMapSchema(), referenceSchema);
        }

        // Build columns:
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) {
View Full Code Here

TOP

Related Classes of org.kiji.schema.avro.CellSchema

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.