You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@thrift.apache.org by Avinash Dongre <do...@gmail.com> on 2013/05/13 13:49:50 UTC

Optional Field in Thrift Structure

I have following structure

struct Response {
  1: optional bool isFinished, // for BLOB and CLOB
  2: optional ResponseSubset r1,
  3: optional i32 Count,
  4: optional list<alue> params,
  6: optional ResponseSubset1 warnings,
}

and Have api like this

Response performanOperation(1. required i32 id)

When I implement my server in Java, do i need to update all the fields
while constructing response . Or just some field updates is enough.

Sometimes I get following kind of exception


org.apache.thrift.transport.TTransportException
    at
org.apache.thrift.transport.TIOStreamTransport.read(TIOStreamTransport.java:132)
    at org.apache.thrift.transport.TTransport.readAll(TTransport.java:84)
    at
org.apache.thrift.protocol.TBinaryProtocol.readAll(TBinaryProtocol.java:378)
    at
org.apache.thrift.protocol.TBinaryProtocol.readI32(TBinaryProtocol.java:297)
    at
org.apache.thrift.protocol.TBinaryProtocol.readMessageBegin(TBinaryProtocol.java:204)
    at org.apache.thrift.TServiceClient.receiveBase(TServiceClient.java:69)


Thanks
Avinash

Re: Optional Field in Thrift Structure

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

what puzzles me is, that

> TBinaryProtocol.java:204

is the first line, where the version number is read. If at that place the 
input stream is empty, then there is something fundamentally wrong. I'm not 
the Java expert, but could it be, that the server (not the client!) throws 
an exception and does not respond to the call corectly, which in turn leads 
to the client trying to read from an empty response stream?



-----Ursprüngliche Nachricht----- 
From: Avinash Dongre
Sent: Tuesday, May 14, 2013 8:48 AM
To: user@thrift.apache.org
Subject: Re: Optional Field in Thrift Structure

Thanks Jens,
I am using Binary protocol. I have further debugged the issue. and What I
found is that
I have
List<List<AnotherStructure>> to return. All the fields in the
AnotherStructure is optional. When I try to update this list then only I am
getting the exception.

List<List<AnotherStructure>> allrows = new
ArrayList<List<AnotherStructure>>();
        while (rs.next()) {
            List<AnotherStructure> singleRow = new
ArrayList<AnotherStructure>();
            for (int i = 1; i <= 100; i++) {
                AnotherStructure cv = createAnotherStructure();
                singleRow.add(cv);
            }
            allrows.add(singleRow);
        }
        sr.getResultSet().setRows(allrows);

If I do following by commenting the population i do not get any exception.

List<List<AnotherStructure>> allrows = new
ArrayList<List<AnotherStructure>>();
        while (rs.next()) {
            List<AnotherStructure> singleRow = new
ArrayList<AnotherStructure>();
            allrows.add(singleRow);
        }
        sr.getResultSet().setRows(allrows);


Thanks
Avinash



On Tue, May 14, 2013 at 3:17 AM, Jens Geyer <je...@hotmail.com> wrote:

> Hi Avinash,
>
>
>  When I implement my server in Java, do i need to update all the fields
>> while constructing response . Or just some field updates is enough.
>>
>
> You would have to set required fields, if there were any. Since your
> Response struct only consists of optionals, it would be perfectly legal to
> send a response structure back with no values at all.
>
>
>  Sometimes I get following kind of exception
>>
>
> From what I see in the code, the exception is TTransportException.END_OF_*
> *FILE. Therefore I don't think that the problem has anything to do with
> optionals being set or not set. But it could be helpful to the Java guys 
> if
> they had a little more information about your setup, especially which
> transport and which protocol(s) you are using.
>
>
>
> -----Ursprüngliche Nachricht----- From: Avinash Dongre
> Sent: Monday, May 13, 2013 1:49 PM
> To: user@thrift.apache.org
> Subject: Optional Field in Thrift Structure
>
>
> I have following structure
>
> struct Response {
>  1: optional bool isFinished, // for BLOB and CLOB
>  2: optional ResponseSubset r1,
>  3: optional i32 Count,
>  4: optional list<alue> params,
>  6: optional ResponseSubset1 warnings,
> }
>
> and Have api like this
>
> Response performanOperation(1. required i32 id)
>
> When I implement my server in Java, do i need to update all the fields
> while constructing response . Or just some field updates is enough.
>
> Sometimes I get following kind of exception
>
>
> org.apache.thrift.transport.**TTransportException
>    at
> org.apache.thrift.transport.**TIOStreamTransport.read(**
> TIOStreamTransport.java:132)
>    at org.apache.thrift.transport.**TTransport.readAll(TTransport.**
> java:84)
>    at
> org.apache.thrift.protocol.**TBinaryProtocol.readAll(**
> TBinaryProtocol.java:378)
>    at
> org.apache.thrift.protocol.**TBinaryProtocol.readI32(**
> TBinaryProtocol.java:297)
>    at
> org.apache.thrift.protocol.**TBinaryProtocol.**readMessageBegin(**
> TBinaryProtocol.java:204)
>    at org.apache.thrift.**TServiceClient.receiveBase(**
> TServiceClient.java:69)
>
>
> Thanks
> Avinash
> 


Re: Optional Field in Thrift Structure

Posted by Avinash Dongre <do...@gmail.com>.
Thanks Jens,
I am using Binary protocol. I have further debugged the issue. and What I
found is that
I have
List<List<AnotherStructure>> to return. All the fields in the
AnotherStructure is optional. When I try to update this list then only I am
getting the exception.

List<List<AnotherStructure>> allrows = new
ArrayList<List<AnotherStructure>>();
        while (rs.next()) {
            List<AnotherStructure> singleRow = new
ArrayList<AnotherStructure>();
            for (int i = 1; i <= 100; i++) {
                AnotherStructure cv = createAnotherStructure();
                singleRow.add(cv);
            }
            allrows.add(singleRow);
        }
        sr.getResultSet().setRows(allrows);

If I do following by commenting the population i do not get any exception.

List<List<AnotherStructure>> allrows = new
ArrayList<List<AnotherStructure>>();
        while (rs.next()) {
            List<AnotherStructure> singleRow = new
ArrayList<AnotherStructure>();
            allrows.add(singleRow);
        }
        sr.getResultSet().setRows(allrows);


Thanks
Avinash



On Tue, May 14, 2013 at 3:17 AM, Jens Geyer <je...@hotmail.com> wrote:

> Hi Avinash,
>
>
>  When I implement my server in Java, do i need to update all the fields
>> while constructing response . Or just some field updates is enough.
>>
>
> You would have to set required fields, if there were any. Since your
> Response struct only consists of optionals, it would be perfectly legal to
> send a response structure back with no values at all.
>
>
>  Sometimes I get following kind of exception
>>
>
> From what I see in the code, the exception is TTransportException.END_OF_*
> *FILE. Therefore I don't think that the problem has anything to do with
> optionals being set or not set. But it could be helpful to the Java guys if
> they had a little more information about your setup, especially which
> transport and which protocol(s) you are using.
>
>
>
> -----Ursprüngliche Nachricht----- From: Avinash Dongre
> Sent: Monday, May 13, 2013 1:49 PM
> To: user@thrift.apache.org
> Subject: Optional Field in Thrift Structure
>
>
> I have following structure
>
> struct Response {
>  1: optional bool isFinished, // for BLOB and CLOB
>  2: optional ResponseSubset r1,
>  3: optional i32 Count,
>  4: optional list<alue> params,
>  6: optional ResponseSubset1 warnings,
> }
>
> and Have api like this
>
> Response performanOperation(1. required i32 id)
>
> When I implement my server in Java, do i need to update all the fields
> while constructing response . Or just some field updates is enough.
>
> Sometimes I get following kind of exception
>
>
> org.apache.thrift.transport.**TTransportException
>    at
> org.apache.thrift.transport.**TIOStreamTransport.read(**
> TIOStreamTransport.java:132)
>    at org.apache.thrift.transport.**TTransport.readAll(TTransport.**
> java:84)
>    at
> org.apache.thrift.protocol.**TBinaryProtocol.readAll(**
> TBinaryProtocol.java:378)
>    at
> org.apache.thrift.protocol.**TBinaryProtocol.readI32(**
> TBinaryProtocol.java:297)
>    at
> org.apache.thrift.protocol.**TBinaryProtocol.**readMessageBegin(**
> TBinaryProtocol.java:204)
>    at org.apache.thrift.**TServiceClient.receiveBase(**
> TServiceClient.java:69)
>
>
> Thanks
> Avinash
>

Re: Optional Field in Thrift Structure

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

> When I implement my server in Java, do i need to update all the fields
> while constructing response . Or just some field updates is enough.

You would have to set required fields, if there were any. Since your 
Response struct only consists of optionals, it would be perfectly legal to 
send a response structure back with no values at all.

> Sometimes I get following kind of exception

>From what I see in the code, the exception is 
TTransportException.END_OF_FILE. Therefore I don't think that the problem 
has anything to do with optionals being set or not set. But it could be 
helpful to the Java guys if they had a little more information about your 
setup, especially which transport and which protocol(s) you are using.



-----Ursprüngliche Nachricht----- 
From: Avinash Dongre
Sent: Monday, May 13, 2013 1:49 PM
To: user@thrift.apache.org
Subject: Optional Field in Thrift Structure

I have following structure

struct Response {
  1: optional bool isFinished, // for BLOB and CLOB
  2: optional ResponseSubset r1,
  3: optional i32 Count,
  4: optional list<alue> params,
  6: optional ResponseSubset1 warnings,
}

and Have api like this

Response performanOperation(1. required i32 id)

When I implement my server in Java, do i need to update all the fields
while constructing response . Or just some field updates is enough.

Sometimes I get following kind of exception


org.apache.thrift.transport.TTransportException
    at
org.apache.thrift.transport.TIOStreamTransport.read(TIOStreamTransport.java:132)
    at org.apache.thrift.transport.TTransport.readAll(TTransport.java:84)
    at
org.apache.thrift.protocol.TBinaryProtocol.readAll(TBinaryProtocol.java:378)
    at
org.apache.thrift.protocol.TBinaryProtocol.readI32(TBinaryProtocol.java:297)
    at
org.apache.thrift.protocol.TBinaryProtocol.readMessageBegin(TBinaryProtocol.java:204)
    at org.apache.thrift.TServiceClient.receiveBase(TServiceClient.java:69)


Thanks
Avinash