Closed mbeckerle closed 9 months ago
I found this works, but I don't know why the "['properties']" notation is needed vs. just "."
select t.feature['properties']['MAPBLKLOT'] as MAPBLKLOT from (SELECT flatten(features) as feature FROM dfs.`/tmp/citydata.json`) t;
select t.feature['properties']['MAPBLKLOT'] as MAPBLKLOT from (SELECT flatten(features) as feature FROM dfs.`/tmp/citydata.json`) t;
+-----------+
| MAPBLKLOT |
+-----------+
| 0001001 |
| 0002001 |
| 0004002 |
+-----------+
3 rows selected (0.128 seconds)
apache drill>
It appears 'properties' is a keyword. This works, note the backticks around properties
select t.feature.`properties` as property from (SELECT flatten(features) as feature FROM dfs.`/tmp/citydata.json`) t;
select t.feature.`properties` as property from (SELECT flatten(features) as feature FROM dfs.`/tmp/citydata.json`) t;
+----------------------------------------------------------------------------------+
| property |
+----------------------------------------------------------------------------------+
| {"MAPBLKLOT":"0001001","BLKLOT":"0001001","BLOCK_NUM":"0001","LOT_NUM":"001","FROM_ST":"0","TO_ST":"0","STREET":"UNKNOWN","ODD_EVEN":"E"} |
| {"MAPBLKLOT":"0002001","BLKLOT":"0002001","BLOCK_NUM":"0002","LOT_NUM":"001","FROM_ST":"0","TO_ST":"0","STREET":"UNKNOWN","ODD_EVEN":"E"} |
| {"MAPBLKLOT":"0004002","BLKLOT":"0004002","BLOCK_NUM":"0004","LOT_NUM":"002","FROM_ST":"0","TO_ST":"0","STREET":"UNKNOWN","ODD_EVEN":"E"} |
+----------------------------------------------------------------------------------+
3 rows selected (0.157 seconds)
apache drill (dfs.tmp)>
Sure enough 'PROPERTIES' is in the keywords list here: https://drill.apache.org/docs/reserved-keywords/
So the original JSON example query can be expressed as:
SELECT features[0].`properties`.MAPBLKLOT FROM `/tmp/citydata.json`;
Fixed in drill-site commit de30f12f4b37f73caac35660d0cae8f8d88f9b7a
@mbeckerle thanks for this!
Using drill 1.21
The example on page https://drill.apache.org/docs/json-data-model/ of querying the citylots.json does not work:
In addition, I've tried numerous variants of this query to see if I can find out what is wrong, but I can't get anything to work.
This much works:
But if I then try this in a sub-select to try to dig out the MAPBLKLOT....