Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] opensearch-sql CLI doesn't print a error return if http code is 500 #5

Open
Yury-Fridlyand opened this issue Nov 19, 2021 · 2 comments
Assignees
Labels
bug Something isn't working

Comments

@Yury-Fridlyand
Copy link
Collaborator

Describe the bug
Some queries cause a error on server side and REST returns a message describing it followed by code 500. In this case CLI doesn't print the error.

opensearchsql> SELECT A, B FROM (SELECT `key` as A, DAYOFWEEK(date1) AS B from calcs) tmp WHERE tmp.B IN (1, 7);
KeyError('datarows')

image
In such cases I have to use CURL to see the message:

curl -XPOST http://localhost:9200/_plugins/_sql -H 'Content-Type: application/json' -d '{"query" : "SELECT A, B FROM (SELECT `key` as A, DAYOFWEEK(date1) AS B from calcs) tmp WHERE B IN (1, 7);"}'
{
  "error": {
    "reason": "There was internal problem at backend",
    "details": "The following method is not supported in Schema: DAYOFWEEK",
    "type": "UnsupportedOperationException"
  },
  "status": 500
}

The CLI interface is much more convenient for use rather than CURL, so it would be useful to keep using it to see the error message.

Additional context
Low priority

@zhongnansu
Copy link
Member

 curl -XPOST http://localhost:9200/_plugins/_sql -H 'Content-Type: application/json' -d '{"query" : "SELECT A, B FROM (SELECT `key` as A, DAYSOFWEEK(customer_first_name) AS B from opensearch_dashboards_sample_data_flights) opensearch_dashboards_sample_data_ecommerce;"}' -v
Note: Unnecessary use of -X or --request, POST is already inferred.
*   Trying ::1...
* TCP_NODELAY set
* Connected to localhost (::1) port 9200 (#0)
> POST /_plugins/_sql HTTP/1.1
> Host: localhost:9200
> User-Agent: curl/7.64.1
> Accept: */*
> Content-Type: application/json
> Content-Length: 180
> 
* upload completely sent off: 180 out of 180 bytes
< HTTP/1.1 200 OK
< content-type: application/json; charset=UTF-8
< content-length: 214
< 
{
  "error": {
    "reason": "There was internal problem at backend",
    "details": "The following method is not supported in Schema: DAYSOFWEEK",
    "type": "UnsupportedOperationException"
  },
  "status": 500
* Connection #0 to host localhost left intact
}* Closing connection 0

I think the sql engine itself shouldn't return 200 for this, it should be a 400 bad request. Then sql-cli will be able to handle this as TransportError defined in opensearch-py clinet. But since it's 200, sql-cli will assume it's giving data in the format, when it tries to parse it by data['datarows'], an KeyError is thrown.

I can deliver a fix temporarily, while creaing an issue for sql-engine

@zhongnansu
Copy link
Member

Created opensearch-project/sql#311

@dai-chen dai-chen transferred this issue from opensearch-project/sql Dec 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
No open projects
Status: No status
Development

No branches or pull requests

2 participants