English 中文(简体)
当FIXED_LEN_BYTE_ARRAY数据类型用于固定长度的平面阵列时,为什么会有更多的 par子?
原标题:Why would a parquet file get larger when FIXED_LEN_BYTE_ARRAY data type is used for fixed length byte array column?

在试图将数据集存放在按区域分类的档案中,以将其上载到HuggingFace I ve时遇到了一种奇怪的现象:在将50-byte阵列作为一栏时,文档尺寸在>时,而不是使用<编码>。 BYTE_ARRAY。

这里的《 code法》表明:

import os
import numpy as np
import pyarrow as pa
import pyarrow.parquet as pq

tmp_dir = os.path.expanduser("~/tmp/pq") # directory for example files to be stored
n_bytes = 50
n_records = 4096 * 126
np_rng = np.random.default_rng(1)
array = np.frombuffer(
    np_rng.bytes(n_bytes * n_records), dtype=np.dtype((np.bytes_, n_bytes)))
table_byte_array = pa.Table.from_pydict({ byte_data : array})
pq.write_table(table_byte_array, f {tmp_dir}/byte_array_example.parquet )
table_fixed_len_byte_array = pa.Table.from_pydict(
    { byte_data : array},
    schema=pa.schema([
        pa.field( byte_data , pa.binary(array.itemsize), nullable=False)]))
pq.write_table(
    table_fixed_len_byte_array,
    f {tmp_dir}/fixed_len_byte_array_example.parquet )
file_sizes = []
for name in [ byte_array ,  fixed_len_byte_array ]:
    filename = f {tmp_dir}/{name}_example.parquet 
    table = pq.read_table(filename)
    file_size = os.path.getsize(filename)
    file_sizes.append(file_size)
    print(f {name}: {table.schema.field("byte_data").type} {file_size} )
print(
    f size ratio: {file_sizes[1] / file_sizes[0]:.3f};  
    f size diff: {file_sizes[1] - file_sizes[0]} )

文件:

byte_array: binary 25493170
fixed_len_byte_array: fixed_size_binary[50] 25850348
size ratio: 1.014; size diff: 357178

这似乎非常具有反面性:没有固定长度(即储存较少数据)导致档案规模扩大。 为什么情况如此?


用于上述测试的系统:Ubraham 22,04.4 LTS;3,10.11;pyarrow edition 12.0.1(使用12.0.1)。 在研究<代码>pqrs schema <name>_example.parquet -detailed的产出时,请参看<编码>encoding。 两卷:<代码>编码:编码 RLE_DITION PLAIN RLE PLAIN。

问题回答




相关问题
Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

An enterprise scheduler for python (like quartz)

I am looking for an enterprise tasks scheduler for python, like quartz is for Java. Requirements: Persistent: if the process restarts or the machine restarts, then all the jobs must stay there and ...

How to remove unique, then duplicate dictionaries in a list?

Given the following list that contains some duplicate and some unique dictionaries, what is the best method to remove unique dictionaries first, then reduce the duplicate dictionaries to single ...

What is suggested seed value to use with random.seed()?

Simple enough question: I m using python random module to generate random integers. I want to know what is the suggested value to use with the random.seed() function? Currently I am letting this ...

How can I make the PyDev editor selectively ignore errors?

I m using PyDev under Eclipse to write some Jython code. I ve got numerous instances where I need to do something like this: import com.work.project.component.client.Interface.ISubInterface as ...

How do I profile `paster serve` s startup time?

Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

Converting Dictionary to List? [duplicate]

I m trying to convert a Python dictionary into a Python list, in order to perform some calculations. #My dictionary dict = {} dict[ Capital ]="London" dict[ Food ]="Fish&Chips" dict[ 2012 ]="...

热门标签