Package com.cloudera.cdk.data

Examples of com.cloudera.cdk.data.SchemaValidationException


    boolean hasCounter = false;

    for (FieldMapping fieldMapping : fieldMappings) {
      if (fieldMapping.getMappingType() == MappingType.OCC_VERSION) {
        if (hasOCCVersion) {
          throw new SchemaValidationException(
              "Schema can't contain multiple occVersion fields.");
        }
        if (hasCounter) {
          throw new SchemaValidationException(
              "Schema can't contain both an occVersion field and a counter field.");
        }
        hasOCCVersion = true;
      } else if (fieldMapping.getMappingType() == MappingType.COUNTER) {
        if (hasOCCVersion) {
          throw new SchemaValidationException(
              "Schema can't contain both an occVersion field and a counter field.");
        }
        hasCounter = true;
      }
    }
View Full Code Here


        String[] familyQualifier = mappingValue.split(":", 2);
        byte[] family;
        try {
          family = familyQualifier[0].getBytes("UTF-8");
        } catch (UnsupportedEncodingException exc) {
          throw new SchemaValidationException(
              "fieldType Must support UTF-8 encoding", exc);
        }
        return family;
      }
    }
View Full Code Here

        byte[] qualifier;
        try {
          qualifier = familyQualifier.length == 1 ? new byte[0]
              : familyQualifier[1].getBytes("UTF-8");
        } catch (UnsupportedEncodingException exc) {
          throw new SchemaValidationException(
              "fieldType Must support UTF-8 encoding", exc);
        }
        return qualifier;
      }
    }
View Full Code Here

      Schema schema) {
    // Get the mapping of fields to default values.
    Map<String, Object> defaultValueMap = AvroUtils.getDefaultValueMap(schema);
    JsonNode fields = schemaAsJson.get("fields");
    if (fields == null) {
      throw new SchemaValidationException(
          "Avro Record Schema must contain fields");
    }

    // Build the fieldMappingMap, which is a mapping of field names to
    // AvroFieldMapping instances (which describe the mapping type of the
View Full Code Here

    ObjectMapper mapper = new ObjectMapper();
    JsonNode avroRecordSchemaJson;
    try {
      avroRecordSchemaJson = mapper.readValue(rawSchema, JsonNode.class);
    } catch (IOException e) {
      throw new SchemaValidationException(
          "Could not parse the avro record as JSON.", e);
    }
    return avroRecordSchemaJson;
  }
View Full Code Here

      JsonNode mappingTypeNode = mappingNode.get("type");
      JsonNode mappingValueNode = mappingNode.get("value");
      JsonNode prefixValueNode = mappingNode.get("prefix");
      if (mappingTypeNode == null) {
        String msg = "mapping attribute must contain type.";
        throw new SchemaValidationException(msg);
      }

      MappingType mappingType = null;
      String mappingValue = null;
      String prefix = null;

      if (mappingTypeNode.getTextValue().equals("column")) {
        mappingType = MappingType.COLUMN;
        if (mappingValueNode == null) {
          throw new SchemaValidationException(
              "column mapping type must contain a value.");
        }
        mappingValue = mappingValueNode.getTextValue();
      } else if ((mappingTypeNode.getTextValue().equals("keyAsColumn"))) {
        mappingType = MappingType.KEY_AS_COLUMN;
        if (mappingValueNode == null) {
          throw new SchemaValidationException(
              "keyAsColumn mapping type must contain a value.");
        }
        mappingValue = mappingValueNode.getTextValue();
        if (prefixValueNode != null) {
          prefix = prefixValueNode.getTextValue();
        }
      } else if (mappingTypeNode.getTextValue().equals("counter")) {
        if (type != Schema.Type.INT && type != Schema.Type.LONG) {
          throw new SchemaValidationException("counter mapping type must be an int or a long");
        }
        if (mappingValueNode == null) {
          throw new SchemaValidationException(
              "counter mapping type must contain a value.");
        }
        mappingType = MappingType.COUNTER;
        mappingValue = mappingValueNode.getTextValue();
      } else if (mappingTypeNode.getTextValue().equals("occVersion")) {
        mappingType = MappingType.OCC_VERSION;
      } else if (mappingTypeNode.getTextValue().equals("key")) {
        mappingType = MappingType.KEY;
        if (mappingValueNode == null) {
          throw new SchemaValidationException(
              "key mapping type must contain an integer value specifying it's key order.");
        }
        mappingValue = mappingValueNode.getTextValue();
      }
      Object defaultValue = defaultValueMap.get(fieldName);
View Full Code Here

    JsonNode newSchema;
    try {
      oldSchema = mapper.readValue(oldSchemaString, JsonNode.class);
      newSchema = mapper.readValue(newSchemaString, JsonNode.class);
    } catch (IOException e) {
      throw new SchemaValidationException(
          "Schemas not proper JSON in mappingCompatible", e);
    }

    JsonNode oldSchemaFields = oldSchema.get("fields");
    JsonNode newSchemaFields = newSchema.get("fields");
View Full Code Here

      serializeKeyAsColumn(fieldName, fieldMapping.getFamily(),
          fieldMapping.getPrefix(), fieldValue, put);
    } else if (fieldMapping.getMappingType() == MappingType.OCC_VERSION) {
      serializeOCCColumn(fieldValue, putAction);
    } else {
      throw new SchemaValidationException(
          "Invalid field mapping for field with name: "
              + fieldMapping.getFieldName());
    }
    return putAction;
  }
View Full Code Here

      return deserializeKeyAsColumn(fieldMapping.getFieldName(),
          fieldMapping.getFamily(), fieldMapping.getPrefix(), result);
    } else if (mappingType == MappingType.OCC_VERSION) {
      return deserializeOCCColumn(result);
    } else {
      throw new SchemaValidationException(
          "Invalid field mapping for field with name: " + fieldName);
    }
  }
View Full Code Here

      if (name.endsWith("StorageKey")) {
        for (String table : tables) {
          if (tableKeySchemaMap.containsKey(table)) {
            String msg = "Multiple keys for table: " + table;
            LOG.error(msg);
            throw new SchemaValidationException(msg);
          }
          LOG.debug("Adding key to tableKeySchemaMap for table: " + table
              + ". " + schemaString);
          tableKeySchemaMap.put(table, schemaString);
        }
      } else {
        for (String table : tables) {
          if (tableEntitySchemaMap.containsKey(table)) {
            tableEntitySchemaMap.get(table).add(schemaString);
          } else {
            List<String> entityList = new ArrayList<String>();
            entityList.add(schemaString);
            tableEntitySchemaMap.put(table, entityList);
          }
        }
      }
    }

    for (Entry<String, List<String>> entry : tableEntitySchemaMap.entrySet()) {
      String table = entry.getKey();
      List<String> entitySchemas = entry.getValue();
      if (!tableKeySchemaMap.containsKey(table)) {
        String msg = "No StorageKey Schema For Table: " + table;
        LOG.error(msg);
        throw new DatasetException(msg);
      }
      if (entitySchemas.size() == 0) {
        String msg = "StorageKey, but no entity schemas for Table: " + table;
        LOG.error(msg);
        throw new SchemaValidationException(msg);
      }
      for (String entitySchema : entry.getValue()) {
        createOrMigrateSchema(table, entitySchema, createTableAndFamilies);
      }
    }
View Full Code Here

TOP

Related Classes of com.cloudera.cdk.data.SchemaValidationException

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.