亚马逊雅典娜创建带有分区的请求

时间:2018-08-06 19:00:00

标签: sql amazon-s3 amazon-athena

我创建一个具有如下分区的表:首先按年,月和日。

问题:我希望获得12/2017和03/2018的数据,我该怎么做? 我的想法:

where (year='2017' and month='12') and ( year ='2018' and month='03')

对吗?我不会感到困惑,因此Amazon Athena可以获取以下数据:

12/2017 and 03/2018 and 03/2017 and 12/2018 

由于运算符?

PS:我无法测试,我只有免费帐户。 谢谢。

1 个答案:

答案 0 :(得分:1)

无论如何,我尝试了一组小型数据,但发现Amazon Athena考虑了括号。

我的测试如下:  表的DDl如已定标:

        <v-btn  block outline color="indigo" class="no-text-transform">
          <span style="white-space: normal;">
            Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam nec dapibus augue.
          </span>
        </v-btn>

我的一组数据测试: enter image description here

我的测试:

1- CREATE EXTERNAL TABLE `manyands`( `years` int COMMENT 'from deserializer', `months` int COMMENT 'from deserializer', `days` int COMMENT 'from deserializer') PARTITIONED BY ( `year` string, `month` string) ROW FORMAT SERDE 'org.openx.data.jsonserde.JsonSerDe' STORED AS INPUTFORMAT 'org.apache.hadoop.mapred.TextInputFormat' OUTPUTFORMAT 'org.apache.hadoop.hive.ql.io.IgnoreKeyTextOutputFormat' LOCATION 's3://mybucket/' 我采用CSV格式:

SELECT * FROM "atlasdatabase"."manyands" where month='1';

2- "years","months","days","year","month" "2017","1","21","2017","1" "2018","1","81","2018","1"

SELECT * FROM "atlasdatabase"."manyands" where month='1' and year='2017';

3- "years","months","days","year","month" "2017","1","21","2017","1"

SELECT * FROM "atlasdatabase"."manyands" where (month='1'  and year='2018') and (month='3'  and year='2017') ;

4- empty (Zéro enregistrements renvoyés)

SELECT * FROM "atlasdatabase"."manyands" where (month='1'  and year='2018') or (month='3' ) ;

结论:在分区的许多实例之间添加 OR 运算符。