Package org.kiji.schema

Examples of org.kiji.schema.KijiEncodingException


    final String validationPolicy = System.getProperty(SCHEMA_VALIDATION_POLICY);
    if (validationPolicy != null) {
      try {
        return AvroValidationPolicy.valueOf(validationPolicy);
      } catch (IllegalArgumentException iae) {
        throw new KijiEncodingException(
            String.format("Unrecognized validation policy: %s", validationPolicy), iae);
      }
    } else {
      return cellSpec.getCellSchema().getAvroValidationPolicy();
    }
View Full Code Here


    // Perform avro schema validation (if necessary).
    switch (mValidationPolicy) {
      case STRICT: {
        if (!mRegisteredWriters.contains(writerSchema)) {
          throw new KijiEncodingException(
              String.format("Error trying to use unregistered writer schema: %s",
                  writerSchema.toString(true)));
        }
        break;
      }
      case DEVELOPER: {
        if (!mRegisteredWriters.contains(writerSchema)) {
          LOG.info("Writer schema {} is currently not registered for column {}, registering now.",
              writerSchema, mCellSpec.getColumnURI());
          if (mCellSpec.getColumnURI() == null) {
            throw new InternalKijiError("CellSpec has no column URI: " + mCellSpec);
          }

          registerWriterSchema(mCellSpec.getColumnURI(), writerSchema);
        }
        break;
      }
      case NONE:
        // No-op. No validation required.
        break;
      case SCHEMA_1_0:
        // No-op. Validation happens for primitive types only during Avro serialization by setting
        // the writer schema (see getWriterSchema()).
        break;
      default: {
        throw new KijiEncodingException(
            String.format("Unrecognized schema validation policy: %s",
                mValidationPolicy.toString()));
      }
    }

    // Perform final column schema validation (if necessary).
    if (mCellSpec.getCellSchema().getStorage() == SchemaStorage.FINAL
        && !writerSchema.equals(mReaderSchema)) {
      throw new KijiEncodingException(
          String.format("Writer schema: %s does not match final column schema: %s",
              writerSchema.toString(true),
              mReaderSchema.toString(true)));
    }

    // Encode the Avro schema (if necessary):
    mSchemaEncoder.encode(writerSchema);

    // Encode the cell value:
    try {
      getDatumWriter(writerSchema).write(cellValue, mByteArrayEncoder);
    } catch (ClassCastException cce) {
      throw new KijiEncodingException(cce);
    } catch (AvroRuntimeException ure) {
      throw new KijiEncodingException(ure);
    }
    return mByteArrayOutputStream.toByteArray();
  }
View Full Code Here

      return mReaderSchema;
    } else {
      final String className = cellValue.getClass().getCanonicalName();
      final Schema schema = PRIMITIVE_SCHEMAS.get(className);
      if (schema == null) {
        throw new KijiEncodingException(String.format(
            "Unable to infer Avro writer schema for value: '%s'", cellValue));
      }
      return schema;
    }
  }
View Full Code Here

TOP

Related Classes of org.kiji.schema.KijiEncodingException

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.