You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@phoenix.apache.org by Steve Terrell <st...@oculus360.us> on 2016/02/05 06:30:48 UTC

Phoenix Query Server and/or Avatica Bug and/or My Misunderstanding

I can query Phoenix by doing something like this:

curl -v -XPOST -H 'request:
{"request":"prepareAndExecute","connectionId":"aaa","sql":"select * from
CAT_MAP"}' http://10.0.100.57:8765/


However, I am unable to make such a request in Javascript in my web page
because the POST method, along with a custom header, trigger CORS security
in modern browsers which do a "method OPTIONS" preflight request, which is
not handled by the Phoenix Query Server (that I know of).

I dug and dug and dug and found some Avatica source code that made it look
like one should be able to put the JSON into the post data instead of the
header, and it should work.  (See lines 78-89 in
https://github.com/apache/calcite/blob/master/avatica-server/src/main/java/org/apache/calcite/avatica/server/AvaticaJsonHandler.java
).  I don't know if this is the version of Avatica that PQS uses, but it
sounded like a good chance this feature would persist through many versions.

So I tried this:

curl -v -XPOST -H 'Content-Type: text/plain' -d
'{"request":"prepareAndExecute","connectionId":"aaa","sql":"select * from
CAT_MAP"}' http://10.0.100.57:8765/


But I got an "HTTP/1.1 500 Server Error".  Further more, the request caused
this in the PQS logs:
2016-02-05 05:22:58,085 WARN org.eclipse.jetty.server.HttpChannel: /

java.lang.NullPointerException
at java.io.StringReader.<init>(StringReader.java:50)
at
com.fasterxml.jackson.core.JsonFactory.createJsonParser(JsonFactory.java:917)
at
com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:1942)
at org.apache.calcite.avatica.remote.JsonHandler.decode(JsonHandler.java:51)
at org.apache.calcite.avatica.remote.JsonHandler.apply(JsonHandler.java:42)
at
org.apache.calcite.avatica.server.AvaticaHandler.handle(AvaticaHandler.java:55)
at org.eclipse.jetty.server.handler.HandlerList.handle(HandlerList.java:52)
at
org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:97)
at org.eclipse.jetty.server.Server.handle(Server.java:497)
at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:310)
at
org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:245)
at
org.eclipse.jetty.io.AbstractConnection$2.run(AbstractConnection.java:540)
at
org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:635)
at
org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:555)
at java.lang.Thread.run(Thread.java:745)


Does anyone know if I am doing something wrong?

Thanks,
    Steve

Re: Phoenix Query Server and/or Avatica Bug and/or My Misunderstanding

Posted by Josh Elser <jo...@gmail.com>.
Hi Steve,

Sorry for the delayed response.

Putting the "payload" (json or protobuf) into the POST instead of the 
header should be the 'recommended' way forward to avoid the limit as you 
ran into [1]. I think Phoenix >=4.6 was using Calcite-1.4, but my memory 
might be failing me.

Regarding the HTTP 500 error you saw, I'm not entirely sure without some 
more information from you about what version you were running. For 
example, the PrepareAndExecute request as of now is a bit different than 
what you provided [2]. I'm guessing it tried to deserialize some 
required field that wasn't provided in the JSON? LMK if you still are 
stuck and I can try help out.

- Josh

[1] https://issues.apache.org/jira/browse/CALCITE-780
[2] 
http://calcite.apache.org/docs/avatica_json_reference.html#prepareandexecuterequest

Steve Terrell wrote:
> I can query Phoenix by doing something like this:
>
>     curl -v -XPOST -H 'request:
>     {"request":"prepareAndExecute","connectionId":"aaa","sql":"select *
>     from CAT_MAP"}' http://10.0.100.57:8765/
>
>
> However, I am unable to make such a request in Javascript in my web page
> because the POST method, along with a custom header, trigger CORS
> security in modern browsers which do a "method OPTIONS" preflight
> request, which is not handled by the Phoenix Query Server (that I know of).
>
> I dug and dug and dug and found some Avatica source code that made it
> look like one should be able to put the JSON into the post data instead
> of the header, and it should work.  (See lines 78-89 in
> https://github.com/apache/calcite/blob/master/avatica-server/src/main/java/org/apache/calcite/avatica/server/AvaticaJsonHandler.java
> ).  I don't know if this is the version of Avatica that PQS uses, but it
> sounded like a good chance this feature would persist through many versions.
>
> So I tried this:
>
>     curl -v -XPOST -H 'Content-Type: text/plain' -d
>     '{"request":"prepareAndExecute","connectionId":"aaa","sql":"select *
>     from CAT_MAP"}' http://10.0.100.57:8765/
>
>
> But I got an "HTTP/1.1 500 Server Error".  Further more, the request
> caused this in the PQS logs:
> 2016-02-05 05:22:58,085 WARN org.eclipse.jetty.server.HttpChannel: /
>
>     java.lang.NullPointerException
>     at java.io.StringReader.<init>(StringReader.java:50)
>     at
>     com.fasterxml.jackson.core.JsonFactory.createJsonParser(JsonFactory.java:917)
>     at
>     com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:1942)
>     at
>     org.apache.calcite.avatica.remote.JsonHandler.decode(JsonHandler.java:51)
>     at
>     org.apache.calcite.avatica.remote.JsonHandler.apply(JsonHandler.java:42)
>     at
>     org.apache.calcite.avatica.server.AvaticaHandler.handle(AvaticaHandler.java:55)
>     at
>     org.eclipse.jetty.server.handler.HandlerList.handle(HandlerList.java:52)
>     at
>     org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:97)
>     at org.eclipse.jetty.server.Server.handle(Server.java:497)
>     at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:310)
>     at
>     org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:245)
>     at
>     org.eclipse.jetty.io.AbstractConnection$2.run(AbstractConnection.java:540)
>     at
>     org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:635)
>     at
>     org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:555)
>     at java.lang.Thread.run(Thread.java:745)
>
>
> Does anyone know if I am doing something wrong?
>
> Thanks,
>      Steve