问题
Learning Google FusionTables, so possibly making a very beginner mistake. I get correct results when querying Google Fusion Tables via the ChartTools API but not via the Ajax API. Strangely, it gives correct results for part of the query, just not all of it. Am I making a mistake?
Chart Tools API works:
Querying Google FusionTable via the Chart Tools API seems to work fine, albeit with a 500 row limit. For instance, this query: SELECT ETHUN, COUNT() FROM 1Nynh5pPrj1q8JqbalppAm-qzAsgKvL0ZRala7VI GROUP BY ETHUN
Using the Google Chart Tools API, the URL is http://www.google.com/fusiontables/gvizdata?tq=SELECT%20ETHUN%2C%20COUNT()%20%20FROM%201Nynh5pPrj1q8JqbalppAm-qzAsgKvL0ZRala7VI%20GROUP%20BY%20ETHUN&tqx=reqId%3A0, which returns a JSON function:
google.visualization.Query.setResponse({
version:'0.5',
reqId:'0',status:'ok',
table:{
p:{totalrows:3},
cols:[
{id:'col6',label:'ETHUN',type:'number'},
{id:'#agg#COUNT',label:'count()',type:'number'}
],
rows:[
{c:[{v:1.0},{v:3308.0}]}
{c:[{v:2.0},{v:18702.0}]},
{c:[{v:-9.0},{v:10768.0}]},
]
}
})
In particular, note the values {1,2,-9} as the values for ETHUN.
New FusionTables API doesnt work: On the other hand, making the same query via the Ajax API returns correct frequencies but NaN for the values themselves that the frequencies describe: https://www.googleapis.com/fusiontables/v1/query?sql=SELECT%20ETHUN%2C%20COUNT()%20%20FROM%201Nynh5pPrj1q8JqbalppAm-qzAsgKvL0ZRala7VI%20GROUP%20BY%20ETHUN&key=AIzaSyBT_ZCriV-Tm78KsJiQp6KKhjDwMhP0tYM
Which returns this JSON:
{
"kind": "fusiontables#sqlresponse",
"columns": [ "ETHUN", "count()" ],
"rows": [
[ NaN, "3308" ]
[ NaN, "18702" ],
[ NaN, "10768" ],
]
}
Why might it be giving me NaN's instead of {1, 2, -9} ?
Update: I now believe this issue is unique to the new Fusion Tables SQL, question slightly edited.
(Here's the link to the example Fusion Table)
Fusion Tables SQL API (now deprecated) also works
Strangely this link also works fine, https://www.google.com/fusiontables/api/query?sql=SELECT%20ETHUN,%20COUNT%28%29%20FROM%204579147%20GROUP%20BY%20ETHUN&alt=json-in-script&jsonCallback=onResponse and returns the following JSONP response with yet another format:
onResponse({"table":{"cols":["ETHUN","count()"],"rows":[["2",18702],["-9",10768],["1",3308]]}})
回答1:
This appears to be a bug with Google Fusion Tables API v1.0. This error is specific to numeric fields. Ajax is able to correctly query String fields just fine. Just this dataset has mostly numeric fields.
- NaN: SELECT SEX, COUNT() FROM .. GROUP BY SEX (integer field)
- NaN: SELECT AGE, COUNT() FROM .. GROUP BY AGE (integer field)
- Ok: SELECT RFV1, COUNT() FROM .. GROUP BY RFV1 (string field)
- Ok: SELECT DIAG1, COUNT() FROM .. GROUP BY DIAG1 (string field)
来源:https://stackoverflow.com/questions/11533395/partially-incorrect-results-from-google-fusion-table-via-ajax-but-correct-via-c