小编Shi*_*kan的帖子

查询按年、月、日分区的 Athena 表

我有一个按年、月、日分区的 Athena 表,其定义如下

CREATE EXTERNAL TABLE `my_table`(
    `price` double) 
PARTITIONED BY ( 
    `year` int, 
    `month` int, 
    `day` int) 
ROW FORMAT SERDE 
    'org.apache.hadoop.hive.ql.io.parquet.serde.ParquetHiveSerDe' 
STORED AS INPUTFORMAT 
    'org.apache.hadoop.hive.ql.io.parquet.MapredParquetInputFormat' 
OUTPUTFORMAT 
    'org.apache.hadoop.hive.ql.io.parquet.MapredParquetOutputFormat'
Run Code Online (Sandbox Code Playgroud)

我需要在日期之间查询它。据我所知,选项例如是:

SELECT avg(price) 
FROM my_table 
WHERE year = 2018 AND month = 1
Run Code Online (Sandbox Code Playgroud)

结果:运行时间:4.89 秒,扫描数据:20.72MB

SELECT avg(price) 
FROM my_table 
WHERE cast(date_parse(concat(cast(year as varchar(4)),'-',
                             cast(month as varchar(2)),'-',
                             cast(day as varchar(2))
                             ), '%Y-%m-%d') as date) 
BETWEEN Date '2018-01-01' AND Date '2018-01-31'
Run Code Online (Sandbox Code Playgroud)

结果:运行时间:8.64 秒,扫描数据:20.72MB

因此,我猜 Athena 足够聪明,即使在转换串联分区列时也能使用分区功能,那么为什么它需要大约 10 分钟。两次?后台究竟发生了什么?

非常感谢。

amazon-web-services presto amazon-athena

7
推荐指数
1
解决办法
3694
查看次数

使用队列导致asyncio异常"将Future <Future pending>附加到不同的循环"

我正在尝试使用asyncio队列运行这个简单的代码,但是捕获异常,甚至嵌套异常.

我希望得到一些帮助,使asyncio中的队列正常工作:

import asyncio, logging

logging.basicConfig(level=logging.DEBUG)
logging.getLogger("asyncio").setLevel(logging.WARNING)


num_workers = 1
in_queue = asyncio.Queue()
out_queue = asyncio.Queue()
tasks = []


async def run():
    for request in range(1):
        await in_queue.put(request)

    # each task consumes from 'input_queue' and produces to 'output_queue':
    for i in range(num_workers):
        tasks.append(asyncio.create_task(worker(name=f'worker-{i}')))
    # tasks.append(asyncio.create_task(saver()))

    print('waiting for queues...')
    await in_queue.join()
    # await out_queue.join()
    print('all queues done')

    for task in tasks:
        task.cancel()
    print('waiting until all tasks cancelled')
    await asyncio.gather(*tasks, return_exceptions=True)
    print('done')


async def worker(name):
    while True:
        try:
            print(f"{name} started")
            num = …
Run Code Online (Sandbox Code Playgroud)

python python-3.x python-asyncio

4
推荐指数
1
解决办法
3079
查看次数

使用另一个数组(C#)初始化某种类型的数组

这是我的问题:假设我有一个带有这样一个构造函数的类:

Class A {
   private int i;
   public A(int new_i) {
      i = new_i;
   }
}
Run Code Online (Sandbox Code Playgroud)

我可以使用int数组初始化A数组吗?如果是这样,我该怎么办?我想的是:

int[] b = new int[5] { 0,1,2,3,4}; 
A[] a; 
a = new A[](b);
Run Code Online (Sandbox Code Playgroud)

谢谢!

c#

1
推荐指数
1
解决办法
63
查看次数

是否可以从刚刚引发异常的方法访问对象?

例如这段代码:

def foo():
    x = 5
    raise

def bar():
    try:
        foo()
    except:
        # access x here
Run Code Online (Sandbox Code Playgroud)

是否可以以某种方式访问​​ x ?谢谢。

python exception

0
推荐指数
1
解决办法
104
查看次数