จัดการ Components

การตรวจสอบคุณภาพข้อมูลด้วย Great Expectations เบื้องต้น

Davina Moossazadeh

Data Scientist

Components

GX components - คลาส Python ที่แทนข้อมูลและ entity การตรวจสอบข้อมูล

  • Data Context
  • Data Sources & Data Assets
  • Batch Definitions & Batches
  • Expectations
  • Expectation Suites
  • Validation Definitions
  • Checkpoints & Actions
  • Data Docs
1 https://docs.greatexpectations.io/docs/core/introduction/gx_overview
การตรวจสอบคุณภาพข้อมูลด้วย Great Expectations เบื้องต้น

การจัดการ Components ใน GX

Data Sources:

  • เชื่อมต่อกับข้อมูลและประกอบด้วย Data Assets

Expectation Suites:

  • รวบรวม Expectations

Validation Definitions:

  • ตรวจสอบ Expectations กับข้อมูล

Checkpoints:

  • จัดกลุ่มและทำให้ Validations เป็นอัตโนมัติ

context.data_sources

$$

context.suites

$$

context.validation_definitions

$$

context.checkpoints

การตรวจสอบคุณภาพข้อมูลด้วย Great Expectations เบื้องต้น

การเพิ่ม Components

Expectation Suite:

suite = context.suites.add(suite)

Validation Definition:

validation_definition = context.validation_definitions.add(validation_definition)

Checkpoint:

checkpoint = context.checkpoints.add(
    checkpoint=checkpoint
)
การตรวจสอบคุณภาพข้อมูลด้วย Great Expectations เบื้องต้น

การเพิ่ม Data Source

data_source = context.data_sources.add_<TYPE_NAME>()

1 https://docs.greatexpectations.io/docs/core/connect_to_data/
การตรวจสอบคุณภาพข้อมูลด้วย Great Expectations เบื้องต้น

การเพิ่ม pandas Data Source

ใช้ .add_pandas() เพื่อตั้งค่า Data Source สำหรับ pandas DataFrames ได้อย่างง่ายดาย:

data_source = context.data_sources.add_pandas(
    name="my_pandas_datasource"
)
การตรวจสอบคุณภาพข้อมูลด้วย Great Expectations เบื้องต้น

การดึง Components

ดึง components ด้วย .get() โดยระบุพารามิเตอร์ name:

context.<COMPONENT>s.get(

name: str )
data_source = context.data_sources.get(

name="my_pandas_datasource" )
print(data_source)
id: 46c91f1b-1db9-4351-b5dd-83e038c0f511
name: 'my_pandas_datasource'
type: pandas
การตรวจสอบคุณภาพข้อมูลด้วย Great Expectations เบื้องต้น

การดึง Components

Data Sources:

context.data_sources.get(
    name="my_pandas_datasource"
)

Expectation Suites:

context.suites.get(
    name="my_suite"
)

Validation Definitions:

context.validation_definitions.get(
    name="my_validation_definition"
)

Checkpoints:

context.checkpoints.get(
    name="my_checkpoint"
)
การตรวจสอบคุณภาพข้อมูลด้วย Great Expectations เบื้องต้น

การแสดงรายการ Components

ใช้ .all() เพื่อแสดงรายการ components ทั้งหมดใน Data Context รวมถึงชื่อและ metadata:

context.<COMPONENT>s.all()
data_sources = context.data_sources.all()

print(data_sources)
{
    'my_pandas_datasource': PandasDatasource(
        type='pandas',
        name='my_pandas_datasource', 
        id=UUID('c22b16f7-6945-400e-932f-026cbd63b112'), 
        assets=[]
    )
}
การตรวจสอบคุณภาพข้อมูลด้วย Great Expectations เบื้องต้น

การแสดงรายการ Components

Data Sources:

context.data_sources.all()

Expectation Suites:

context.suites.all()

Validation Definitions:

context.validation_definitions.all()

Checkpoints:

context.checkpoints.all()
การตรวจสอบคุณภาพข้อมูลด้วย Great Expectations เบื้องต้น

การลบ Components

ใช้ .delete() เพื่อลบ components โดยระบุชื่อ:

context.<COMPONENT>s.delete(

name: str )
context.data_sources.delete(
    name="my_pandas_datasource"
)

print(context.data_sources.all())
{}
การตรวจสอบคุณภาพข้อมูลด้วย Great Expectations เบื้องต้น

การลบ Components

Data Sources:

context.data_sources.delete(
    name="my_pandas_datasource"
)

Expectation Suites:

context.suites.delete(
    name="my_suite"
)

Validation Definitions:

context.validation_definitions.delete(
    name="my_validation_definition"
)

Checkpoints:

context.checkpoints.delete(
    name="my_checkpoint"
)
การตรวจสอบคุณภาพข้อมูลด้วย Great Expectations เบื้องต้น

สรุปคำสั่ง

เพิ่ม component เข้า Data Context:

context.data_sources.add(data_source)

context.suites.add(suite)

context.validation_definitions.add(
    validation_definition
)

context.checkpoints.add(checkpoint)

ดึง component:

.get(name: str)

แสดงรายการ components:

.all()

ลบ component:

.delete(name: str)
การตรวจสอบคุณภาพข้อมูลด้วย Great Expectations เบื้องต้น

มาฝึกกันเถอะ!

การตรวจสอบคุณภาพข้อมูลด้วย Great Expectations เบื้องต้น

Preparing Video For Download...