侧视图爆炸产生笛卡尔积

时间:2014-03-03 11:28:07

标签: join view hive hiveql lateral

我的数据集如下:

{
    "markers":{
        "marker":[
            {
                "id":"3540A",
                "lt":"28.46880448",
                "ln":"77.09402561",
                "speed":"25.7657263185792",
                "brng":"359.3928885",
                "time":"1392975226"
            },
            {
                "id":"3549B",
                "lt":"28.46207019",
                "ln":"77.08945513",
                "speed":"16.7443583120476",
                "brng":"254.4740405",
                "time":"1392975227"
            },
            {
                "id":"3554B",
                "lt":"28.51104306",
                "ln":"77.09399343",
                "speed":"46.8510996103777",
                "brng":"161.7287907",
                "time":"1392975205"
            },
            {
                "id":"3564A",
                "lt":"28.4964115",
                "ln":"77.08691239",
                "speed":"42.9285245904275",
                "brng":"39.96777172",
                "time":"1392975204"
            }
        ]
    }
}

我正在使用查询:

CREATE TABLE test AS 
SELECT id,speed
FROM raw_data 
LATERAL VIEW explode (markers.marker.id)id as id
LATERAL VIEW explode (markers.marker.speed)speed as speed;

这给了我一个id和速度的笛卡尔积。有人可以建议我该怎样摆脱这个。

1 个答案:

答案 0 :(得分:1)

我认为这应该有效:

SELECT s.id, s.speed FROM raw_data LATERAL VIEW explode(markers.marker) s as s;

不要做多个横向视图,只需做一个得到整个结构,然后选择该结构的各个字段。