Package com.datasalt.pangool.tuplemr

Examples of com.datasalt.pangool.tuplemr.TupleMRException


    String[] fieldsStr = serialized.split(",");
    List<Field> fields = new ArrayList<Field>();
    for(String field : fieldsStr) {
      String[] nameType = field.split(":");
      if(nameType.length != 2) {
        throw new TupleMRException("Incorrect fields description " + serialized);
      }
      String fieldName = nameType[0].trim();
      String fieldType = nameType[1].trim();
      Type type = strToType.get(fieldType);
      try {
        if(type != null) {
          fields.add(Field.create(fieldName, type));
        } else {
          Class<?> objectClazz = Class.forName(fieldType);
          if(objectClazz.isEnum()) {
            fields.add(Field.createEnum(fieldName, objectClazz));
          } else {
            fields.add(Field.createObject(fieldName, objectClazz));
          }
        }
      } catch(ClassNotFoundException e) {
        throw new TupleMRException("Type " + fieldType
            + " not a valid class name ", e);
      }
    }
    return fields;
  }
View Full Code Here


   * schemas added by this method. Schemas added in consecutive calls to this
   * method must be named differently.
   */
  public void addIntermediateSchema(Schema schema) throws TupleMRException {
    if (schemaAlreadyExists(schema.getName())) {
      throw new TupleMRException("There's a schema with that name '" + schema.getName()
          + "'");
    }
    schemas.add(schema);
  }
View Full Code Here

    failIfEmpty(groupByFields, "GroupBy fields can't be null or empty");
    failIfEmpty(schemas, "No schemas defined");
    failIfNotNull(this.groupByFields, "GroupBy fields already set : " + Arrays.toString(groupByFields));
    for (String field : groupByFields) {
      if (!fieldPresentInAllSchemas(field)) {
        throw new TupleMRException("Can't group by field '" + field
            + "' . Not present in all sources");
      }
      if (!fieldSameTypeInAllSources(field)) {
        throw new TupleMRException("Can't group by field '" + field
            + "' since its type differs among sources");
      }
    }
    this.groupByFields = Arrays.asList(groupByFields);
  }
View Full Code Here

    failIfNull(rollupFrom, "Rollup can't be null");
    failIfNotNull(this.rollupFrom, "Rollup was already set");
    failIfEmpty(this.groupByFields, "GroupBy fields not set");

    if (!this.groupByFields.contains(rollupFrom)) {
      throw new TupleMRException("Rollup field must be present in groupBy fields '"
          + groupByFields + "'");
    }
    if (this.commonOrderBy == null) {
      // rollup needs explicit common orderby
      throw new TupleMRException(
          "Rollup needs explicit order by. No common order previously set");
    }
    this.rollupFrom = rollupFrom;
  }
View Full Code Here

  public void setCustomPartitionFields(String... fields) throws TupleMRException {
    failIfEmpty(fields, "Need to specify at leas tone field to partition by");
    // check if all fields are present in all sources and with the same type
    for (String field : fields) {
      if (!fieldPresentInAllSchemas(field)) {
        throw new TupleMRException("Can't group by field '" + field
            + "' . Not present in all sources");
      }
      if (!fieldSameTypeInAllSources(field)) {
        throw new TupleMRException("Can't group by field '" + field
            + "' since its type differs among sources");
      }
    }
    this.fieldsToPartition = fields;
  }
View Full Code Here

   * @param aliases    An {@link Aliases} instance that contains pairs of (alias, referenced_field) pairs.
   * @throws TupleMRException
   */
  public void setFieldAliases(String schemaName, Aliases aliases) throws TupleMRException {
    if (schemas.isEmpty()) {
      throw new TupleMRException("Not able to define field aliases with no schemas defined");
    } else if (schemas.size() == 1) {
      throw new TupleMRException("Not able to define field aliases with just one schema");
    }
    failIfNull(schemaName, "Need to specify schema");
    failIfEmpty(aliases.getAliases().entrySet(), "Aliases empty");

    Schema schema = getSchemaByName(schemaName);
    if (schema == null) {
      throw new TupleMRException("Unknown schema : " + schemaName);
    }

    if (this.fieldAliases.get(schemaName) != null) {
      throw new TupleMRException("Already aliases set for schema '" + schemaName + "'");
    }

    for (Map.Entry<String, String> entry : aliases.getAliases().entrySet()) {
      String alias = entry.getKey();
      if (schema.containsField(alias)) {
        throw new TupleMRException("Forbidden alias '" + alias +
            "'. Schema '" + schema + "' already contains a field with that name");
      }

      String referenced = entry.getValue();
      if (!schema.containsField(referenced)) {
        throw new TupleMRException("Incorrect alias.Schema '" + schemaName +
            "' doesn't contain field: '" + referenced);
      }
    }
    this.fieldAliases.put(schemaName, aliases.getAliases());
  }
View Full Code Here

    failIfEmpty(ordering.getElements(), "OrderBy can't be empty");
    failIfEmpty(schemas, "Need to specify source schemas");
    failIfEmpty(groupByFields, "Need to specify group by fields");
    if (schemas.size() == 1) {
      if (ordering.getSchemaOrderIndex() != null) {
        throw new TupleMRException(
            "Not able to use source order when just one source specified");
      }
    }
    Schema firstSchema = schemas.get(0);

    for (SortElement sortElement : ordering.getElements()) {
      if (!fieldPresentInAllSchemas(sortElement.getName())) {
        throw new TupleMRException("Can't sort by field '" + sortElement.getName()
            + "' . Not present in all sources");
      }
      if (!fieldSameTypeInAllSources(sortElement.getName())) {
        throw new TupleMRException("Can't sort by field '" + sortElement.getName()
            + "' since its type differs among sources");
      }

      if (sortElement.getCustomComparator() != null) {
        Field field = firstSchema.getField(sortElement.getName());
        if (field.getType() != Type.OBJECT) {
          throw new TupleMRException("Not allowed to specify custom comparator for type=" + field.getType());
        }
      }
    }
    // group by fields need to be a prefix of sort by fields
    for (String groupField : groupByFields) {
      if (!ordering.containsBeforeSchemaOrder(groupField)) {
        throw new TupleMRException("Group by field '" + groupField
            + "' is not present in common order by before source order");
      }
    }

    this.commonOrderBy = ordering;
View Full Code Here

  public void setSpecificOrderBy(String schemaName, OrderBy ordering)
      throws TupleMRException {
    // TODO
    failIfNull(schemaName, "Not able to set specific orderBy for null source");
    if (!schemaAlreadyExists(schemaName)) {
      throw new TupleMRException("Unknown source '" + schemaName
          + "' in specific OrderBy");
    }
    failIfNull(ordering, "Not able to set null criteria for source '" + schemaName + "'");
    failIfEmpty(ordering.getElements(), "Can't set empty ordering");
    failIfNull(commonOrderBy,
        "Not able to set specific order with no previous common OrderBy");
    if (commonOrderBy.getSchemaOrderIndex() == null) {
      throw new TupleMRException(
          "Need to specify source order in common OrderBy when using specific OrderBy");
    }
    if (ordering.getSchemaOrderIndex() != null) {
      throw new TupleMRException("Not allowed to set source order in specific order");
    }
    Schema schema = getSchemaByName(schemaName);
    Map<String, String> aliases = fieldAliases.get(schema.getName());
    for (SortElement e : ordering.getElements()) {
      if (!Schema.containsFieldUsingAlias(schema, e.getName(), aliases)) {
        throw new TupleMRException("Source '" + schemaName + "' doesn't contain field '"
            + e.getName());
      }
      if (e.getCustomComparator() != null) {
        Field field = schema.getField(e.getName());
        if (field == null) {
          field = schema.getField(aliases.get(e.getName()));
        }
        if (field.getType() != Type.OBJECT) {
          throw new TupleMRException("Not allowed to set custom comparator for type=" + field.getType());
        }
      }
    }

    for (SortElement e : ordering.getElements()) {
      if (commonOrderBy.containsFieldName(e.getName())) {
        throw new TupleMRException("Common sort by already contains sorting for field '"
            + e.getName());
      }
    }
    this.specificsOrderBy.put(schemaName, ordering);
  }
View Full Code Here

TOP

Related Classes of com.datasalt.pangool.tuplemr.TupleMRException

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.