SELECT _.city, travel-sample.inventory.airport.airportname,
_.ANN
FROM travel-sample.inventory.airport
JOIN (
SELECT *
FROM analysis.additional_data.temperatures
JOIN analysis.additional_data.cities ON analysis.additional_data.temperatures.state = analysis.additional_data.cities.state_id) AS _ ON travel-sample.inventory.airport.city = _.city;
The problem being a returned error as such:
[
{
“code”: 24042,
“msg”: “Cannot resolve ambiguous alias reference for identifier analysis (in line 8, at column 47)”,
“query_from_user”: “SELECT _.city,\n travel-sample.inventory.airport.airportname,\n _.ANN\nFROM travel-sample.inventory.airport\n JOIN (\n SELECT *\n FROM analysis.additional_data.temperatures\n JOIN analysis.additional_data.cities ON analysis.additional_data.temperatures.state = analysis.additional_data.cities.state_id) AS _ ON travel-sample.inventory.airport.city = _.city;”
}
]
The travel-sample is a bucket and the analysis one is another bucket. Can we make queries on data from different buckets ?
You can’t provide full multi-part qualification of fields - you must refer to them as alias.field; so try:
SELECT _.city, airport.airportname, _.ANN
FROM `travel-sample`.inventory.airport
JOIN
(
SELECT *
FROM analysis.additional_data.temperatures
JOIN analysis.additional_data.cities
ON temperatures.state = cities.state_id
) AS _
ON airport.city = _.city
(Of course you’ll need appropriate indices to support the query.)
Your INSERT would be:
INSERT INTO analysis.additional_data.airport (KEY _k, VALUE _v)
SELECT META().id _k, _v
FROM `travel-sample` _v
WHERE type = 'airport'
You have to quote any field or keyspace etc. name that includes a minus sign using Grave Accent (“backtick”) characters; i.e.
`travel-sample`
always. This certainly works for me:
cbq> INSERT INTO analysis.additional_data.airport (KEY _k, VALUE _v)
2 SELECT META().id _k, _v
3 FROM `travel-sample` _v
4 WHERE type = 'airport';
{
"requestID": "9839e375-9897-4bba-a847-e41971c1c670",
"signature": null,
"results": [
],
"status": "success",
"metrics": {
"elapsedTime": "348.539458ms",
"executionTime": "348.449651ms",
"resultCount": 0,
"resultSize": 0,
"serviceLoad": 3,
"mutationCount": 1968
}
}
You can join across buckets. Your example SELECT does just that - joining analysis and travel-sample and runs without error when the correct indices exist.