You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@flink.apache.org by Federico D'Ambrosio <fe...@smartlab.ws> on 2017/09/14 13:51:23 UTC

Dot notation not working for accessing case classes nested fields

Hi,

I have the following case classes:

case class Event(instantValues: InstantValues)
case class InstantValues(speed: Int, altitude: Int, time: DateTime)


in a DataStream[Event] I'd like to perform a maxBy operation on the field
time of instantValue for each event and according to the docs here
<https://ci.apache.org/projects/flink/flink-docs-release-1.3/api/java/org/apache/flink/streaming/api/datastream/KeyedStream.html#maxBy-int->it
would be possible to use the dot notation such the following:

val events = stream
  .keyBy("otherField")
  .window(TumblingEventTimeWindows.of(Time.seconds(5)))
  .maxBy("instantValues.time")

positionToMaxBy - In case of a POJO, Scala case class, or Tuple type, the
name of the public) field on which to perform the aggregation.
Additionally, a dot can be used to drill down into nested objects, as
in "field1.fieldxy"
. Furthermore "*" can be specified in case of a basic type (which is
considered as having only one field).


Still, I'm getting the following error:

Fields 'instantValues.time' are not valid for 'package.Event(instantValues:
package.InstantValues(speed: Integer, altitude: Integer, time:
GenericType<org.joda.time.DateTime>))'

whereas if, for instance, use only "instantValues" (while implementing its
compareTo method) the aggregation works as usual.

Any idea as to why this isn't working? Am I doing something wrong?

Thanks a lot,
Federico

Re: Dot notation not working for accessing case classes nested fields

Posted by Federico D'Ambrosio <fe...@smartlab.ws>.
Great, thanks!

The fact that it's actually written on the documentation is really
misleading.

Thank you very much for your response

Federico D'Ambrosio

Il 15 set 2017 13:26, "Gábor Gévay" <gg...@gmail.com> ha scritto:

> Hi Federico,
>
> Sorry, nested field expressions are not supported in these methods at
> the moment. I have created a JIRA issue for this:
> https://issues.apache.org/jira/browse/FLINK-7629
> I think this should be easy to fix, as all the infrastructure for
> supporting this is already in place. I'll try to do it over the
> weekend.
>
> Best,
> Gábor
>
>
>
>
> On Thu, Sep 14, 2017 at 3:51 PM, Federico D'Ambrosio
> <fe...@smartlab.ws> wrote:
> > Hi,
> >
> > I have the following case classes:
> >
> > case class Event(instantValues: InstantValues)
> > case class InstantValues(speed: Int, altitude: Int, time: DateTime)
> >
> >
> > in a DataStream[Event] I'd like to perform a maxBy operation on the field
> > time of instantValue for each event and according to the docs here it
> would
> > be possible to use the dot notation such the following:
> >
> > val events = stream
> >   .keyBy("otherField")
> >   .window(TumblingEventTimeWindows.of(Time.seconds(5)))
> >   .maxBy("instantValues.time")
> >
> > positionToMaxBy - In case of a POJO, Scala case class, or Tuple type, the
> > name of the public) field on which to perform the aggregation.
> Additionally,
> > a dot can be used to drill down into nested objects, as in
> "field1.fieldxy"
> > . Furthermore "*" can be specified in case of a basic type (which is
> > considered as having only one field).
> >
> >
> > Still, I'm getting the following error:
> >
> > Fields 'instantValues.time' are not valid for
> 'package.Event(instantValues:
> > package.InstantValues(speed: Integer, altitude: Integer, time:
> > GenericType<org.joda.time.DateTime>))'
> >
> > whereas if, for instance, use only "instantValues" (while implementing
> its
> > compareTo method) the aggregation works as usual.
> >
> > Any idea as to why this isn't working? Am I doing something wrong?
> >
> > Thanks a lot,
> > Federico
>

Re: Dot notation not working for accessing case classes nested fields

Posted by Gábor Gévay <gg...@gmail.com>.
Hi Federico,

Sorry, nested field expressions are not supported in these methods at
the moment. I have created a JIRA issue for this:
https://issues.apache.org/jira/browse/FLINK-7629
I think this should be easy to fix, as all the infrastructure for
supporting this is already in place. I'll try to do it over the
weekend.

Best,
Gábor




On Thu, Sep 14, 2017 at 3:51 PM, Federico D'Ambrosio
<fe...@smartlab.ws> wrote:
> Hi,
>
> I have the following case classes:
>
> case class Event(instantValues: InstantValues)
> case class InstantValues(speed: Int, altitude: Int, time: DateTime)
>
>
> in a DataStream[Event] I'd like to perform a maxBy operation on the field
> time of instantValue for each event and according to the docs here it would
> be possible to use the dot notation such the following:
>
> val events = stream
>   .keyBy("otherField")
>   .window(TumblingEventTimeWindows.of(Time.seconds(5)))
>   .maxBy("instantValues.time")
>
> positionToMaxBy - In case of a POJO, Scala case class, or Tuple type, the
> name of the public) field on which to perform the aggregation. Additionally,
> a dot can be used to drill down into nested objects, as in "field1.fieldxy"
> . Furthermore "*" can be specified in case of a basic type (which is
> considered as having only one field).
>
>
> Still, I'm getting the following error:
>
> Fields 'instantValues.time' are not valid for 'package.Event(instantValues:
> package.InstantValues(speed: Integer, altitude: Integer, time:
> GenericType<org.joda.time.DateTime>))'
>
> whereas if, for instance, use only "instantValues" (while implementing its
> compareTo method) the aggregation works as usual.
>
> Any idea as to why this isn't working? Am I doing something wrong?
>
> Thanks a lot,
> Federico