You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@thrift.apache.org by reena upadhyay <re...@gmail.com> on 2015/06/17 19:41:25 UTC

How to represent java object as return type of service in .thrift file

I'm developing a service using apache thrift. I have a service named
getUser which returns User object. I couldn't find any way to define
user-defined data type as a return type for my service defined in .thrift
file.

user.thrift file looks like:

service UserService{
        User getUser(1:i32 userId),}

When I am compiling the user.thrift to generate java source code, I am
getting "*Type "User" has not been defined*" error. Can anyone please help
me, how to represent this user-defined java object as a data type in thrift.

The getUser method code in service implementation class:

@Override
     public User getUser(int user id) throws TException {
       // here is the code that fetch the user object from database
      return user;
     }

This is my User class, whose object is being returned by service getUser:

public class User {

private int userId;private String name;private String city;private
String country;public int getUserId() {
    return userId;}public void setUserId(int userId) {
    this.userId = userId;}public String getName() {
    return name;}public void setName(String name) {
    this.name = name;}public String getCity() {
    return city;}public void setCity(String city) {
    this.city = city;}public String getCountry() {
    return country;}public void setCountry(String country) {
    this.country = country;}

}

Re: How to represent java object as return type of service in .thrift file

Posted by Matt Chambers <mv...@me.com>.
Right, it would be like a proxy to a connection object and you could locate the connection out of some LRU cache or pool, but the client side object is not usable as a connection for ODBC.  And as you stated, its madness!

-Matt

> On Jun 17, 2015, at 2:29 PM, Stuart Reynolds <st...@stureynolds.com> wrote:
> 
> Its is *possible* to marshall a DB connection. (e.g. by representing a
> reference to it as an int ID, and sending it back for each query).
> However, its probably madness to do this.
> 
> On Wed, Jun 17, 2015 at 11:23 AM, Matt Chambers <mv...@me.com> wrote:
>> 
>> Then you have to construct the connection object on the client side.  Additionally, making DB connections and then handing them down to the client, even if it was possible and thankfully it isn’t, is not a good idea anyway.  It kinda defeats the purpose of thrift.
>> 
>> 
>>> On Jun 17, 2015, at 2:17 PM, reena upadhyay <re...@gmail.com> wrote:
>>> 
>>> I have built custom ODBC driver which works at client side, and there I
>>> would need a connection object.
>>> 
>>> On Wed, Jun 17, 2015 at 11:43 PM, Stuart Reynolds <st...@stureynolds.com>
>>> wrote:
>>> 
>>>> This isn't going to work. A java.sql.Connection contains data that
>>>> can't be communicated outside of the process (e.g. file system
>>>> objects)
>>>> 
>>>> This is a limitation of (almost all) network communication protocols,
>>>> not specifically thrift.
>>>> I guess, *why* do you want to send a Connection object out of your process?
>>>> There's probably something more sensible that you should send instead.
>>>> 
>>>> 
>>>> 
>>>> 
>>>> On Wed, Jun 17, 2015 at 11:00 AM, reena upadhyay <re...@gmail.com>
>>>> wrote:
>>>>> Ok. Thanks for the reply.
>>>>> 
>>>>> But my actual use case is: I want my service to return
>>>> java.sql.Connection
>>>>> object, and this data type is not supported in hive. How it represent it
>>>> in
>>>>> thrift file?
>>>>> 
>>>>> .thrift file is:
>>>>> 
>>>>> service databaseService{
>>>>>       Connection openConnection(),}
>>>>> 
>>>>> 
>>>>> The openConnection method code in service implementation class:
>>>>> 
>>>>> @Override
>>>>>    public Connection openConnection() throws TException {
>>>>>      // here is the code that fetch the user object from database
>>>>>     return connecton;
>>>>>    }
>>>>> 
>>>>> 
>>>>> On Wed, Jun 17, 2015 at 11:19 PM, nash <na...@gmail.com> wrote:
>>>>> 
>>>>>> I typically do it like this:
>>>>>> 
>>>>>> struct User {
>>>>>>  1: required string username;
>>>>>>  2: required i32 id;
>>>>>>  3: required string homedir;
>>>>>> }
>>>>>> 
>>>>>> service UserService {
>>>>>> User getUser(1:i32 userid);
>>>>>> }
>>>>>> 
>>>>>> When I compile the thrift file, it generates the User class.
>>>>>> 
>>>>>> --nash
>>>>>> 
>>>>>> On Wed, Jun 17, 2015 at 10:41 AM reena upadhyay <re...@gmail.com>
>>>>>> wrote:
>>>>>> 
>>>>>>> I'm developing a service using apache thrift. I have a service named
>>>>>>> getUser which returns User object. I couldn't find any way to define
>>>>>>> user-defined data type as a return type for my service defined in
>>>> .thrift
>>>>>>> file.
>>>>>>> 
>>>>>>> user.thrift file looks like:
>>>>>>> 
>>>>>>> service UserService{
>>>>>>>       User getUser(1:i32 userId),}
>>>>>>> 
>>>>>>> When I am compiling the user.thrift to generate java source code, I am
>>>>>>> getting "*Type "User" has not been defined*" error. Can anyone please
>>>>>> help
>>>>>>> me, how to represent this user-defined java object as a data type in
>>>>>>> thrift.
>>>>>>> 
>>>>>>> The getUser method code in service implementation class:
>>>>>>> 
>>>>>>> @Override
>>>>>>>    public User getUser(int user id) throws TException {
>>>>>>>      // here is the code that fetch the user object from database
>>>>>>>     return user;
>>>>>>>    }
>>>>>>> 
>>>>>>> This is my User class, whose object is being returned by service
>>>> getUser:
>>>>>>> 
>>>>>>> public class User {
>>>>>>> 
>>>>>>> private int userId;private String name;private String city;private
>>>>>>> String country;public int getUserId() {
>>>>>>>   return userId;}public void setUserId(int userId) {
>>>>>>>   this.userId = userId;}public String getName() {
>>>>>>>   return name;}public void setName(String name) {
>>>>>>>   this.name = name;}public String getCity() {
>>>>>>>   return city;}public void setCity(String city) {
>>>>>>>   this.city = city;}public String getCountry() {
>>>>>>>   return country;}public void setCountry(String country) {
>>>>>>>   this.country = country;}
>>>>>>> 
>>>>>>> }
>>>>>>> 
>>>>>> 
>>>> 
>> 


Re: How to represent java object as return type of service in .thrift file

Posted by Stuart Reynolds <st...@stureynolds.com>.
Its is *possible* to marshall a DB connection. (e.g. by representing a
reference to it as an int ID, and sending it back for each query).
However, its probably madness to do this.

On Wed, Jun 17, 2015 at 11:23 AM, Matt Chambers <mv...@me.com> wrote:
>
> Then you have to construct the connection object on the client side.  Additionally, making DB connections and then handing them down to the client, even if it was possible and thankfully it isn’t, is not a good idea anyway.  It kinda defeats the purpose of thrift.
>
>
>> On Jun 17, 2015, at 2:17 PM, reena upadhyay <re...@gmail.com> wrote:
>>
>> I have built custom ODBC driver which works at client side, and there I
>> would need a connection object.
>>
>> On Wed, Jun 17, 2015 at 11:43 PM, Stuart Reynolds <st...@stureynolds.com>
>> wrote:
>>
>>> This isn't going to work. A java.sql.Connection contains data that
>>> can't be communicated outside of the process (e.g. file system
>>> objects)
>>>
>>> This is a limitation of (almost all) network communication protocols,
>>> not specifically thrift.
>>> I guess, *why* do you want to send a Connection object out of your process?
>>> There's probably something more sensible that you should send instead.
>>>
>>>
>>>
>>>
>>> On Wed, Jun 17, 2015 at 11:00 AM, reena upadhyay <re...@gmail.com>
>>> wrote:
>>>> Ok. Thanks for the reply.
>>>>
>>>> But my actual use case is: I want my service to return
>>> java.sql.Connection
>>>> object, and this data type is not supported in hive. How it represent it
>>> in
>>>> thrift file?
>>>>
>>>> .thrift file is:
>>>>
>>>> service databaseService{
>>>>        Connection openConnection(),}
>>>>
>>>>
>>>> The openConnection method code in service implementation class:
>>>>
>>>> @Override
>>>>     public Connection openConnection() throws TException {
>>>>       // here is the code that fetch the user object from database
>>>>      return connecton;
>>>>     }
>>>>
>>>>
>>>> On Wed, Jun 17, 2015 at 11:19 PM, nash <na...@gmail.com> wrote:
>>>>
>>>>> I typically do it like this:
>>>>>
>>>>> struct User {
>>>>>   1: required string username;
>>>>>   2: required i32 id;
>>>>>   3: required string homedir;
>>>>> }
>>>>>
>>>>> service UserService {
>>>>>  User getUser(1:i32 userid);
>>>>> }
>>>>>
>>>>> When I compile the thrift file, it generates the User class.
>>>>>
>>>>> --nash
>>>>>
>>>>> On Wed, Jun 17, 2015 at 10:41 AM reena upadhyay <re...@gmail.com>
>>>>> wrote:
>>>>>
>>>>>> I'm developing a service using apache thrift. I have a service named
>>>>>> getUser which returns User object. I couldn't find any way to define
>>>>>> user-defined data type as a return type for my service defined in
>>> .thrift
>>>>>> file.
>>>>>>
>>>>>> user.thrift file looks like:
>>>>>>
>>>>>> service UserService{
>>>>>>        User getUser(1:i32 userId),}
>>>>>>
>>>>>> When I am compiling the user.thrift to generate java source code, I am
>>>>>> getting "*Type "User" has not been defined*" error. Can anyone please
>>>>> help
>>>>>> me, how to represent this user-defined java object as a data type in
>>>>>> thrift.
>>>>>>
>>>>>> The getUser method code in service implementation class:
>>>>>>
>>>>>> @Override
>>>>>>     public User getUser(int user id) throws TException {
>>>>>>       // here is the code that fetch the user object from database
>>>>>>      return user;
>>>>>>     }
>>>>>>
>>>>>> This is my User class, whose object is being returned by service
>>> getUser:
>>>>>>
>>>>>> public class User {
>>>>>>
>>>>>> private int userId;private String name;private String city;private
>>>>>> String country;public int getUserId() {
>>>>>>    return userId;}public void setUserId(int userId) {
>>>>>>    this.userId = userId;}public String getName() {
>>>>>>    return name;}public void setName(String name) {
>>>>>>    this.name = name;}public String getCity() {
>>>>>>    return city;}public void setCity(String city) {
>>>>>>    this.city = city;}public String getCountry() {
>>>>>>    return country;}public void setCountry(String country) {
>>>>>>    this.country = country;}
>>>>>>
>>>>>> }
>>>>>>
>>>>>
>>>
>

Re: How to represent java object as return type of service in .thrift file

Posted by Matt Chambers <mv...@me.com>.
Then you have to construct the connection object on the client side.  Additionally, making DB connections and then handing them down to the client, even if it was possible and thankfully it isn’t, is not a good idea anyway.  It kinda defeats the purpose of thrift.


> On Jun 17, 2015, at 2:17 PM, reena upadhyay <re...@gmail.com> wrote:
> 
> I have built custom ODBC driver which works at client side, and there I
> would need a connection object.
> 
> On Wed, Jun 17, 2015 at 11:43 PM, Stuart Reynolds <st...@stureynolds.com>
> wrote:
> 
>> This isn't going to work. A java.sql.Connection contains data that
>> can't be communicated outside of the process (e.g. file system
>> objects)
>> 
>> This is a limitation of (almost all) network communication protocols,
>> not specifically thrift.
>> I guess, *why* do you want to send a Connection object out of your process?
>> There's probably something more sensible that you should send instead.
>> 
>> 
>> 
>> 
>> On Wed, Jun 17, 2015 at 11:00 AM, reena upadhyay <re...@gmail.com>
>> wrote:
>>> Ok. Thanks for the reply.
>>> 
>>> But my actual use case is: I want my service to return
>> java.sql.Connection
>>> object, and this data type is not supported in hive. How it represent it
>> in
>>> thrift file?
>>> 
>>> .thrift file is:
>>> 
>>> service databaseService{
>>>        Connection openConnection(),}
>>> 
>>> 
>>> The openConnection method code in service implementation class:
>>> 
>>> @Override
>>>     public Connection openConnection() throws TException {
>>>       // here is the code that fetch the user object from database
>>>      return connecton;
>>>     }
>>> 
>>> 
>>> On Wed, Jun 17, 2015 at 11:19 PM, nash <na...@gmail.com> wrote:
>>> 
>>>> I typically do it like this:
>>>> 
>>>> struct User {
>>>>   1: required string username;
>>>>   2: required i32 id;
>>>>   3: required string homedir;
>>>> }
>>>> 
>>>> service UserService {
>>>>  User getUser(1:i32 userid);
>>>> }
>>>> 
>>>> When I compile the thrift file, it generates the User class.
>>>> 
>>>> --nash
>>>> 
>>>> On Wed, Jun 17, 2015 at 10:41 AM reena upadhyay <re...@gmail.com>
>>>> wrote:
>>>> 
>>>>> I'm developing a service using apache thrift. I have a service named
>>>>> getUser which returns User object. I couldn't find any way to define
>>>>> user-defined data type as a return type for my service defined in
>> .thrift
>>>>> file.
>>>>> 
>>>>> user.thrift file looks like:
>>>>> 
>>>>> service UserService{
>>>>>        User getUser(1:i32 userId),}
>>>>> 
>>>>> When I am compiling the user.thrift to generate java source code, I am
>>>>> getting "*Type "User" has not been defined*" error. Can anyone please
>>>> help
>>>>> me, how to represent this user-defined java object as a data type in
>>>>> thrift.
>>>>> 
>>>>> The getUser method code in service implementation class:
>>>>> 
>>>>> @Override
>>>>>     public User getUser(int user id) throws TException {
>>>>>       // here is the code that fetch the user object from database
>>>>>      return user;
>>>>>     }
>>>>> 
>>>>> This is my User class, whose object is being returned by service
>> getUser:
>>>>> 
>>>>> public class User {
>>>>> 
>>>>> private int userId;private String name;private String city;private
>>>>> String country;public int getUserId() {
>>>>>    return userId;}public void setUserId(int userId) {
>>>>>    this.userId = userId;}public String getName() {
>>>>>    return name;}public void setName(String name) {
>>>>>    this.name = name;}public String getCity() {
>>>>>    return city;}public void setCity(String city) {
>>>>>    this.city = city;}public String getCountry() {
>>>>>    return country;}public void setCountry(String country) {
>>>>>    this.country = country;}
>>>>> 
>>>>> }
>>>>> 
>>>> 
>> 


Re: How to represent java object as return type of service in .thrift file

Posted by Jens Geyer <je...@hotmail.com>.
Hi,

In my humble opinion, the only way that makes sense is to create a proxy 
object on the client side. The proxy hands out a "fake" connection to the 
client and makes it transparent to the client where the "real" connection 
really lives.

        Client  <--- ODBC ---> proxy driver <--- RPC ----> server driver 
<--- ODBC ---> connection

Whether or not the approach as a whole makes sense, and whether it will be 
performant enough to satisfy your needs, is another story.

Have fun,
JensG


-----Ursprüngliche Nachricht----- 
From: reena upadhyay
Sent: Wednesday, June 17, 2015 8:17 PM
To: user@thrift.apache.org
Subject: Re: How to represent java object as return type of service in 
.thrift file

I have built custom ODBC driver which works at client side, and there I
would need a connection object.

On Wed, Jun 17, 2015 at 11:43 PM, Stuart Reynolds <st...@stureynolds.com>
wrote:

> This isn't going to work. A java.sql.Connection contains data that
> can't be communicated outside of the process (e.g. file system
> objects)
>
> This is a limitation of (almost all) network communication protocols,
> not specifically thrift.
> I guess, *why* do you want to send a Connection object out of your 
> process?
> There's probably something more sensible that you should send instead.
>
>
>
>
> On Wed, Jun 17, 2015 at 11:00 AM, reena upadhyay <re...@gmail.com>
> wrote:
> > Ok. Thanks for the reply.
> >
> > But my actual use case is: I want my service to return
> java.sql.Connection
> > object, and this data type is not supported in hive. How it represent it
> in
> > thrift file?
> >
> > .thrift file is:
> >
> > service databaseService{
> >         Connection openConnection(),}
> >
> >
> > The openConnection method code in service implementation class:
> >
> > @Override
> >      public Connection openConnection() throws TException {
> >        // here is the code that fetch the user object from database
> >       return connecton;
> >      }
> >
> >
> > On Wed, Jun 17, 2015 at 11:19 PM, nash <na...@gmail.com> wrote:
> >
> >> I typically do it like this:
> >>
> >> struct User {
> >>    1: required string username;
> >>    2: required i32 id;
> >>    3: required string homedir;
> >> }
> >>
> >> service UserService {
> >>   User getUser(1:i32 userid);
> >> }
> >>
> >> When I compile the thrift file, it generates the User class.
> >>
> >> --nash
> >>
> >> On Wed, Jun 17, 2015 at 10:41 AM reena upadhyay <re...@gmail.com>
> >> wrote:
> >>
> >> > I'm developing a service using apache thrift. I have a service named
> >> > getUser which returns User object. I couldn't find any way to define
> >> > user-defined data type as a return type for my service defined in
> .thrift
> >> > file.
> >> >
> >> > user.thrift file looks like:
> >> >
> >> > service UserService{
> >> >         User getUser(1:i32 userId),}
> >> >
> >> > When I am compiling the user.thrift to generate java source code, I 
> >> > am
> >> > getting "*Type "User" has not been defined*" error. Can anyone please
> >> help
> >> > me, how to represent this user-defined java object as a data type in
> >> > thrift.
> >> >
> >> > The getUser method code in service implementation class:
> >> >
> >> > @Override
> >> >      public User getUser(int user id) throws TException {
> >> >        // here is the code that fetch the user object from database
> >> >       return user;
> >> >      }
> >> >
> >> > This is my User class, whose object is being returned by service
> getUser:
> >> >
> >> > public class User {
> >> >
> >> > private int userId;private String name;private String city;private
> >> > String country;public int getUserId() {
> >> >     return userId;}public void setUserId(int userId) {
> >> >     this.userId = userId;}public String getName() {
> >> >     return name;}public void setName(String name) {
> >> >     this.name = name;}public String getCity() {
> >> >     return city;}public void setCity(String city) {
> >> >     this.city = city;}public String getCountry() {
> >> >     return country;}public void setCountry(String country) {
> >> >     this.country = country;}
> >> >
> >> > }
> >> >
> >>
> 


Re: How to represent java object as return type of service in .thrift file

Posted by reena upadhyay <re...@gmail.com>.
I have built custom ODBC driver which works at client side, and there I
would need a connection object.

On Wed, Jun 17, 2015 at 11:43 PM, Stuart Reynolds <st...@stureynolds.com>
wrote:

> This isn't going to work. A java.sql.Connection contains data that
> can't be communicated outside of the process (e.g. file system
> objects)
>
> This is a limitation of (almost all) network communication protocols,
> not specifically thrift.
> I guess, *why* do you want to send a Connection object out of your process?
> There's probably something more sensible that you should send instead.
>
>
>
>
> On Wed, Jun 17, 2015 at 11:00 AM, reena upadhyay <re...@gmail.com>
> wrote:
> > Ok. Thanks for the reply.
> >
> > But my actual use case is: I want my service to return
> java.sql.Connection
> > object, and this data type is not supported in hive. How it represent it
> in
> > thrift file?
> >
> > .thrift file is:
> >
> > service databaseService{
> >         Connection openConnection(),}
> >
> >
> > The openConnection method code in service implementation class:
> >
> > @Override
> >      public Connection openConnection() throws TException {
> >        // here is the code that fetch the user object from database
> >       return connecton;
> >      }
> >
> >
> > On Wed, Jun 17, 2015 at 11:19 PM, nash <na...@gmail.com> wrote:
> >
> >> I typically do it like this:
> >>
> >> struct User {
> >>    1: required string username;
> >>    2: required i32 id;
> >>    3: required string homedir;
> >> }
> >>
> >> service UserService {
> >>   User getUser(1:i32 userid);
> >> }
> >>
> >> When I compile the thrift file, it generates the User class.
> >>
> >> --nash
> >>
> >> On Wed, Jun 17, 2015 at 10:41 AM reena upadhyay <re...@gmail.com>
> >> wrote:
> >>
> >> > I'm developing a service using apache thrift. I have a service named
> >> > getUser which returns User object. I couldn't find any way to define
> >> > user-defined data type as a return type for my service defined in
> .thrift
> >> > file.
> >> >
> >> > user.thrift file looks like:
> >> >
> >> > service UserService{
> >> >         User getUser(1:i32 userId),}
> >> >
> >> > When I am compiling the user.thrift to generate java source code, I am
> >> > getting "*Type "User" has not been defined*" error. Can anyone please
> >> help
> >> > me, how to represent this user-defined java object as a data type in
> >> > thrift.
> >> >
> >> > The getUser method code in service implementation class:
> >> >
> >> > @Override
> >> >      public User getUser(int user id) throws TException {
> >> >        // here is the code that fetch the user object from database
> >> >       return user;
> >> >      }
> >> >
> >> > This is my User class, whose object is being returned by service
> getUser:
> >> >
> >> > public class User {
> >> >
> >> > private int userId;private String name;private String city;private
> >> > String country;public int getUserId() {
> >> >     return userId;}public void setUserId(int userId) {
> >> >     this.userId = userId;}public String getName() {
> >> >     return name;}public void setName(String name) {
> >> >     this.name = name;}public String getCity() {
> >> >     return city;}public void setCity(String city) {
> >> >     this.city = city;}public String getCountry() {
> >> >     return country;}public void setCountry(String country) {
> >> >     this.country = country;}
> >> >
> >> > }
> >> >
> >>
>

Re: How to represent java object as return type of service in .thrift file

Posted by Stuart Reynolds <st...@stureynolds.com>.
This isn't going to work. A java.sql.Connection contains data that
can't be communicated outside of the process (e.g. file system
objects)

This is a limitation of (almost all) network communication protocols,
not specifically thrift.
I guess, *why* do you want to send a Connection object out of your process?
There's probably something more sensible that you should send instead.




On Wed, Jun 17, 2015 at 11:00 AM, reena upadhyay <re...@gmail.com> wrote:
> Ok. Thanks for the reply.
>
> But my actual use case is: I want my service to return java.sql.Connection
> object, and this data type is not supported in hive. How it represent it in
> thrift file?
>
> .thrift file is:
>
> service databaseService{
>         Connection openConnection(),}
>
>
> The openConnection method code in service implementation class:
>
> @Override
>      public Connection openConnection() throws TException {
>        // here is the code that fetch the user object from database
>       return connecton;
>      }
>
>
> On Wed, Jun 17, 2015 at 11:19 PM, nash <na...@gmail.com> wrote:
>
>> I typically do it like this:
>>
>> struct User {
>>    1: required string username;
>>    2: required i32 id;
>>    3: required string homedir;
>> }
>>
>> service UserService {
>>   User getUser(1:i32 userid);
>> }
>>
>> When I compile the thrift file, it generates the User class.
>>
>> --nash
>>
>> On Wed, Jun 17, 2015 at 10:41 AM reena upadhyay <re...@gmail.com>
>> wrote:
>>
>> > I'm developing a service using apache thrift. I have a service named
>> > getUser which returns User object. I couldn't find any way to define
>> > user-defined data type as a return type for my service defined in .thrift
>> > file.
>> >
>> > user.thrift file looks like:
>> >
>> > service UserService{
>> >         User getUser(1:i32 userId),}
>> >
>> > When I am compiling the user.thrift to generate java source code, I am
>> > getting "*Type "User" has not been defined*" error. Can anyone please
>> help
>> > me, how to represent this user-defined java object as a data type in
>> > thrift.
>> >
>> > The getUser method code in service implementation class:
>> >
>> > @Override
>> >      public User getUser(int user id) throws TException {
>> >        // here is the code that fetch the user object from database
>> >       return user;
>> >      }
>> >
>> > This is my User class, whose object is being returned by service getUser:
>> >
>> > public class User {
>> >
>> > private int userId;private String name;private String city;private
>> > String country;public int getUserId() {
>> >     return userId;}public void setUserId(int userId) {
>> >     this.userId = userId;}public String getName() {
>> >     return name;}public void setName(String name) {
>> >     this.name = name;}public String getCity() {
>> >     return city;}public void setCity(String city) {
>> >     this.city = city;}public String getCountry() {
>> >     return country;}public void setCountry(String country) {
>> >     this.country = country;}
>> >
>> > }
>> >
>>

Re: How to represent java object as return type of service in .thrift file

Posted by reena upadhyay <re...@gmail.com>.
Ok. Thanks for the reply.

But my actual use case is: I want my service to return java.sql.Connection
object, and this data type is not supported in hive. How it represent it in
thrift file?

.thrift file is:

service databaseService{
        Connection openConnection(),}


The openConnection method code in service implementation class:

@Override
     public Connection openConnection() throws TException {
       // here is the code that fetch the user object from database
      return connecton;
     }


On Wed, Jun 17, 2015 at 11:19 PM, nash <na...@gmail.com> wrote:

> I typically do it like this:
>
> struct User {
>    1: required string username;
>    2: required i32 id;
>    3: required string homedir;
> }
>
> service UserService {
>   User getUser(1:i32 userid);
> }
>
> When I compile the thrift file, it generates the User class.
>
> --nash
>
> On Wed, Jun 17, 2015 at 10:41 AM reena upadhyay <re...@gmail.com>
> wrote:
>
> > I'm developing a service using apache thrift. I have a service named
> > getUser which returns User object. I couldn't find any way to define
> > user-defined data type as a return type for my service defined in .thrift
> > file.
> >
> > user.thrift file looks like:
> >
> > service UserService{
> >         User getUser(1:i32 userId),}
> >
> > When I am compiling the user.thrift to generate java source code, I am
> > getting "*Type "User" has not been defined*" error. Can anyone please
> help
> > me, how to represent this user-defined java object as a data type in
> > thrift.
> >
> > The getUser method code in service implementation class:
> >
> > @Override
> >      public User getUser(int user id) throws TException {
> >        // here is the code that fetch the user object from database
> >       return user;
> >      }
> >
> > This is my User class, whose object is being returned by service getUser:
> >
> > public class User {
> >
> > private int userId;private String name;private String city;private
> > String country;public int getUserId() {
> >     return userId;}public void setUserId(int userId) {
> >     this.userId = userId;}public String getName() {
> >     return name;}public void setName(String name) {
> >     this.name = name;}public String getCity() {
> >     return city;}public void setCity(String city) {
> >     this.city = city;}public String getCountry() {
> >     return country;}public void setCountry(String country) {
> >     this.country = country;}
> >
> > }
> >
>

Re: How to represent java object as return type of service in .thrift file

Posted by nash <na...@gmail.com>.
I typically do it like this:

struct User {
   1: required string username;
   2: required i32 id;
   3: required string homedir;
}

service UserService {
  User getUser(1:i32 userid);
}

When I compile the thrift file, it generates the User class.

--nash

On Wed, Jun 17, 2015 at 10:41 AM reena upadhyay <re...@gmail.com> wrote:

> I'm developing a service using apache thrift. I have a service named
> getUser which returns User object. I couldn't find any way to define
> user-defined data type as a return type for my service defined in .thrift
> file.
>
> user.thrift file looks like:
>
> service UserService{
>         User getUser(1:i32 userId),}
>
> When I am compiling the user.thrift to generate java source code, I am
> getting "*Type "User" has not been defined*" error. Can anyone please help
> me, how to represent this user-defined java object as a data type in
> thrift.
>
> The getUser method code in service implementation class:
>
> @Override
>      public User getUser(int user id) throws TException {
>        // here is the code that fetch the user object from database
>       return user;
>      }
>
> This is my User class, whose object is being returned by service getUser:
>
> public class User {
>
> private int userId;private String name;private String city;private
> String country;public int getUserId() {
>     return userId;}public void setUserId(int userId) {
>     this.userId = userId;}public String getName() {
>     return name;}public void setName(String name) {
>     this.name = name;}public String getCity() {
>     return city;}public void setCity(String city) {
>     this.city = city;}public String getCountry() {
>     return country;}public void setCountry(String country) {
>     this.country = country;}
>
> }
>