Return-Path: X-Original-To: apmail-apex-dev-archive@minotaur.apache.org Delivered-To: apmail-apex-dev-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 0920318450 for ; Fri, 22 Jan 2016 13:35:24 +0000 (UTC) Received: (qmail 11439 invoked by uid 500); 22 Jan 2016 13:35:23 -0000 Delivered-To: apmail-apex-dev-archive@apex.apache.org Received: (qmail 11374 invoked by uid 500); 22 Jan 2016 13:35:23 -0000 Mailing-List: contact dev-help@apex.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@apex.incubator.apache.org Delivered-To: mailing list dev@apex.incubator.apache.org Received: (qmail 11357 invoked by uid 99); 22 Jan 2016 13:35:23 -0000 Received: from Unknown (HELO spamd2-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 22 Jan 2016 13:35:23 +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 E658B1A0887 for ; Fri, 22 Jan 2016 13:35:22 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd2-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 3 X-Spam-Level: *** X-Spam-Status: No, score=3 tagged_above=-999 required=6.31 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, HTML_MESSAGE=3, SPF_PASS=-0.001, URIBL_BLOCKED=0.001] autolearn=disabled Authentication-Results: spamd2-us-west.apache.org (amavisd-new); dkim=pass (2048-bit key) header.d=datatorrent-com.20150623.gappssmtp.com Received: from mx1-us-east.apache.org ([10.40.0.8]) by localhost (spamd2-us-west.apache.org [10.40.0.9]) (amavisd-new, port 10024) with ESMTP id iwLagKA98amm for ; Fri, 22 Jan 2016 13:35:12 +0000 (UTC) Received: from mail-ob0-f181.google.com (mail-ob0-f181.google.com [209.85.214.181]) by mx1-us-east.apache.org (ASF Mail Server at mx1-us-east.apache.org) with ESMTPS id 8661243F5A for ; Fri, 22 Jan 2016 13:35:12 +0000 (UTC) Received: by mail-ob0-f181.google.com with SMTP id is5so62453385obc.0 for ; Fri, 22 Jan 2016 05:35:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=datatorrent-com.20150623.gappssmtp.com; s=20150623; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=MC2bv2lwyUfSvq7U8NPODRLR2+7BerOPjMXbt/98kkg=; b=1Liviks4JBfSI2biiycnEcdtFOKhwm5roPT7JnGW4sHHWDdULs7fU6uixueAwXI5jW g0xKNxMYhW7EYOTWN67QZ0FvEMeliqawLT4HKjj3X+3S3V6aylvn3N5/MhlbrMI31+0Z 67Uz/AtkqaHN9udMkA16Mn27dOJ8CsMiZa1s3VI77NmPr6ZX6QWnXxRMbbNHbplwCYLx ypeGI4eOiNKOz9Hq2LEFvjcL+m5CWg0vpBrDS40r3gmD0AHhAAY+nTK8KqGFkyCmZbgi ou94uvQbEH/aXpkWC5+RL4aSxQ7sUkug3fVX21rXBhISbJWdmw5bTlF5Pm0r5ZgoCZZn XilA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:content-type; bh=MC2bv2lwyUfSvq7U8NPODRLR2+7BerOPjMXbt/98kkg=; b=Ac+g3GGzZj2xqTQS4pxkuGTNRQgy6+kR7ftLUaSkO8d8UrjOEsJ8HGQHK7o6fEJ1+c glqVnGZpVN9oxaeUIBuKb2Tds/AVdf+wqhj1ZZ9I5lxtL25E2OUT9pC0MW44GJcf9JQH /1Q9YjZWeKzlE8ai0JPQByXrC1rEeIar2mzcf52aG11bPf/dCTQYWxZfZy175vgKD7Qw L6B/mQMi1/g6rRSlgFZQP0T1yIctK5DM/K/+2nWmRoZMHVE0wtOU72lZmDCFbY15sgfH 0Ogp0krUKBFkhVS0PDNlAIdJAw05B8ZvYm1rWy63N56Ss5DNzFULHuwM50zMaJq20zS2 Yveg== X-Gm-Message-State: AG10YORSfRYd7SKw0FlP+bPmEbToOXCAIs5GVuZr0cNF5xCGUK7kWeFZFiqXg+nLzqLV2fSAEFba1Ph+zV2W6Goz X-Received: by 10.182.18.8 with SMTP id s8mr2454106obd.43.1453469712100; Fri, 22 Jan 2016 05:35:12 -0800 (PST) MIME-Version: 1.0 Received: by 10.182.81.228 with HTTP; Fri, 22 Jan 2016 05:34:52 -0800 (PST) In-Reply-To: References: From: Bhupesh Chawda Date: Fri, 22 Jan 2016 19:04:52 +0530 Message-ID: Subject: Re: Ability to generate POJO class on the fly To: dev@apex.incubator.apache.org Content-Type: multipart/alternative; boundary=001a11c2d2e6e1c8b10529ec4976 --001a11c2d2e6e1c8b10529ec4976 Content-Type: text/plain; charset=UTF-8 Yes. So in the JDBC output case, a json object could be readily constructed by the operator to get a POJO class rather than playing around with JSON syntax. On Fri, Jan 22, 2016 at 6:54 PM, Chinmay Kolhatkar wrote: > @bhupesh, would it help if JSONObject is taken as input to this utility > rather than json string? > > Thanks, > Chinmay > On 22 Jan 2016 18:45, "Chinmay Kolhatkar" wrote: > > > Got it. I think approach 2 is still possible with json based schema. > > So basically, the operator can create json schema as mention in first > mail > > based on column name and type. Then pass that json schema to this utility > > to get class to be used directly. > > > > Thanks, > > Chinmay. > > On 22 Jan 2016 18:38, "Priyanka Gugale" > wrote: > > > >> Say I need to emit pojo from JDBCInputOperator. I will use on fly POJO > >> generator for this purpose instead of providing predefined class. > >> Now to generate POJO on fly there are two options: > >> 1. Get json as config from user as you specified. > >> 2. Based on column name and type generate pojo fields and hence pojo > class > >> without much of user configuration. (I am only considering one level > here, > >> not the nested pojo) > >> > >> Option 1 is must have to provide user a way to control how we generate > >> pojo. But option 2 is useful when user simply want to put column values > in > >> some object. > >> > >> -Priyanka > >> > >> On Fri, Jan 22, 2016 at 6:30 PM, Chinmay Kolhatkar < > >> chinmay@datatorrent.com> > >> wrote: > >> > >> > Hi Priyanka, > >> > > >> > Can you give an example? > >> > > >> > Thanks, > >> > Chinmay. > >> > > >> > ~ Chinmay > >> > On 22 Jan 2016 18:14, "Priyanka Gugale" > >> wrote: > >> > > >> > > We do need configuration in some form like json, but I was thinking > we > >> > can > >> > > have default wherever possible. This is an option and not > replacement > >> to > >> > > json config. > >> > > > >> > > -Priyanka > >> > > > >> > > On Fri, Jan 22, 2016 at 4:34 PM, Chinmay Kolhatkar < > >> > > chinmay@datatorrent.com> > >> > > wrote: > >> > > > >> > > > @priyanka > >> > > > > >> > > > Advantage with JSON schema is that one can represent nested POJO > >> > > definition > >> > > > in that. If you're referring to FieldInfo, I'm not sure if that is > >> > > possible > >> > > > there. > >> > > > > >> > > > Even if we chose not to have nested POJO now, I think JSON schema > >> input > >> > > to > >> > > > this utility gives more chance to expand easily later. > >> > > > > >> > > > > >> > > > > >> > > > On Fri, Jan 22, 2016 at 3:30 PM, Chinmay Kolhatkar < > >> > > > chinmay@datatorrent.com> > >> > > > wrote: > >> > > > > >> > > > > Sure. We can make this utility to provide byte[] for compiled > >> class. > >> > > > > Though the utility will give a OutputStream object.. One can get > >> > byte[] > >> > > > > out of that. > >> > > > > > >> > > > > On Fri, Jan 22, 2016 at 2:56 PM, Timothy Farkas < > >> tim@datatorrent.com > >> > > > >> > > > > wrote: > >> > > > > > >> > > > >> Suggestion: +1 for automatic generation of schema. The user > >> should > >> > be > >> > > > able > >> > > > >> to override the a manually specified schema though. > >> > > > >> > >> > > > >> Question: If the mechanism used to generate the class can > >> produce a > >> > > > byte[] > >> > > > >> array, then you can send the byte[] array for the class to > >> > downstream > >> > > > >> operators and load the class from the byte[] array in each > >> operator. > >> > > An > >> > > > >> example of how to do this is here: > >> > > > >> > >> > > > >> > >> > > > >> > >> > > > > >> > > > >> > > >> > http://stackoverflow.com/questions/1781091/java-how-to-load-class-stored-as-byte-into-the-jvm > >> > > > >> > >> > > > >> Thanks, > >> > > > >> Tim > >> > > > >> > >> > > > >> On Fri, Jan 22, 2016 at 12:59 AM, Priyanka Gugale < > >> > > > >> priyanka@datatorrent.com> > >> > > > >> wrote: > >> > > > >> > >> > > > >> > Hi, > >> > > > >> > > >> > > > >> > Suggestion: > >> > > > >> > This came up with one of the discussion with Pramod, will it > >> be a > >> > > good > >> > > > >> > idea, for database input operators to generate pojo based on > >> the > >> > > > >> selected > >> > > > >> > column field names and types? No need to accept json input > from > >> > > user. > >> > > > >> > > >> > > > >> > Question: > >> > > > >> > How can we share this POJO among multiple operators when > >> > application > >> > > > is > >> > > > >> > already launched and class is generated on the fly? > >> > > > >> > > >> > > > >> > -Priyanka > >> > > > >> > > >> > > > >> > On Thu, Jan 21, 2016 at 11:16 PM, Chinmay Kolhatkar < > >> > > > >> > chinmay@datatorrent.com > >> > > > >> > > wrote: > >> > > > >> > > >> > > > >> > > Hi All, > >> > > > >> > > > >> > > > >> > > We're planning to add a utility in malhar-library for > >> > generating a > >> > > > >> POJO > >> > > > >> > > class on the fly from given JSON schema. > >> > > > >> > > > >> > > > >> > > Use case is where the application is provided with schema > and > >> > that > >> > > > >> needs > >> > > > >> > to > >> > > > >> > > be used in one or more operators either as a tuple over the > >> > stream > >> > > > OR > >> > > > >> for > >> > > > >> > > processing. > >> > > > >> > > > >> > > > >> > > General Design: > >> > > > >> > > 1. Utility will be provided with fqcn of the class and > schema > >> > > > >> definition > >> > > > >> > > provided as json. > >> > > > >> > > 2. The schema definition will look like following: > >> > > > >> > > { > >> > > > >> > > "fqcn":"", > >> > > > >> > > "fields": [ > >> > > > >> > > { > >> > > > >> > > "name":"field1", > >> > > > >> > > "type":"long" > >> > > > >> > > }, > >> > > > >> > > { > >> > > > >> > > "name":"field2", > >> > > > >> > > "type": "string" > >> > > > >> > > } > >> > > > >> > > ] > >> > > > >> > > } > >> > > > >> > > 3. Supported types identified in "type" JSON field are: > >> > > > >> > > boolean, char, byte, short, int, float, long, double > >> > > > >> > > 4. The output of this utility will be a generated .class > >> file in > >> > > the > >> > > > >> form > >> > > > >> > > of FSDataOutputStream. > >> > > > >> > > 5. Xbean asm5 library will be used for this. > >> > > > >> > > 6. Following methods will be added to the generated class: > >> > > > >> > > a. Getter/Setter methods for given fields. > >> > > > >> > > b. simple toString - Generate string equivalent for all > >> the > >> > > > fields > >> > > > >> > > c. hashCode method - calculate the overall hashCode > using > >> > > > >> individual > >> > > > >> > > field hashcodes, similar to how String.hashCode generates > >> > hashCode > >> > > > of > >> > > > >> > > string using chars in it. > >> > > > >> > > d. equals method - Similar to how String.equals method > >> has > >> > > done > >> > > > it > >> > > > >> > > using individual char. > >> > > > >> > > > >> > > > >> > > > >> > > > >> > > Questions I have about the functionality: > >> > > > >> > > 1. Should the utility also support nested pojo definition > via > >> > > schema > >> > > > >> > json? > >> > > > >> > > In such case the field definition can look like > >> following: > >> > > > >> > > { "name":"nestedField", "type":" class>", > >> > > > >> > > "fields":[....] } > >> > > > >> > > The nested class will be provided > >> > > > >> > > > >> > > > >> > > 2. Should the utility also support giving out the > >> > JarOutputStream > >> > > > >> which > >> > > > >> > > will have a generated jar? > >> > > > >> > > > >> > > > >> > > Please let me know your thoughts. > >> > > > >> > > > >> > > > >> > > Thanks, > >> > > > >> > > Chinmay. > >> > > > >> > > > >> > > > >> > > >> > > > >> > >> > > > > > >> > > > > > >> > > > > >> > > > >> > > >> > > > --001a11c2d2e6e1c8b10529ec4976--