@Override public boolean equals(Object obj) { return obj == this || obj instanceof TypeHint && this.typeInfo.equals(((TypeHint<?>) obj).typeInfo); }
@Override public boolean equals(Object obj) { if (obj instanceof UnionTypeInfo) { @SuppressWarnings("unchecked") UnionTypeInfo<T1, T2> unionTypeInfo = (UnionTypeInfo<T1, T2>) obj; return unionTypeInfo.canEqual(this) && oneType.equals(unionTypeInfo.oneType) && twoType.equals(unionTypeInfo.twoType); } else { return false; } }
@Override public boolean equals(Object obj) { if (obj == this) { return true; } else if (obj instanceof MapTypeInfo) { @SuppressWarnings("unchecked") MapTypeInfo<K, V> other = (MapTypeInfo<K, V>) obj; return (other.canEqual(this) && keyTypeInfo.equals(other.keyTypeInfo) && valueTypeInfo.equals(other.valueTypeInfo)); } else { return false; } }
@Override public boolean equals(Object o) { if (this == o) { return true; } if (!(o instanceof StreamTransformation)) { return false; } StreamTransformation<?> that = (StreamTransformation<?>) o; if (bufferTimeout != that.bufferTimeout) { return false; } if (id != that.id) { return false; } if (parallelism != that.parallelism) { return false; } if (!name.equals(that.name)) { return false; } return outputType != null ? outputType.equals(that.outputType) : that.outputType == null; }
@Override public boolean equals(Object obj) { if (obj instanceof ObjectArrayTypeInfo) { @SuppressWarnings("unchecked") ObjectArrayTypeInfo<T, C> objectArrayTypeInfo = (ObjectArrayTypeInfo<T, C>)obj; return objectArrayTypeInfo.canEqual(this) && arrayType == objectArrayTypeInfo.arrayType && componentInfo.equals(objectArrayTypeInfo.componentInfo); } else { return false; } }
@Override public boolean equals(Object obj) { if (obj == this) { return true; } else if (obj instanceof ListTypeInfo) { final ListTypeInfo<?> other = (ListTypeInfo<?>) obj; return other.canEqual(this) && elementTypeInfo.equals(other.elementTypeInfo); } else { return false; } }
@Override public boolean equals(Object obj) { if (obj instanceof PojoField) { PojoField other = (PojoField) obj; return other.canEqual(this) && type.equals(other.type) && Objects.equals(field, other.field); } else { return false; } }
@Override public boolean equals(Object obj) { if (obj instanceof BasicArrayTypeInfo) { BasicArrayTypeInfo<?, ?> other = (BasicArrayTypeInfo<?, ?>) obj; return other.canEqual(this) && arrayClass == other.arrayClass && componentInfo.equals(other.componentInfo); } else { return false; } }
private static boolean areFieldsCompatible(String sourceField, TypeInformation<?> inType, String targetField, TypeInformation<?> outType, boolean throwException) { try { // get source type information TypeInformation<?> sourceType = getExpressionTypeInformation(sourceField, inType); // get target type information TypeInformation<?> targetType = getExpressionTypeInformation(targetField, outType); return sourceType.equals(targetType); } catch (InvalidFieldReferenceException e) { if (throwException) { throw e; } else { return false; } } }
/** * Check whether the edge type of the {@link DataSet} is {@link NullValue}. * * @param edges data set for introspection * @param <T> graph ID type * @param <ET> edge value type * @return whether the edge type of the {@link DataSet} is {@link NullValue} */ private static <T, ET> boolean hasNullValueEdges(DataSet<Edge<T, ET>> edges) { TypeInformation<?> genericTypeInfo = edges.getType(); @SuppressWarnings("unchecked") TupleTypeInfo<Tuple3<T, T, ET>> tupleTypeInfo = (TupleTypeInfo<Tuple3<T, T, ET>>) genericTypeInfo; return tupleTypeInfo.getTypeAt(2).equals(ValueTypeInfo.NULL_VALUE_TYPE_INFO); } }
@Override public boolean equals(Object obj) { if (obj == this) { return true; } else if (obj instanceof MultisetTypeInfo) { final MultisetTypeInfo<?> other = (MultisetTypeInfo<?>) obj; return other.canEqual(this) && getKeyTypeInfo().equals(other.getKeyTypeInfo()); } else { return false; } }
/** * Creates a new {@code UnionTransformation} from the given input {@code StreamTransformations}. * * <p>The input {@code StreamTransformations} must all have the same type. * * @param inputs The list of input {@code StreamTransformations} */ public UnionTransformation(List<StreamTransformation<T>> inputs) { super("Union", inputs.get(0).getOutputType(), inputs.get(0).getParallelism()); for (StreamTransformation<T> input: inputs) { if (!input.getOutputType().equals(getOutputType())) { throw new UnsupportedOperationException("Type mismatch in input " + input); } } this.inputs = Lists.newArrayList(inputs); }
@Override public <E> void validateCustomPartitioner(Partitioner<E> partitioner, TypeInformation<E> typeInfo) { if (keyFields.size() != 1) { throw new InvalidProgramException("Custom partitioners can only be used with keys that have one key field."); } if (typeInfo == null) { // try to extract key type from partitioner try { typeInfo = TypeExtractor.getPartitionerTypes(partitioner); } catch (Throwable t) { // best effort check, so we ignore exceptions } } // only check if type is known and not a generic type if (typeInfo != null && !(typeInfo instanceof GenericTypeInfo)) { // check equality of key and partitioner type if (!keyType.equals(typeInfo)) { throw new InvalidProgramException("The partitioner is incompatible with the key type. " + "Partitioner type: " + typeInfo + " , key type: " + keyType); } } }
@Override public <E> void validateCustomPartitioner(Partitioner<E> partitioner, TypeInformation<E> typeInfo) { if (keyFields.size() != 1) { throw new InvalidProgramException("Custom partitioners can only be used with keys that have one key field."); } if (typeInfo == null) { // try to extract key type from partitioner try { typeInfo = TypeExtractor.getPartitionerTypes(partitioner); } catch (Throwable t) { // best effort check, so we ignore exceptions } } if (typeInfo != null && !(typeInfo instanceof GenericTypeInfo)) { // only check type compatibility if type is known and not a generic type TypeInformation<?> keyType = keyFields.get(0).getType(); if (!keyType.equals(typeInfo)) { throw new InvalidProgramException("The partitioner is incompatible with the key type. " + "Partitioner type: " + typeInfo + " , key type: " + keyType); } } }
/** * Creates a new {@link DataStream} by merging {@link DataStream} outputs of * the same type with each other. The DataStreams merged using this operator * will be transformed simultaneously. * * @param streams * The DataStreams to union output with. * @return The {@link DataStream}. */ @SafeVarargs public final DataStream<T> union(DataStream<T>... streams) { List<StreamTransformation<T>> unionedTransforms = new ArrayList<>(); unionedTransforms.add(this.transformation); for (DataStream<T> newStream : streams) { if (!getType().equals(newStream.getType())) { throw new IllegalArgumentException("Cannot union streams of different types: " + getType() + " and " + newStream.getType()); } unionedTransforms.add(newStream.getTransformation()); } return new DataStream<>(this.environment, new UnionTransformation<>(unionedTransforms)); }
/** * Check if two sets of keys are compatible to each other (matching types, key counts) */ public boolean areCompatible(Keys<?> other) throws IncompatibleKeysException { TypeInformation<?>[] thisKeyFieldTypes = this.getKeyFieldTypes(); TypeInformation<?>[] otherKeyFieldTypes = other.getKeyFieldTypes(); if (thisKeyFieldTypes.length != otherKeyFieldTypes.length) { throw new IncompatibleKeysException(IncompatibleKeysException.SIZE_MISMATCH_MESSAGE); } else { for (int i = 0; i < thisKeyFieldTypes.length; i++) { if (!thisKeyFieldTypes[i].equals(otherKeyFieldTypes[i])) { throw new IncompatibleKeysException(thisKeyFieldTypes[i], otherKeyFieldTypes[i] ); } } } return true; }
/** * Create an operator that produces the union of the two given data sets. * * @param input1 The first data set to be unioned. * @param input2 The second data set to be unioned. */ public UnionOperator(DataSet<T> input1, DataSet<T> input2, String unionLocationName) { super(input1, input2, input1.getType()); if (!input1.getType().equals(input2.getType())) { throw new InvalidProgramException("Cannot union inputs of different types. Input1=" + input1.getType() + ", input2=" + input2.getType()); } this.unionLocationName = unionLocationName; }
@Test public void testSerialization() { final T[] testData = getTestData(); for (T typeInfo : testData) { final byte[] serialized; try { serialized = InstantiationUtil.serializeObject(typeInfo); } catch (IOException e) { throw new AssertionError("Could not serialize type information: " + typeInfo, e); } final T deserialized; try { deserialized = InstantiationUtil.deserializeObject(serialized, getClass().getClassLoader()); } catch (IOException | ClassNotFoundException e) { throw new AssertionError("Could not deserialize type information: " + typeInfo, e); } if (typeInfo.hashCode() != deserialized.hashCode() || !typeInfo.equals(deserialized)) { throw new AssertionError("Deserialized type information differs from original one."); } } }
@Test public void testPojoWithComplexHierarchy() { TypeInformation<?> typeForClass = TypeExtractor.createTypeInfo(ComplexHierarchyTop.class); Assert.assertTrue(typeForClass instanceof PojoTypeInfo<?>); PojoTypeInfo<?> pojoTypeForClass = (PojoTypeInfo<?>) typeForClass; for(int i = 0; i < pojoTypeForClass.getArity(); i++) { PojoField field = pojoTypeForClass.getPojoFieldAt(i); String name = field.getField().getName(); if(name.equals("field1")) { Assert.assertTrue(field.getTypeInformation() instanceof PojoTypeInfo<?>); // From tuple is pojo (not tuple type!) } else if (name.equals("field2")) { Assert.assertTrue(field.getTypeInformation() instanceof TupleTypeInfo<?>); Assert.assertTrue( ((TupleTypeInfo<?>)field.getTypeInformation()).getTypeAt(0).equals(BasicTypeInfo.STRING_TYPE_INFO) ); } else if (name.equals("key")) { Assert.assertEquals(BasicTypeInfo.INT_TYPE_INFO, field.getTypeInformation()); } else { Assert.fail("Unexpected field "+field); } } }