Examples of InvalidTypesException


Examples of eu.stratosphere.api.java.functions.InvalidTypesException

  static final <T extends Writable> TypeInformation<T> getWritableTypeInfo(Class<T> typeClass) {
    if (Writable.class.isAssignableFrom(typeClass) && !typeClass.equals(Writable.class)) {
      return new WritableTypeInfo<T>(typeClass);
    }
    else {
      throw new InvalidTypesException("The given class is no subclass of " + Writable.class.getName());
    }
  }
View Full Code Here

Examples of org.apache.flink.api.common.functions.InvalidTypesException

  // --------------------------------------------------------------------------------------------

  @SuppressWarnings("unchecked")
  public static <X, C> BasicArrayTypeInfo<X, C> getInfoFor(Class<X> type) {
    if (!type.isArray()) {
      throw new InvalidTypesException("The given class is no array.");
    }

    // basic type arrays
    return (BasicArrayTypeInfo<X, C>) TYPES.get(type);
  }
View Full Code Here

Examples of org.apache.flink.api.common.functions.InvalidTypesException

  // --------------------------------------------------------------------------------------------

  @SuppressWarnings("unchecked")
  public static <X> PrimitiveArrayTypeInfo<X> getInfoFor(Class<X> type) {
    if (!type.isArray()) {
      throw new InvalidTypesException("The given class is no array.");
    }

    // basic type arrays
    return (PrimitiveArrayTypeInfo<X>) TYPES.get(type);
  }
View Full Code Here

Examples of org.apache.flink.api.common.functions.InvalidTypesException

  static final <T extends Writable> TypeInformation<T> getWritableTypeInfo(Class<T> typeClass) {
    if (Writable.class.isAssignableFrom(typeClass) && !typeClass.equals(Writable.class)) {
      return new WritableTypeInfo<T>(typeClass);
    }
    else {
      throw new InvalidTypesException("The given class is no subclass of " + Writable.class.getName());
    }
  }
View Full Code Here

Examples of org.apache.flink.api.common.functions.InvalidTypesException

     
      Type curT = t;
     
      // do not allow usage of Tuple as type
      if (curT instanceof Class<?> && ((Class<?>) curT).equals(Tuple.class)) {
        throw new InvalidTypesException(
            "Usage of class Tuple as a type is not allowed. Use a concrete subclass (e.g. Tuple1, Tuple2, etc.) instead.");
      }
           
      // go up the hierarchy until we reach immediate child of Tuple (with or without generics)
      // collect the types while moving up for a later top-down
      while (!(curT instanceof ParameterizedType && ((Class<?>) ((ParameterizedType) curT).getRawType()).getSuperclass().equals(
          Tuple.class))
          && !(curT instanceof Class<?> && ((Class<?>) curT).getSuperclass().equals(Tuple.class))) {
        typeHierarchy.add(curT);
       
        // parameterized type
        if (curT instanceof ParameterizedType) {
          curT = ((Class<?>) ((ParameterizedType) curT).getRawType()).getGenericSuperclass();
        }
        // class
        else {
          curT = ((Class<?>) curT).getGenericSuperclass();
        }
      }
     
      // check if immediate child of Tuple has generics
      if (curT instanceof Class<?>) {
        throw new InvalidTypesException("Tuple needs to be parameterized by using generics.");
      }
     
      ParameterizedType tupleChild = (ParameterizedType) curT;
     
      Type[] subtypes = new Type[tupleChild.getActualTypeArguments().length];
     
      // materialize possible type variables
      for (int i = 0; i < subtypes.length; i++) {
        // materialize immediate TypeVariables
        if (tupleChild.getActualTypeArguments()[i] instanceof TypeVariable<?>) {
          subtypes[i] = materializeTypeVariable(typeHierarchy, (TypeVariable<?>) tupleChild.getActualTypeArguments()[i]);
        }
        // class or parameterized type
        else {
          subtypes[i] = tupleChild.getActualTypeArguments()[i];
        }
      }
     
      TypeInformation<?>[] tupleSubTypes = new TypeInformation<?>[subtypes.length];
      for (int i = 0; i < subtypes.length; i++) {
        // sub type could not be determined with materializing
        // try to derive the type info of the TypeVariable from the immediate base child input as a last attempt
        if (subtypes[i] instanceof TypeVariable<?>) {
          tupleSubTypes[i] = createTypeInfoFromInputs((TypeVariable<?>) subtypes[i], typeHierarchy, in1Type, in2Type);
         
          // variable could not be determined
          if (tupleSubTypes[i] == null) {
            throw new InvalidTypesException("Type of TypeVariable '" + ((TypeVariable<?>) subtypes[i]).getName() + "' in '"
                + ((TypeVariable<?>) subtypes[i]).getGenericDeclaration()
                + "' could not be determined. This is most likely a type erasure problem. "
                + "The type extraction currently supports types with generic variables only in cases where "
                + "all variables in the return type can be deduced from the input type(s).");
          }
        } else {
          tupleSubTypes[i] = createTypeInfoWithTypeHierarchy(new ArrayList<Type>(typeHierarchy), subtypes[i], in1Type, in2Type);
        }
      }
     
      Class<?> tAsClass = null;
      if (t instanceof Class<?>) {
        tAsClass = (Class<?>) t;
      } else if (t instanceof ParameterizedType) {
        tAsClass = (Class<? extends Tuple>) ((ParameterizedType) t).getRawType();
      }
      Preconditions.checkNotNull(tAsClass, "t has a unexpected type");
      // check if the class we assumed to be a Tuple so far is actually a pojo because it contains additional fields.
      // check for additional fields.
      int fieldCount = countFieldsInClass(tAsClass);
      if(fieldCount != tupleSubTypes.length) {
        // the class is not a real tuple because it contains additional fields. treat as a pojo
        return (TypeInformation<OUT>) analyzePojo(tAsClass, new ArrayList<Type>(), null); // the typeHierarchy here should be sufficient, even though it stops at the Tuple.class.
      }
     
      return new TupleTypeInfo(tAsClass, tupleSubTypes);
     
    }
    // type depends on another type
    // e.g. class MyMapper<E> extends MapFunction<String, E>
    else if (t instanceof TypeVariable) {
      Type typeVar = materializeTypeVariable(typeHierarchy, (TypeVariable<?>) t);
     
      if (!(typeVar instanceof TypeVariable)) {
        return createTypeInfoWithTypeHierarchy(typeHierarchy, typeVar, in1Type, in2Type);
      }
      // try to derive the type info of the TypeVariable from the immediate base child input as a last attempt
      else {
        TypeInformation<OUT> typeInfo = (TypeInformation<OUT>) createTypeInfoFromInputs((TypeVariable<?>) t, typeHierarchy, in1Type, in2Type);
        if (typeInfo != null) {
          return typeInfo;
        } else {
          throw new InvalidTypesException("Type of TypeVariable '" + ((TypeVariable<?>) t).getName() + "' in '"
              + ((TypeVariable<?>) t).getGenericDeclaration() + "' could not be determined. This is most likely a type erasure problem. "
              + "The type extraction currently supports types with generic variables only in cases where "
              + "all variables in the return type can be deduced from the input type(s).");
        }
      }
    }
    // arrays with generics
    else if (t instanceof GenericArrayType) {
      GenericArrayType genericArray = (GenericArrayType) t;
     
      Type componentType = genericArray.getGenericComponentType();
     
      // due to a Java 6 bug, it is possible that the JVM classifies e.g. String[] or int[] as GenericArrayType instead of Class
      if (componentType instanceof Class) {
       
        Class<?> componentClass = (Class<?>) componentType;
        String className;
        // for int[], double[] etc.
        if(componentClass.isPrimitive()) {
          className = encodePrimitiveClass(componentClass);
        }
        // for String[], Integer[] etc.
        else {
          className = "L" + componentClass.getName() + ";";
        }
       
        Class<OUT> classArray = null;
        try {
          classArray = (Class<OUT>) Class.forName("[" + className);
        } catch (ClassNotFoundException e) {
          throw new InvalidTypesException("Could not convert GenericArrayType to Class.");
        }
        return getForClass(classArray);
      }
     
      TypeInformation<?> componentInfo = createTypeInfoWithTypeHierarchy(typeHierarchy, genericArray.getGenericComponentType(),
          in1Type, in2Type);
      return ObjectArrayTypeInfo.getInfoFor(t, componentInfo);
    }
    // objects with generics are treated as raw type
    else if (t instanceof ParameterizedType) { //TODO
      return privateGetForClass((Class<OUT>) ((ParameterizedType) t).getRawType(), typeHierarchy, (ParameterizedType) t);
    }
    // no tuple, no TypeVariable, no generic type
    else if (t instanceof Class) {
      return privateGetForClass((Class<OUT>) t, new ArrayList<Type>());
    }
   
    throw new InvalidTypesException("Type Information could not be created.");
  }
View Full Code Here

Examples of org.apache.flink.api.common.functions.InvalidTypesException

    ArrayList<Type> typeHierarchy = new ArrayList<Type>();
    try {
      validateInfo(typeHierarchy, t, inType);
    }
    catch(InvalidTypesException e) {
      throw new InvalidTypesException("Input mismatch: " + e.getMessage());
    }
  }
View Full Code Here

Examples of org.apache.flink.api.common.functions.InvalidTypesException

    ArrayList<Type> typeHierarchy = new ArrayList<Type>();
    try {
      validateInfo(typeHierarchy, getParameterType(baseClass, typeHierarchy, clazz, inputParamPos), inType);
    }
    catch(InvalidTypesException e) {
      throw new InvalidTypesException("Input mismatch: " + e.getMessage());
    }
  }
View Full Code Here

Examples of org.apache.flink.api.common.functions.InvalidTypesException

 
  @SuppressWarnings("unchecked")
  private static void validateInfo(ArrayList<Type> typeHierarchy, Type type, TypeInformation<?> typeInfo) {
   
    if (type == null) {
      throw new InvalidTypesException("Unknown Error. Type is null.");
    }
   
    if (typeInfo == null) {
      throw new InvalidTypesException("Unknown Error. TypeInformation is null.");
    }
   
    if (!(type instanceof TypeVariable<?>)) {
      // check for basic type
      if (typeInfo.isBasicType()) {
       
        TypeInformation<?> actual = null;
        // check if basic type at all
        if (!(type instanceof Class<?>) || (actual = BasicTypeInfo.getInfoFor((Class<?>) type)) == null) {
          throw new InvalidTypesException("Basic type expected.");
        }
        // check if correct basic type
        if (!typeInfo.equals(actual)) {
          throw new InvalidTypesException("Basic type '" + typeInfo + "' expected but was '" + actual + "'.");
        }
       
      }
      // check for tuple
      else if (typeInfo.isTupleType()) {
        // check if tuple at all
        if (!(type instanceof Class<?> && Tuple.class.isAssignableFrom((Class<?>) type))
            && !(type instanceof ParameterizedType && Tuple.class.isAssignableFrom((Class<?>) ((ParameterizedType) type)
                .getRawType()))) {
          throw new InvalidTypesException("Tuple type expected.");
        }
       
        // do not allow usage of Tuple as type
        if (type instanceof Class<?> && ((Class<?>) type).equals(Tuple.class)) {
          throw new InvalidTypesException("Concrete subclass of Tuple expected.");
        }
       
        // go up the hierarchy until we reach immediate child of Tuple (with or without generics)
        while (!(type instanceof ParameterizedType && ((Class<?>) ((ParameterizedType) type).getRawType()).getSuperclass().equals(
            Tuple.class))
            && !(type instanceof Class<?> && ((Class<?>) type).getSuperclass().equals(Tuple.class))) {
          typeHierarchy.add(type);
          // parameterized type
          if (type instanceof ParameterizedType) {
            type = ((Class<?>) ((ParameterizedType) type).getRawType()).getGenericSuperclass();
          }
          // class
          else {
            type = ((Class<?>) type).getGenericSuperclass();
          }
        }
       
        // check if immediate child of Tuple has generics
        if (type instanceof Class<?>) {
          throw new InvalidTypesException("Parameterized Tuple type expected.");
        }
       
        TupleTypeInfo<?> tti = (TupleTypeInfo<?>) typeInfo;
       
        Type[] subTypes = ((ParameterizedType) type).getActualTypeArguments();
       
        if (subTypes.length != tti.getArity()) {
          throw new InvalidTypesException("Tuple arity '" + tti.getArity() + "' expected but was '"
              + subTypes.length + "'.");
        }
       
        for (int i = 0; i < subTypes.length; i++) {
          validateInfo(new ArrayList<Type>(typeHierarchy), subTypes[i], ((TupleTypeInfo<?>) typeInfo).getTypeAt(i));
        }
      }
      // check for Writable
      else if (typeInfo instanceof WritableTypeInfo<?>) {
        // check if writable at all
        if (!(type instanceof Class<?> && Writable.class.isAssignableFrom((Class<?>) type))) {
          throw new InvalidTypesException("Writable type expected.");
        }
       
        // check writable type contents
        Class<?> clazz = null;
        if (((WritableTypeInfo<?>) typeInfo).getTypeClass() != (clazz = (Class<?>) type)) {
          throw new InvalidTypesException("Writable type '"
              + ((WritableTypeInfo<?>) typeInfo).getTypeClass().getCanonicalName() + "' expected but was '"
              + clazz.getCanonicalName() + "'.");
        }
      }
      // check for basic array
      else if (typeInfo instanceof BasicArrayTypeInfo<?, ?>) {
        Type component = null;
        // check if array at all
        if (!(type instanceof Class<?> && ((Class<?>) type).isArray() && (component = ((Class<?>) type).getComponentType()) != null)
            && !(type instanceof GenericArrayType && (component = ((GenericArrayType) type).getGenericComponentType()) != null)) {
          throw new InvalidTypesException("Array type expected.");
        }
       
        if (component instanceof TypeVariable<?>) {
          component = materializeTypeVariable(typeHierarchy, (TypeVariable<?>) component);
          if (component instanceof TypeVariable) {
            return;
          }
        }
       
        validateInfo(typeHierarchy, component, ((BasicArrayTypeInfo<?, ?>) typeInfo).getComponentInfo());
       
      }
      // check for object array
      else if (typeInfo instanceof ObjectArrayTypeInfo<?, ?>) {
        // check if array at all
        if (!(type instanceof Class<?> && ((Class<?>) type).isArray()) && !(type instanceof GenericArrayType)) {
          throw new InvalidTypesException("Object array type expected.");
        }
       
        // check component
        Type component = null;
        if (type instanceof Class<?>) {
          component = ((Class<?>) type).getComponentType();
        } else {
          component = ((GenericArrayType) type).getGenericComponentType();
        }
       
        if (component instanceof TypeVariable<?>) {
          component = materializeTypeVariable(typeHierarchy, (TypeVariable<?>) component);
          if (component instanceof TypeVariable) {
            return;
          }
        }
       
        validateInfo(typeHierarchy, component, ((ObjectArrayTypeInfo<?, ?>) typeInfo).getComponentInfo());
      }
      // check for value
      else if (typeInfo instanceof ValueTypeInfo<?>) {
        // check if value at all
        if (!(type instanceof Class<?> && Value.class.isAssignableFrom((Class<?>) type))) {
          throw new InvalidTypesException("Value type expected.");
        }
       
        TypeInformation<?> actual = null;
        // check value type contents
        if (!((ValueTypeInfo<?>) typeInfo).equals(actual = ValueTypeInfo.getValueTypeInfo((Class<? extends Value>) type))) {
          throw new InvalidTypesException("Value type '" + typeInfo + "' expected but was '" + actual + "'.");
        }
      }
      // check for POJO
      else if (typeInfo instanceof PojoTypeInfo) {
        Class<?> clazz = null;
        if (!(type instanceof Class<?> && ((PojoTypeInfo<?>) typeInfo).getTypeClass() == (clazz = (Class<?>) type))
            && !(type instanceof ParameterizedType && (clazz = (Class<?>) ((ParameterizedType) type).getRawType()) == ((PojoTypeInfo<?>) typeInfo)
                .getTypeClass())) {
          throw new InvalidTypesException("POJO type '"
              + ((PojoTypeInfo<?>) typeInfo).getTypeClass().getCanonicalName() + "' expected but was '"
              + clazz.getCanonicalName() + "'.");
        }
      }
      // check for generic object
      else if (typeInfo instanceof GenericTypeInfo<?>) {
        Class<?> clazz = null;
        if (!(type instanceof Class<?> && ((GenericTypeInfo<?>) typeInfo).getTypeClass() == (clazz = (Class<?>) type))
            && !(type instanceof ParameterizedType && (clazz = (Class<?>) ((ParameterizedType) type).getRawType()) == ((GenericTypeInfo<?>) typeInfo)
                .getTypeClass())) {
          throw new InvalidTypesException("Generic object type '"
              + ((GenericTypeInfo<?>) typeInfo).getTypeClass().getCanonicalName() + "' expected but was '"
              + clazz.getCanonicalName() + "'.");
        }
      }
    } else {
View Full Code Here

Examples of org.apache.flink.api.common.functions.InvalidTypesException

      return;
    }
    final Class<?> clazz = (Class<?>) t;

    if(clazz.getTypeParameters().length > 0) {
      throw new InvalidTypesException("The generic type parameters of '" + clazz.getSimpleName() + "' are missing. \n"
          + "It seems that your compiler has not stored them into the .class file. \n"
          + "Currently, only the Eclipse JDT compiler preserves the type information necessary to use the lambdas feature type-safely. \n"
          + "See the documentation for more information about how to compile jobs containing lambda expressions.");
    }
  }
View Full Code Here

Examples of org.apache.flink.api.common.functions.InvalidTypesException

      return "J";
    }
    else if (name.equals("short")) {
      return "S";
    }
    throw new InvalidTypesException();
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.