> ## Documentation Index
> Fetch the complete documentation index at: https://clickhouse.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# كيفية الاستعلام عن ملفات Parquet

> تعرّف على كيفية الاستعلام عن ملفات Parquet باستخدام chDB.

يُخزَّن قدر كبير من بيانات العالم في حاويات Amazon S3.
في هذا الدليل، سنتعلّم كيفية الاستعلام عن هذه البيانات باستخدام chDB.

<div id="setup">
  ## الإعداد
</div>

لننشئ أولًا بيئة افتراضية:

```bash theme={null}
python -m venv .venv
source .venv/bin/activate
```

والآن سنثبّت chDB.
تأكّد من استخدام الإصدار 2.0.2 أو أحدث:

```bash theme={null}
pip install "chdb>=2.0.2"
```

والآن سنثبّت IPython:

```bash theme={null}
pip install ipython
```

سنستخدم `ipython` لتشغيل الأوامر في بقية هذا الدليل، ويمكنك تشغيله عبر تنفيذ:

```bash theme={null}
ipython
```

يمكنك أيضًا استخدام الشيفرة في برنامج نصي بلغة Python أو في دفتر ملاحظاتك المفضل.

<div id="exploring-parquet-metadata">
  ## استكشاف البيانات الوصفية لملف Parquet
</div>

سنستكشف ملف Parquet من مجموعة بيانات [مراجعات Amazon](/docs/ar/get-started/sample-datasets/amazon-reviews).
لكن أولًا، لِنُثبِّت `chDB`:

```python theme={null}
import chdb
```

عند الاستعلام عن ملفات Parquet، يمكننا استخدام تنسيق الإدخال [`ParquetMetadata`](/docs/ar/reference/formats/Parquet/ParquetMetadata) لإرجاع بيانات Parquet الوصفية بدلًا من محتوى الملف.
لنستخدم عبارة `DESCRIBE` للاطلاع على الحقول التي تُعاد عند استخدام هذا التنسيق:

```python theme={null}
query = """
DESCRIBE s3(
  'https://datasets-documentation.s3.eu-west-3.amazonaws.com/amazon_reviews/amazon_reviews_2015.snappy.parquet', 
  ParquetMetadata
)
SETTINGS describe_compact_output=1
"""

chdb.query(query, 'TabSeparated')
```

```text theme={null}
num_columns     UInt64
num_rows        UInt64
num_row_groups  UInt64
format_version  String
metadata_size   UInt64
total_uncompressed_size UInt64
total_compressed_size   UInt64
columns Array(Tuple(name String, path String, max_definition_level UInt64, max_repetition_level UInt64, physical_type String, logical_type String, compression String, total_uncompressed_size UInt64, total_compressed_size UInt64, space_saved String, encodings Array(String)))
row_groups      Array(Tuple(num_columns UInt64, num_rows UInt64, total_uncompressed_size UInt64, total_compressed_size UInt64, columns Array(Tuple(name String, path String, total_compressed_size UInt64, total_uncompressed_size UInt64, have_statistics Bool, statistics Tuple(num_values Nullable(UInt64), null_count Nullable(UInt64), distinct_count Nullable(UInt64), min Nullable(String), max Nullable(String))))))
```

لنلقِ الآن نظرة على البيانات الوصفية لهذا الملف.
يحتوي كلٌّ من `columns` و`row_groups` على مصفوفات من tuples تتضمن العديد من الخصائص، لذا سنستبعدهما مؤقتًا.

```python theme={null}
query = """
SELECT * EXCEPT(columns, row_groups)
FROM s3(
  'https://datasets-documentation.s3.eu-west-3.amazonaws.com/amazon_reviews/amazon_reviews_2015.snappy.parquet', 
  ParquetMetadata
)
"""

chdb.query(query, 'Vertical')
```

```text theme={null}
Row 1:
──────
num_columns:             15
num_rows:                41905631
num_row_groups:          42
format_version:          2.6
metadata_size:           79730
total_uncompressed_size: 14615827169
total_compressed_size:   9272262304
```

يتضح من هذا الناتج أن ملف Parquet هذا يحتوي على أكثر من 40 مليون صف، مقسّمة على 42 مجموعة صفوف، مع 15 عمودًا من البيانات في كل صف.
مجموعة الصفوف هي تقسيم أفقي منطقي للبيانات إلى صفوف.
ترتبط بيانات وصفية بكل مجموعة صفوف، ويمكن لأدوات الاستعلام الاستفادة من هذه البيانات الوصفية للاستعلام عن الملف بكفاءة.

لنلقِ نظرة على إحدى مجموعات الصفوف:

```python theme={null}
query = """
WITH rowGroups AS (
    SELECT rg
    FROM s3(
    'https://datasets-documentation.s3.eu-west-3.amazonaws.com/amazon_reviews/amazon_reviews_2015.snappy.parquet',
    ParquetMetadata
    )
    ARRAY JOIN row_groups AS rg
    LIMIT 1
)
SELECT tupleElement(c, 'name') AS name, tupleElement(c, 'total_compressed_size') AS total_compressed_size, 
       tupleElement(c, 'total_uncompressed_size') AS total_uncompressed_size,
       tupleElement(tupleElement(c, 'statistics'), 'min') AS min,
       tupleElement(tupleElement(c, 'statistics'), 'max') AS max
FROM rowGroups
ARRAY JOIN tupleElement(rg, 'columns') AS c
"""

chdb.query(query, 'DataFrame')
```

```text theme={null}
                 name  total_compressed_size  total_uncompressed_size                                                min                                                max
0         review_date                    493                      646                                              16455                                              16472
1         marketplace                     66                       64                                                 US                                                 US
2         customer_id                5207967                  7997207                                              10049                                           53096413
3           review_id               14748425                 17991290                                     R10004U8OQDOGE                                      RZZZUTBAV1RYI
4          product_id                8003456                 13969668                                         0000032050                                         BT00DDVMVQ
5      product_parent                5758251                  7974737                                                645                                          999999730
6       product_title               41068525                 63355320  ! Small S 1pc Black 1pc Navy (Blue) Replacemen...                            🌴 Vacation On The Beach
7    product_category                   1726                     1815                                            Apparel                                       Pet Products
8         star_rating                 369036                   374046                                                  1                                                  5
9       helpful_votes                 538940                  1022990                                                  0                                               3440
10        total_votes                 610902                  1080520                                                  0                                               3619
11               vine                  11426                   125999                                                  0                                                  1
12  verified_purchase                 102634                   125999                                                  0                                                  1
13    review_headline               16538189                 27634740                                                     🤹🏽‍♂️🎤Great product. Practice makes perfect. D...
14        review_body              145886383                232457911                                                                                              🚅 +🐧=💥 😀
```

<div id="querying-parquet-files">
  ## الاستعلام عن ملفات Parquet
</div>

بعد ذلك، لنستعلم عن محتويات الملف.
يمكننا فعل ذلك بتعديل الاستعلام أعلاه لإزالة `ParquetMetadata`، ثم، على سبيل المثال، حساب قيمة `star_rating` الأكثر شيوعًا بين جميع المراجعات:

```python theme={null}
query = """
SELECT star_rating, count() AS count, formatReadableQuantity(count)
FROM s3(
  'https://datasets-documentation.s3.eu-west-3.amazonaws.com/amazon_reviews/amazon_reviews_2015.snappy.parquet'
)
GROUP BY ALL
ORDER BY star_rating
"""

chdb.query(query, 'DataFrame')
```

```text theme={null}
   star_rating     count formatReadableQuantity(count())
0            1   3253070                    3.25 million
1            2   1865322                    1.87 million
2            3   3130345                    3.13 million
3            4   6578230                    6.58 million
4            5  27078664                   27.08 million
```

ومن اللافت للاهتمام أن عدد المراجعات ذات الخمس نجوم يفوق مجموع جميع التقييمات الأخرى!
ويبدو أن الناس يحبّون المنتجات على Amazon، أو أنهم إذا لم تعجبهم، فلا يقدّمون تقييمًا.
