Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id E60D0200CF8 for ; Thu, 14 Sep 2017 12:07:02 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id E4FDC1609CD; Thu, 14 Sep 2017 10:07:02 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 0FCB91609CC for ; Thu, 14 Sep 2017 12:07:01 +0200 (CEST) Received: (qmail 99503 invoked by uid 500); 14 Sep 2017 10:07:00 -0000 Mailing-List: contact user-help@flink.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Delivered-To: mailing list user@flink.apache.org Received: (qmail 99493 invoked by uid 99); 14 Sep 2017 10:06:59 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd2-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 14 Sep 2017 10:06:59 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd2-us-west.apache.org (ASF Mail Server at spamd2-us-west.apache.org) with ESMTP id 452E41A6540 for ; Thu, 14 Sep 2017 10:06:59 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd2-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 3.692 X-Spam-Level: *** X-Spam-Status: No, score=3.692 tagged_above=-999 required=6.31 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, HTML_MESSAGE=2, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, RCVD_IN_SORBS_SPAM=0.5, SPF_PASS=-0.001, URI_HEX=1.313] autolearn=disabled Authentication-Results: spamd2-us-west.apache.org (amavisd-new); dkim=pass (2048-bit key) header.d=gmail.com Received: from mx1-lw-us.apache.org ([10.40.0.8]) by localhost (spamd2-us-west.apache.org [10.40.0.9]) (amavisd-new, port 10024) with ESMTP id 9WUlSVzCMBtB for ; Thu, 14 Sep 2017 10:06:57 +0000 (UTC) Received: from mail-vk0-f49.google.com (mail-vk0-f49.google.com [209.85.213.49]) by mx1-lw-us.apache.org (ASF Mail Server at mx1-lw-us.apache.org) with ESMTPS id 7021F5FDBC for ; Thu, 14 Sep 2017 10:06:57 +0000 (UTC) Received: by mail-vk0-f49.google.com with SMTP id g69so505953vke.5 for ; Thu, 14 Sep 2017 03:06:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=irNAud4oGoXxcMIHMYcEQJ4RocqSuNU/pjiCoLAEGEo=; b=NwkH2Xxh3Vc1g9HC6ZRcEXdeRrvXnA4wFDo+CUZ4C650tdnq0syvbW9u4MuPvEGoGY 8a6z0B0/0WFiHk+HDgtM+MSgy14FGa61w/dPktqe1jRRvRpPfqWfOcj9AiVTMrUQVdt9 bSC0c2y7CzYBVDo3QkHUXQTBaT1XlFkITftCEyBqkFBwyLCzBjmIjiGuyyta9hJnwQNz ZZvIkSaHCFg1inC4qf8/Gerk52ZdpaUVY2jMv71O/OGTKQLjE6lsKNCtgWvaRggOFfLc vXiSq9MiqrJ+xVBNbb9Tp9Kuxvh9XNphYTOBATnddv6C/XjxpseQ+BbY9hrAzzRIWGt7 At9w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=irNAud4oGoXxcMIHMYcEQJ4RocqSuNU/pjiCoLAEGEo=; b=YaSwL5olRWcGOsu3g2tMgo9yLHLn4+qQ3uk536+vyf9a5b9GdvYWODCShvT93557I1 FC/GAh8mrkI+F0nw3KFNR7QCyfYYK5F0IhBcBRkoBNInreVkvUP/yqS/DRofdiarJDrO T2VJ6QwX9eIyFfhXjYmR7DPfYK0z+iPxv8PfdOsOUqkfFkYHDPfeH7sLVvwbt3rnWTdf AolEZ/NA+9SQ393Zuad+zfDLtj3oVvAJDJzhwTLDYbo4fOR3SL78Qc5WnEhtKFF9drEk QopYQ+REZGvSuiYM+vOM+T3w488GHLF67qlxKbHEX/9kYBLMt7b7zPu1xAd0CsyYc/0V 4x2w== X-Gm-Message-State: AHPjjUiVhajwZ2jp7hBKZzjy0moJfFQ99ZG3hELdqs83CXeZIc2CyCuH Gx8hefKuL8ShSNVRV5quVL0yiW2CkwLmSIojz2I= X-Google-Smtp-Source: AOwi7QDQbjqwdtdDdMwPoDjClOkfTeOfDTzQg79UUltip4YsX0q74s8Fg35gB+A4yUC2j0BmBpCtNzOn8FhiwYf4o4Y= X-Received: by 10.31.234.1 with SMTP id i1mr14095969vkh.192.1505383611151; Thu, 14 Sep 2017 03:06:51 -0700 (PDT) MIME-Version: 1.0 Received: by 10.103.56.209 with HTTP; Thu, 14 Sep 2017 03:06:20 -0700 (PDT) In-Reply-To: <1505126335488-0.post@n4.nabble.com> References: <1505126335488-0.post@n4.nabble.com> From: Fabian Hueske Date: Thu, 14 Sep 2017 12:06:20 +0200 Message-ID: Subject: Re: Keyed function type erasure problem. To: yunfan123 Cc: user Content-Type: multipart/alternative; boundary="94eb2c091ec064bed70559236fa8" archived-at: Thu, 14 Sep 2017 10:07:03 -0000 --94eb2c091ec064bed70559236fa8 Content-Type: text/plain; charset="UTF-8" Hi, The problem is that Flink cannot determine the key type produced by the KeySelector because the type is a generic. The type information is lost at runtime due to Java's type erasure. You can try to implement the ResultTypeQueryable interface with the KeySelector and tell Flink the key type directly. Best, Fabian 2017-09-11 12:38 GMT+02:00 yunfan123 : > Just small change from PojoExample: > PojoExample.java > n4.nabble.com/file/t921/PojoExample.java> > public class PojoExample { > private SelectorContainer selectorContainer; > // KeySelector class like this can't be used in flink !!! > public static class SelectorContainer implements > KeySelector { > public KeySelector keySelector; > public SelectorContainer(KeySelector > keySelector) { > this.keySelector = keySelector; > } > > @Override > public K getKey(Word value) throws Exception { > return keySelector.getKey(value); > } > } > public void run() { > dataStream.keyed(selectorContainer); > } > > } > > This will cause: > Type of TypeVariable 'K' in 'class > org.apache.flink.streaming.examples.wordcount. > PojoExample$SelectorContainer' > 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). > > org.apache.flink.api.java.typeutils.TypeExtractor. > createTypeInfoWithTypeHierarchy(TypeExtractor.java:915) > > org.apache.flink.api.java.typeutils.TypeExtractor.privateCreateTypeInfo( > TypeExtractor.java:836) > > org.apache.flink.api.java.typeutils.TypeExtractor. > getUnaryOperatorReturnType(TypeExtractor.java:622) > > org.apache.flink.api.java.typeutils.TypeExtractor.getKeySelectorTypes( > TypeExtractor.java:443) > > org.apache.flink.api.java.typeutils.TypeExtractor.getKeySelectorTypes( > TypeExtractor.java:436) > > org.apache.flink.streaming.api.datastream.KeyedStream.< > init>(KeyedStream.java:108) > > org.apache.flink.streaming.api.datastream.DataStream. > keyBy(DataStream.java:263) > > org.apache.flink.streaming.examples.wordcount.PojoExample.execute( > PojoExample.java:86) > > org.apache.flink.streaming.examples.wordcount. > PojoExample.main(PojoExample.java:108) > > It sames can't use a class contains the KeySelector ? > > > > -- > Sent from: http://apache-flink-user-mailing-list-archive.2336050. > n4.nabble.com/ > --94eb2c091ec064bed70559236fa8 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hi,

The problem is that F= link cannot determine the key type produced by the KeySelector because the = type is a generic.
The type information is lost at runtime due to= Java's type erasure.

You can try to implement = the ResultTypeQueryable interface with the KeySelector and tell Flink the k= ey type directly.

Best,
Fabian

2017-09-11 12:38 GMT+02:00 yun= fan123 <yunfanfighting@foxmail.com>:
Just small change from PojoExample:
PojoExample.java
<ht= tp://apache-flink-user-mailing-list-archive.2336050.n4.nabble.com= /file/t921/PojoExample.java>
public class PojoExample<KEY> {
=C2=A0 =C2=A0 =C2=A0 =C2=A0 private SelectorContainer<KEY> selectorCo= ntainer;
=C2=A0 =C2=A0 =C2=A0 =C2=A0 // KeySelector class like this can't be use= d in flink !!!
=C2=A0 =C2=A0 =C2=A0 =C2=A0 public static class SelectorContainer<K> = implements KeySelector<Word ,K> {
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 public KeySelector&= lt;Word, K> keySelector;
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 public SelectorCont= ainer(KeySelector<Word, K> keySelector) {
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 this.keySelector =3D keySelector;
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 }

=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 @Override
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 public K getKey(Wor= d value) throws Exception {
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 return keySelector.getKey(value);
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 }
=C2=A0 =C2=A0 =C2=A0 =C2=A0 }
=C2=A0 =C2=A0 =C2=A0 =C2=A0 public void run() {
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 dataStream.keyed(sele= ctorContainer);
=C2=A0 =C2=A0 =C2=A0 =C2=A0 }

}

This will cause:
Type of TypeVariable 'K' in 'class
org.apache.flink.streaming.examples.wordcount.PojoExample$Selecto= rContainer'
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<= br> type(s).

org.apache.flink.api.java.typeutils.TypeExtractor.createTypeInfoW= ithTypeHierarchy(TypeExtractor.java:915)

org.apache.flink.api.java.typeutils.TypeExtractor.privateCreateTy= peInfo(TypeExtractor.java:836)

org.apache.flink.api.java.typeutils.TypeExtractor.getUnaryOperato= rReturnType(TypeExtractor.java:622)

org.apache.flink.api.java.typeutils.TypeExtractor.getKeySelectorT= ypes(TypeExtractor.java:443)

org.apache.flink.api.java.typeutils.TypeExtractor.getKeySelectorT= ypes(TypeExtractor.java:436)

org.apache.flink.streaming.api.datastream.KeyedStream.<init>= ;(KeyedStream.java:108)

org.apache.flink.streaming.api.datastream.DataStream.keyBy(DataSt= ream.java:263)

org.apache.flink.streaming.examples.wordcount.PojoExample.execute= (PojoExample.java:86)

org.apache.flink.streaming.examples.wordcount.PojoExample.main(Po= joExample.java:108)

It sames can't use a class contains the KeySelector ?



--
Sent from: http://apache-flink-u= ser-mailing-list-archive.2336050.n4.nabble.com/

--94eb2c091ec064bed70559236fa8--