Query_runner output format?


#1

I am attempting to write a new query runner for Redash. I have reviewed the instructions Almost everything seems to work except the final step where the result is sent back to the javascript client and displayed. I opened the browser debugger and confirmed the GET request to http://localhost:8080/api/query_results/74 returns

{"query_result":{
    "retrieved_at":"2017-05-10T19:54:26.226000-04:00",
    "query_hash":"2dc661d2611d74d651b1107035e596f6",
    "query":"SELECT repo.changeset.id\nFROM perf",
    "runtime":0.16100001335144,
    "data":{
        "rows":[
            ["eda310265741fb26bbd91a92017bc6337fcc8de6"],
            ["eda310265741fb26bbd91a92017bc6337fcc8de6"],
            ["eda310265741fb26bbd91a92017bc6337fcc8de6"],
            ["eda310265741fb26bbd91a92017bc6337fcc8de6"],
            ["e1763ef7d6b96ab3ff6bc4f94c6e3cdd6b5e79bb"],
            ["e1763ef7d6b96ab3ff6bc4f94c6e3cdd6b5e79bb"],
            ["b2091e309c886676cdee80ecda98f11bdf78d461"],
            ["b1d60f2f68c7cccc96fcf9a2075bb430a500a0f2"],
            ["733a77530961deeed0690c1b0993b8c064b07da4"],
            ["d3d45f7fa087c2c15742bd572ec45e01d1151911"]
        ],
        "columns":[["repo.changeset.id","string",null]]
    },
    "id":74,
    "data_source_id":1
}}

but the console complains

TypeError: name is undefined
Stack trace:
prepareFilters/<@http://localhost:8080/app.8ae2e1990723221426bd.js line 2090 > eval:390:15
prepareFilters@http://localhost:8080/app.8ae2e1990723221426bd.js line 2090 > eval:388:9
getFilters@http://localhost:8080/app.8ae2e1990723221426bd.js line 2090 > eval:373:11
getData@http://localhost:8080/app.8ae2e1990723221426bd.js line 2090 > eval:226:23
fn@http://localhost:8080/app.8ae2e1990723221426bd.js line 346 > eval line 15358 > Function:4:252
$digest@http://localhost:8080/app.8ae2e1990723221426bd.js line 346 > eval:17991:34
$apply@http://localhost:8080/app.8ae2e1990723221426bd.js line 346 > eval:18269:13
done@http://localhost:8080/app.8ae2e1990723221426bd.js line 346 > eval:12387:36
completeRequest@http://localhost:8080/app.8ae2e1990723221426bd.js line 346 > eval:12613:7
requestLoaded@http://localhost:8080/app.8ae2e1990723221426bd.js line 346 > eval:12541:9

I assume this is a formatting problem of some sort. Are there some examples of well formatted query responses that I can use to compare against?

Thank you


#2

Your results format is wrong - both for columns and rows. See this for reference: https://redash.io/help-onpremise/how-rd-works/data-source-results-format.html. Also, any query you run with a regular data source will generate you an example of how it should look like.

Your data should be like this:

{
  "rows": [
    {"repo.changeset.id": "eda310265741fb26bbd91a92017bc6337fcc8de6"}, 
    {"repo.changeset.id": "eda310265741fb26bbd91a92017bc6337fcc8de6"},
    ...],
  "columns": [{"name": "repo.changeset.id", "type": "string", "friendly_name": null}]
}

#3

Thank you very much! I totally read the code wrong.


#4

When the client calls http://localhost:8080/api/query_results/90 it now returns

{"query_result": {
    "retrieved_at": "2017-05-27T08:58:27.780000-04:00",
    "query_hash": "2dc661d2611d74d651b1107035e596f6",
    "query": "select repo.changeset.id from perf",
    "runtime": 0.144999980926514,
    "data": {
        "rows": [
            {"repo_changeset_id": "eda310265741fb26bbd91a92017bc6337fcc8de6"},
            {"repo_changeset_id": "eda310265741fb26bbd91a92017bc6337fcc8de6"},
            {"repo_changeset_id": "eda310265741fb26bbd91a92017bc6337fcc8de6"},
            {"repo_changeset_id": "eda310265741fb26bbd91a92017bc6337fcc8de6"},
            {"repo_changeset_id": "e1763ef7d6b96ab3ff6bc4f94c6e3cdd6b5e79bb"},
            {"repo_changeset_id": "e1763ef7d6b96ab3ff6bc4f94c6e3cdd6b5e79bb"},
            {"repo_changeset_id": "b2091e309c886676cdee80ecda98f11bdf78d461"},
            {"repo_changeset_id": "b1d60f2f68c7cccc96fcf9a2075bb430a500a0f2"},
            {"repo_changeset_id": "733a77530961deeed0690c1b0993b8c064b07da4"},
            {"repo_changeset_id": "d3d45f7fa087c2c15742bd572ec45e01d1151911"}
        ],
        "columns": [{
            "type": "string",
            "friendly_name": "repo.changeset.id",
            "name": "repo_changeset_id"
        }]
    },
    "id": 90,
    "data_source_id": 1
}}

The column header shows, but no data shows. When I click on “TABLE”, the client sends HTTP GET to http://localhost:8080/api/queries/undefined. Hopefully these two problems have the same root.

I believe my query_runner is not returning all the required properties. What else am I doing wrong?


#5

No errors in the browser console?