@@ -64,7 +64,7 @@ public static OtpOutputStream encodeTsQueryRequest(String queryText, byte[] cove
6464 final OtpOutputStream os = new OtpOutputStream ();
6565 os .write (OtpExternal .versionTag ); // NB: this is the reqired 0x83 (131) value
6666
67- // TsQueryReq is a 4-tuple: {'tsqueryreq', TsInt , boolIsStreaming, bytesCoverContext}
67+ // TsQueryReq is a 4-tuple: {'tsqueryreq', TsInterpolation , boolIsStreaming, bytesCoverContext}
6868 os .write_tuple_head (4 );
6969 os .write_atom (TS_QUERY_REQ );
7070
@@ -171,6 +171,10 @@ else if (cell.hasDouble())
171171 {
172172 stream .write_double (cell .getDouble ());
173173 }
174+ else if (cell .hasBlob ())
175+ {
176+ stream .write_binary (cell .getBlob ());
177+ }
174178 else
175179 {
176180 logger .error ("Unknown TS cell type encountered." );
@@ -181,11 +185,9 @@ else if (cell.hasDouble())
181185 private static QueryResult decodeTsResponse (byte [] response )
182186 throws OtpErlangDecodeException , InvalidTermToBinaryException
183187 {
184- QueryResult result = null ;
185-
186- OtpInputStream is = new OtpInputStream (response );
188+ final OtpInputStream is = new OtpInputStream (response );
187189
188- int firstByte = is .read1skip_version ();
190+ final int firstByte = is .read1skip_version ();
189191 is .reset ();
190192
191193 if (firstByte != OtpExternal .smallTupleTag && firstByte != OtpExternal .largeTupleTag )
@@ -213,7 +215,7 @@ private static QueryResult parseAtomResult(OtpInputStream is)
213215 private static QueryResult parseTupleResult (OtpInputStream is )
214216 throws OtpErlangDecodeException , InvalidTermToBinaryException
215217 {
216- QueryResult result ;
218+ final QueryResult result ;
217219 final int msgArity = is .read_tuple_head ();
218220 // Response is:
219221 // {'rpberrorresp', ErrMsg, ErrCode}
@@ -322,30 +324,55 @@ private static Cell parseCell(List<RiakTsPB.TsColumnDescription> columnDescripti
322324 {
323325 if (cell instanceof OtpErlangBinary )
324326 {
325- OtpErlangBinary v = (OtpErlangBinary ) cell ;
326- String s = new String (v .binaryValue (), StandardCharsets .UTF_8 );
327- return new Cell (s );
327+ final OtpErlangBinary v = (OtpErlangBinary ) cell ;
328+ final RiakTsPB .TsColumnType type = columnDescriptions .get (j ).getType ();
329+ switch (type )
330+ {
331+ case VARCHAR :
332+ final String s = new String (v .binaryValue (), StandardCharsets .UTF_8 );
333+ return new Cell (s );
334+
335+ case BLOB :
336+ return new Cell (v .binaryValue ());
337+
338+ default :
339+ throw new IllegalStateException (
340+ String .format (
341+ "Type '%s' from the provided ColumnDescription contradicts to the actual OtpErlangBinary value" ,
342+ type .name ()
343+ )
344+ );
345+ }
328346 }
329347 else if (cell instanceof OtpErlangLong )
330348 {
331- OtpErlangLong v = (OtpErlangLong ) cell ;
332- if (columnDescriptions .get (j ).getType () == RiakTsPB .TsColumnType .TIMESTAMP )
349+ final OtpErlangLong v = (OtpErlangLong ) cell ;
350+ final RiakTsPB .TsColumnType type = columnDescriptions .get (j ).getType ();
351+ switch (type )
333352 {
334- return Cell .newTimestamp (v .longValue ());
335- }
336- else
337- {
338- return new Cell (v .longValue ());
353+ case TIMESTAMP :
354+ return Cell .newTimestamp (v .longValue ());
355+
356+ case SINT64 :
357+ return new Cell (v .longValue ());
358+
359+ default :
360+ throw new IllegalStateException (
361+ String .format (
362+ "Type '%s' from the provided ColumnDescription contradicts to the actual OtpErlangLong value" ,
363+ type .name ()
364+ )
365+ );
339366 }
340367 }
341368 else if (cell instanceof OtpErlangDouble )
342369 {
343- OtpErlangDouble v = (OtpErlangDouble ) cell ;
370+ final OtpErlangDouble v = (OtpErlangDouble ) cell ;
344371 return new Cell (v .doubleValue ());
345372 }
346373 else if (cell instanceof OtpErlangAtom )
347374 {
348- OtpErlangAtom v = (OtpErlangAtom ) cell ;
375+ final OtpErlangAtom v = (OtpErlangAtom ) cell ;
349376 return new Cell (v .booleanValue ());
350377 }
351378 else if (cell instanceof OtpErlangList )
@@ -354,10 +381,8 @@ else if (cell instanceof OtpErlangList)
354381 assert (l .arity () == 0 );
355382 return null ;
356383 }
357- else
358- {
359- throw new InvalidTermToBinaryException ("Unknown cell type encountered: " + cell .toString () + ", unable to" +
360- " continue parsing." );
361- }
384+
385+ throw new InvalidTermToBinaryException ("Unknown cell type encountered: " + cell .toString () +
386+ ", unable to continue parsing." );
362387 }
363388}
0 commit comments