إنتقل إلى المحتوى الرئيسي

الفصل 3: جودة البيانات والتحقق من صحتها

Great Expectations​

Great Expectations هي مكتبة بايثون للتحقق من صحة البيانات وتوثيقها وتحليلها.

الإعداد والاستخدام الأساسي​

import great_expectations as gx
from great_expectations.core.batch import BatchRequest

# إنشاء السياق
context = gx.get_context()

# إنشاء مجموعة التوقعات
suite = context.create_expectation_suite("customer_data_suite")

# الحصول على المدقق
validator = context.get_validator(
batch_request=BatchRequest(
datasource_name="my_datasource",
data_connector_name="default",
data_asset_name="customers"
),
expectation_suite_name="customer_data_suite"
)

# إضافة التوقعات
validator.expect_column_values_to_not_be_null("customer_id")
validator.expect_column_values_to_be_between("age", min_value=18, max_value=120)
validator.expect_column_values_to_be_unique("email")
validator.expect_column_values_to_match_regex("phone", r"^\+?[0-9]{10,15}$")

# تشغيل التحقق
results = validator.validate()
print(f"Success: {results.success}")

عقود البيانات​

# data_contract.yaml
contract:
name: customer_features
version: "1.0.0"
owner: data-engineering@company.com

schema:
customer_id:
type: string
nullable: false
unique: true
age:
type: integer
min: 18
max: 120
email:
type: string
format: email
nullable: false

quality:
completeness: 0.99
freshness: "1 hour"

sla:
availability: "99.9%"
update_frequency: "hourly"

النقاط الرئيسية​

ملخص
  1. تحقق من صحة البيانات في كل مرحلة من مراحل خط الأنابيب
  2. استخدم عقود البيانات بين الفرق
  3. راقب الانحراف باستمرار
  4. افشل بسرعة عند وجود مشكلات في الجودة

التالي: اختبار الوحدة 4