[
https://issues.apache.org/jira/browse/FLINK-3444?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15227979#comment-15227979
]
ASF GitHub Bot commented on FLINK-3444:
---------------------------------------
Github user zentol commented on a diff in the pull request:
https://github.com/apache/flink/pull/1857#discussion_r58673148
--- Diff:
flink-streaming-java/src/main/java/org/apache/flink/streaming/api/environment/StreamExecutionEnvironment.java
---
@@ -673,6 +673,43 @@ public TimeCharacteristic
getStreamTimeCharacteristic() {
}
/**
+ * Creates a new data stream that contains the given elements. The
elements must all be of the same type, for
+ * example, all of the {@link String} or {@link Integer}.
+ * <p>
+ * The framework will try and determine the exact type from the
elements. In case of generic elements, it may be
+ * necessary to manually supply the type information via {@link
#fromCollection(java.util.Collection,
+ * org.apache.flink.api.common.typeinfo.TypeInformation)}.
+ * <p>
+ * Note that this operation will result in a non-parallel data stream
source, i.e. a data stream source with a
+ * degree of parallelism one.
+ *
+ * @param clazz
+ * The base class type in the collection.
+ * @param data
+ * The array of elements to create the data stream from.
+ * @param <OUT>
+ * The type of the returned data stream
+ * @return The data stream representing the given array of elements
+ */
+ @SafeVarargs
+ public final <OUT> DataStreamSource<OUT> fromElements(Class<OUT> clazz,
OUT... data) {
+ if (data.length == 0) {
+ throw new IllegalArgumentException("fromElements needs
at least one element as argument");
+ }
+
+ TypeInformation<OUT> typeInfo;
+ try {
+ typeInfo = TypeExtractor.getForClass(clazz);
+ }
+ catch (Exception e) {
+ throw new RuntimeException("Could not create
TypeInformation for type " + data[0].getClass().getName()
--- End diff --
shouldn't this exception contain clazz.getName() instead?
> env.fromElements relies on the first input element for determining the
> DataSet/DataStream type
> ----------------------------------------------------------------------------------------------
>
> Key: FLINK-3444
> URL: https://issues.apache.org/jira/browse/FLINK-3444
> Project: Flink
> Issue Type: Bug
> Components: DataSet API, DataStream API
> Affects Versions: 0.10.0, 1.0.0
> Reporter: Vasia Kalavri
>
> The {{fromElements}} method of the {{ExecutionEnvironment}} and
> {{StreamExecutionEnvironment}} determines the DataSet/DataStream type by
> extracting the type of the first input element.
> This is problematic if the first element is a subtype of another element in
> the collection.
> For example, the following
> {code}
> DataStream<Event> input = env.fromElements(new Event(1, "a"), new SubEvent(2,
> "b"));
> {code}
> succeeds, while the following
> {code}
> DataStream<Event> input = env.fromElements(new SubEvent(1, "a"), new Event(2,
> "b"));
> {code}
> fails with "java.lang.IllegalArgumentException: The elements in the
> collection are not all subclasses of SubEvent".
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)