org.apache.flink.annotation.Internal Java Examples

The following examples show how to use org.apache.flink.annotation.Internal. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ReduceOperator.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Override
@Internal
public SingleInputSemanticProperties getSemanticProperties() {

	SingleInputSemanticProperties props = super.getSemanticProperties();

	// offset semantic information by extracted key fields
	if (props != null &&
			this.grouper != null &&
			this.grouper.keys instanceof SelectorFunctionKeys) {

		int offset = ((SelectorFunctionKeys<?, ?>) this.grouper.keys).getKeyType().getTotalFields();
		if (this.grouper instanceof SortedGrouping) {
			offset += ((SortedGrouping<?>) this.grouper).getSortSelectionFunctionKey().getKeyType().getTotalFields();
		}
		props = SemanticPropUtil.addSourceFieldOffset(props, this.getInputType().getTotalFields(), offset);
	}

	return props;
}
 
Example #2
Source File: ReduceOperator.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
@Internal
public SingleInputSemanticProperties getSemanticProperties() {

	SingleInputSemanticProperties props = super.getSemanticProperties();

	// offset semantic information by extracted key fields
	if (props != null &&
			this.grouper != null &&
			this.grouper.keys instanceof SelectorFunctionKeys) {

		int offset = ((SelectorFunctionKeys<?, ?>) this.grouper.keys).getKeyType().getTotalFields();
		if (this.grouper instanceof SortedGrouping) {
			offset += ((SortedGrouping<?>) this.grouper).getSortSelectionFunctionKey().getKeyType().getTotalFields();
		}
		props = SemanticPropUtil.addSourceFieldOffset(props, this.getInputType().getTotalFields(), offset);
	}

	return props;
}
 
Example #3
Source File: FunctionAnnotation.java    From flink with Apache License 2.0 6 votes vote down vote up
/**
 * Reads the annotations of a user defined function with one input and returns semantic properties according to the forwarded fields annotated.
 *
 * @param udfClass The user defined function, represented by its class.
 * @return	The DualInputSemanticProperties containing the forwarded fields.
 */
@Internal
public static Set<Annotation> readSingleForwardAnnotations(Class<?> udfClass) {
	ForwardedFields forwardedFields = udfClass.getAnnotation(ForwardedFields.class);
	NonForwardedFields nonForwardedFields = udfClass.getAnnotation(NonForwardedFields.class);
	ReadFields readSet = udfClass.getAnnotation(ReadFields.class);

	Set<Annotation> annotations = new HashSet<Annotation>();
	if (forwardedFields != null) {
		annotations.add(forwardedFields);
	}
	if (nonForwardedFields != null) {
		if (!annotations.isEmpty()) {
			throw new InvalidProgramException("Either " + ForwardedFields.class.getSimpleName() + " or " +
					NonForwardedFields.class.getSimpleName() + " can be annotated to a function, not both.");
		}
		annotations.add(nonForwardedFields);
	}
	if (readSet != null) {
		annotations.add(readSet);
	}

	return !annotations.isEmpty() ? annotations : null;
}
 
Example #4
Source File: GroupCombineOperator.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Override
@Internal
public SingleInputSemanticProperties getSemanticProperties() {

	SingleInputSemanticProperties props = super.getSemanticProperties();

	// offset semantic information by extracted key fields
	if (props != null &&
			this.grouper != null &&
			this.grouper.keys instanceof SelectorFunctionKeys) {

		int offset = ((SelectorFunctionKeys<?, ?>) this.grouper.keys).getKeyType().getTotalFields();
		if (this.grouper instanceof SortedGrouping) {
			offset += ((SortedGrouping<?>) this.grouper).getSortSelectionFunctionKey().getKeyType().getTotalFields();
		}

		props = SemanticPropUtil.addSourceFieldOffset(props, this.getInputType().getTotalFields(), offset);
	}

	return props;
}
 
Example #5
Source File: FunctionAnnotation.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
/**
 * Reads the annotations of a user defined function with one input and returns semantic properties according to the forwarded fields annotated.
 *
 * @param udfClass The user defined function, represented by its class.
 * @return	The DualInputSemanticProperties containing the forwarded fields.
 */
@Internal
public static Set<Annotation> readSingleForwardAnnotations(Class<?> udfClass) {
	ForwardedFields forwardedFields = udfClass.getAnnotation(ForwardedFields.class);
	NonForwardedFields nonForwardedFields = udfClass.getAnnotation(NonForwardedFields.class);
	ReadFields readSet = udfClass.getAnnotation(ReadFields.class);

	Set<Annotation> annotations = new HashSet<Annotation>();
	if (forwardedFields != null) {
		annotations.add(forwardedFields);
	}
	if (nonForwardedFields != null) {
		if (!annotations.isEmpty()) {
			throw new InvalidProgramException("Either " + ForwardedFields.class.getSimpleName() + " or " +
					NonForwardedFields.class.getSimpleName() + " can be annotated to a function, not both.");
		}
		annotations.add(nonForwardedFields);
	}
	if (readSet != null) {
		annotations.add(readSet);
	}

	return !annotations.isEmpty() ? annotations : null;
}
 
Example #6
Source File: GroupReduceOperator.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Override
@Internal
public SingleInputSemanticProperties getSemanticProperties() {

	SingleInputSemanticProperties props = super.getSemanticProperties();

	// offset semantic information by extracted key fields
	if (props != null &&
			this.grouper != null &&
			this.grouper.keys instanceof SelectorFunctionKeys) {

		int offset = ((SelectorFunctionKeys<?, ?>) this.grouper.keys).getKeyType().getTotalFields();
		if (this.grouper instanceof SortedGrouping) {
			offset += ((SortedGrouping<?>) this.grouper).getSortSelectionFunctionKey().getKeyType().getTotalFields();
		}
		props = SemanticPropUtil.addSourceFieldOffset(props, this.getInputType().getTotalFields(), offset);
	}

	return props;
}
 
Example #7
Source File: TypeExtractor.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the type information factory for a type using the factory registry or annotations.
 */
@Internal
public static <OUT> TypeInfoFactory<OUT> getTypeInfoFactory(Type t) {
	final Class<?> factoryClass;
	if (registeredTypeInfoFactories.containsKey(t)) {
		factoryClass = registeredTypeInfoFactories.get(t);
	}
	else {
		if (!isClassType(t) || !typeToClass(t).isAnnotationPresent(TypeInfo.class)) {
			return null;
		}
		final TypeInfo typeInfoAnnotation = typeToClass(t).getAnnotation(TypeInfo.class);
		factoryClass = typeInfoAnnotation.value();
		// check for valid factory class
		if (!TypeInfoFactory.class.isAssignableFrom(factoryClass)) {
			throw new InvalidTypesException("TypeInfo annotation does not specify a valid TypeInfoFactory.");
		}
	}

	// instantiate
	return (TypeInfoFactory<OUT>) InstantiationUtil.instantiate(factoryClass);
}
 
Example #8
Source File: TypeExtractor.java    From flink with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the type information factory for a type using the factory registry or annotations.
 */
@Internal
public static <OUT> TypeInfoFactory<OUT> getTypeInfoFactory(Type t) {
	final Class<?> factoryClass;
	if (registeredTypeInfoFactories.containsKey(t)) {
		factoryClass = registeredTypeInfoFactories.get(t);
	}
	else {
		if (!isClassType(t) || !typeToClass(t).isAnnotationPresent(TypeInfo.class)) {
			return null;
		}
		final TypeInfo typeInfoAnnotation = typeToClass(t).getAnnotation(TypeInfo.class);
		factoryClass = typeInfoAnnotation.value();
		// check for valid factory class
		if (!TypeInfoFactory.class.isAssignableFrom(factoryClass)) {
			throw new InvalidTypesException("TypeInfo annotation does not specify a valid TypeInfoFactory.");
		}
	}

	// instantiate
	return (TypeInfoFactory<OUT>) InstantiationUtil.instantiate(factoryClass);
}
 
Example #9
Source File: EnvironmentSettings.java    From flink with Apache License 2.0 5 votes vote down vote up
@Internal
public Map<String, String> toExecutorProperties() {
	Map<String, String> properties = new HashMap<>(toCommonProperties());
	if (executorClass != null) {
		properties.put(CLASS_NAME, executorClass);
	}
	return properties;
}
 
Example #10
Source File: SingleInputUdfOperator.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Override
@Internal
public SingleInputSemanticProperties getSemanticProperties() {
	if (this.udfSemantics == null || analyzedUdfSemantics) {
		SingleInputSemanticProperties props = extractSemanticAnnotations(getFunction().getClass());
		if (props != null) {
			setSemanticProperties(props);
		}
	}
	if (this.udfSemantics == null) {
		setSemanticProperties(new SingleInputSemanticProperties());
	}
	return this.udfSemantics;
}
 
Example #11
Source File: SingleInputUdfOperator.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
@Internal
public Map<String, DataSet<?>> getBroadcastSets() {
	return this.broadcastVariables == null ?
			Collections.<String, DataSet<?>>emptyMap() :
			Collections.unmodifiableMap(this.broadcastVariables);
}
 
Example #12
Source File: TwoInputUdfOperator.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Override
@Internal
public Map<String, DataSet<?>> getBroadcastSets() {
	return this.broadcastVariables == null ?
			Collections.<String, DataSet<?>>emptyMap() :
			Collections.unmodifiableMap(this.broadcastVariables);
}
 
Example #13
Source File: AvroSerializer.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new AvroSerializer for the type indicated by the given class.
 */
@Internal
AvroSerializer(Class<T> type, SerializableAvroSchema newSchema, SerializableAvroSchema previousSchema) {
	this.type = checkNotNull(type);
	this.schema = checkNotNull(newSchema);
	this.previousSchema = checkNotNull(previousSchema);
}
 
Example #14
Source File: FileSystemSafetyNet.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
/**
 * Closes the safety net for a thread. This closes all remaining unclosed streams that were opened
 * by safety-net-guarded file systems. After this method was called, no streams can be opened any more
 * from any FileSystem instance that was obtained while the thread was guarded by the safety net.
 *
 * <p>This method should be called at the very end of a guarded thread.
 */
@Internal
public static void closeSafetyNetAndGuardedResourcesForThread() {
	SafetyNetCloseableRegistry registry = REGISTRIES.get();
	if (null != registry) {
		REGISTRIES.remove();
		IOUtils.closeQuietly(registry);
	}
}
 
Example #15
Source File: TwoInputUdfOperator.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
@Internal
public DualInputSemanticProperties getSemanticProperties() {
	if (this.udfSemantics == null || analyzedUdfSemantics) {
		DualInputSemanticProperties props = extractSemanticAnnotationsFromUdf(getFunction().getClass());
		if (props != null) {
			setSemanticProperties(props);
		}
	}
	if (this.udfSemantics == null) {
		setSemanticProperties(new DualInputSemanticProperties());
	}
	return this.udfSemantics;
}
 
Example #16
Source File: FileSystemSafetyNet.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * Closes the safety net for a thread. This closes all remaining unclosed streams that were opened
 * by safety-net-guarded file systems. After this method was called, no streams can be opened any more
 * from any FileSystem instance that was obtained while the thread was guarded by the safety net.
 *
 * <p>This method should be called at the very end of a guarded thread.
 */
@Internal
public static void closeSafetyNetAndGuardedResourcesForThread() {
	SafetyNetCloseableRegistry registry = REGISTRIES.get();
	if (null != registry) {
		REGISTRIES.remove();
		IOUtils.closeQuietly(registry);
	}
}
 
Example #17
Source File: StreamExecutionEnvironment.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
/**
 * Getter of the {@link org.apache.flink.streaming.api.graph.StreamGraph} of the streaming job.
 *
 * @return The streamgraph representing the transformations
 */
@Internal
public StreamGraph getStreamGraph() {
	if (transformations.size() <= 0) {
		throw new IllegalStateException("No operators defined in streaming topology. Cannot execute.");
	}
	return StreamGraphGenerator.generate(this, transformations);
}
 
Example #18
Source File: StreamExecutionEnvironment.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a "closure-cleaned" version of the given function. Cleans only if closure cleaning
 * is not disabled in the {@link org.apache.flink.api.common.ExecutionConfig}
 */
@Internal
public <F> F clean(F f) {
	if (getConfig().isClosureCleanerEnabled()) {
		ClosureCleaner.clean(f, getConfig().getClosureCleanerLevel(), true);
	}
	ClosureCleaner.ensureSerializable(f);
	return f;
}
 
Example #19
Source File: ZonedTimestampType.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * Internal constructor that allows attaching additional metadata about time attribute
 * properties. The additional metadata does not affect equality or serializability.
 *
 * <p>Use {@link #getKind()} for comparing this metadata.
 */
@Internal
public ZonedTimestampType(boolean isNullable, TimestampKind kind, int precision) {
	super(isNullable, LogicalTypeRoot.TIMESTAMP_WITH_TIME_ZONE);
	if (precision < MIN_PRECISION || precision > MAX_PRECISION) {
		throw new ValidationException(
			String.format(
				"Timestamp with time zone precision must be between %d and %d (both inclusive).",
				MIN_PRECISION,
				MAX_PRECISION));
	}
	this.kind = kind;
	this.precision = precision;
}
 
Example #20
Source File: LocalZonedTimestampType.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * Internal constructor that allows attaching additional metadata about time attribute
 * properties. The additional metadata does not affect equality or serializability.
 *
 * <p>Use {@link #getKind()} for comparing this metadata.
 */
@Internal
public LocalZonedTimestampType(boolean isNullable, TimestampKind kind, int precision) {
	super(isNullable, LogicalTypeRoot.TIMESTAMP_WITH_LOCAL_TIME_ZONE);
	if (precision < MIN_PRECISION || precision > MAX_PRECISION) {
		throw new ValidationException(
			String.format(
				"Timestamp with local time zone precision must be between %d and %d (both inclusive).",
				MIN_PRECISION,
				MAX_PRECISION));
	}
	this.kind = kind;
	this.precision = precision;
}
 
Example #21
Source File: FileSystemSafetyNet.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
/**
 * Activates the safety net for a thread. {@link FileSystem} instances obtained by the thread
 * that called this method will be guarded, meaning that their created streams are tracked and can
 * be closed via the safety net closing hook.
 *
 * <p>This method should be called at the beginning of a thread that should be guarded.
 *
 * @throws IllegalStateException Thrown, if a safety net was already registered for the thread.
 */
@Internal
public static void initializeSafetyNetForThread() {
	SafetyNetCloseableRegistry oldRegistry = REGISTRIES.get();

	checkState(null == oldRegistry, "Found an existing FileSystem safety net for this thread: %s " +
			"This may indicate an accidental repeated initialization, or a leak of the" +
			"(Inheritable)ThreadLocal through a ThreadPool.", oldRegistry);

	SafetyNetCloseableRegistry newRegistry = new SafetyNetCloseableRegistry();
	REGISTRIES.set(newRegistry);
}
 
Example #22
Source File: EnvironmentSettings.java    From flink with Apache License 2.0 5 votes vote down vote up
@Internal
public Map<String, String> toPlannerProperties() {
	Map<String, String> properties = new HashMap<>(toCommonProperties());
	if (plannerClass != null) {
		properties.put(CLASS_NAME, plannerClass);
	}
	return properties;
}
 
Example #23
Source File: AvroSerializer.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new AvroSerializer for the type indicated by the given class.
 */
@Internal
AvroSerializer(Class<T> type, SerializableAvroSchema newSchema, SerializableAvroSchema previousSchema) {
	this.type = checkNotNull(type);
	this.schema = checkNotNull(newSchema);
	this.previousSchema = checkNotNull(previousSchema);
}
 
Example #24
Source File: ConnectedStreams.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
/**
 * Applies the given {@link CoProcessFunction} on the connected input streams,
 * thereby creating a transformed output stream.
 *
 * <p>The function will be called for every element in the input streams and can produce zero
 * or more output elements. Contrary to the {@link #flatMap(CoFlatMapFunction)} function,
 * this function can also query the time and set timers. When reacting to the firing of set
 * timers the function can directly emit elements and/or register yet more timers.
 *
 * @param coProcessFunction The {@link CoProcessFunction} that is called for each element
 *                      in the stream.
 *
 * @param <R> The type of elements emitted by the {@code CoProcessFunction}.
 *
 * @return The transformed {@link DataStream}.
 */
@Internal
public <R> SingleOutputStreamOperator<R> process(
		CoProcessFunction<IN1, IN2, R> coProcessFunction,
		TypeInformation<R> outputType) {

	TwoInputStreamOperator<IN1, IN2, R> operator;

	if ((inputStream1 instanceof KeyedStream) && (inputStream2 instanceof KeyedStream)) {
		operator = new KeyedCoProcessOperator<>(inputStream1.clean(coProcessFunction));
	} else {
		operator = new CoProcessOperator<>(inputStream1.clean(coProcessFunction));
	}

	return transform("Co-Process", outputType, operator);
}
 
Example #25
Source File: TypeSerializerConfigSnapshot.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
/**
 * Set the originating serializer of this configuration snapshot.
 */
@Internal
public final void setPriorSerializer(TypeSerializer<T> serializer) {
	this.serializer = Preconditions.checkNotNull(serializer);
}
 
Example #26
Source File: ExecutionConfig.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@Internal
public boolean isLatencyTrackingConfigured() {
	return isLatencyTrackingConfigured;
}
 
Example #27
Source File: CoGroupOperator.java    From flink with Apache License 2.0 4 votes vote down vote up
@Internal
protected Keys<I2> getKeys2() {
	return this.keys2;
}
 
Example #28
Source File: FunctionAnnotation.java    From flink with Apache License 2.0 4 votes vote down vote up
/**
 * Reads the annotations of a user defined function with two inputs and returns semantic properties according to the forwarded fields annotated.
 * @param udfClass The user defined function, represented by its class.
 * @return	The DualInputSemanticProperties containing the forwarded fields.
 */
@Internal
public static Set<Annotation> readDualForwardAnnotations(Class<?> udfClass) {

	// get readSet annotation from stub
	ForwardedFieldsFirst forwardedFields1 = udfClass.getAnnotation(ForwardedFieldsFirst.class);
	ForwardedFieldsSecond forwardedFields2 = udfClass.getAnnotation(ForwardedFieldsSecond.class);

	// get readSet annotation from stub
	NonForwardedFieldsFirst nonForwardedFields1 = udfClass.getAnnotation(NonForwardedFieldsFirst.class);
	NonForwardedFieldsSecond nonForwardedFields2 = udfClass.getAnnotation(NonForwardedFieldsSecond.class);

	ReadFieldsFirst readSet1 = udfClass.getAnnotation(ReadFieldsFirst.class);
	ReadFieldsSecond readSet2 = udfClass.getAnnotation(ReadFieldsSecond.class);

	Set<Annotation> annotations = new HashSet<Annotation>();

	if (nonForwardedFields1 != null && forwardedFields1 != null) {
		throw new InvalidProgramException("Either " + ForwardedFieldsFirst.class.getSimpleName() + " or " +
				NonForwardedFieldsFirst.class.getSimpleName() + " can be annotated to a function, not both.");
	} else if (forwardedFields1 != null) {
		annotations.add(forwardedFields1);
	} else if (nonForwardedFields1 != null) {
		annotations.add(nonForwardedFields1);
	}

	if (forwardedFields2 != null && nonForwardedFields2 != null) {
		throw new InvalidProgramException("Either " + ForwardedFieldsSecond.class.getSimpleName() + " or " +
				NonForwardedFieldsSecond.class.getSimpleName() + " can be annotated to a function, not both.");
	} else if (forwardedFields2 != null) {
		annotations.add(forwardedFields2);
	} else if (nonForwardedFields2 != null) {
		annotations.add(nonForwardedFields2);
	}

	if (readSet1 != null) {
		annotations.add(readSet1);
	}
	if (readSet2 != null) {
		annotations.add(readSet2);
	}

	return !annotations.isEmpty() ? annotations : null;
}
 
Example #29
Source File: StateDescriptor.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@Nonnull
@Internal
public StateTtlConfig getTtlConfig() {
	return ttlConfig;
}
 
Example #30
Source File: NestedSerializersSnapshotDelegate.java    From flink with Apache License 2.0 4 votes vote down vote up
/**
 * Constructor to create a snapshot during deserialization.
 */
@Internal
NestedSerializersSnapshotDelegate(TypeSerializerSnapshot<?>[] snapshots) {
	this.nestedSnapshots = checkNotNull(snapshots);
}