本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
FileFreshness
FileFreshness 會根據您提供的條件,確保您的資料檔案是全新的。其使用您檔案的上次修改時間,來確保資料檔案或整個資料夾是最新的。
此規則會收集兩個指標:
-
根據您所設定規則的 FileFreshness 合規性
-
規則掃描的檔案數目
{"Dataset.*.FileFreshness.Compliance":1,"Dataset.*.FileCount":1}
異常偵測不會考慮這些指標。
檢查檔案新鮮度
下列規則可確保 tickets.parquet 在過去 24 小時內建立。
FileFreshness "s3://amzn-s3-demo-bucket/artifacts/file/tickets/tickets.parquet" > (now() - 24 hours)
檢查資料夾新鮮度
如果資料夾中的所有檔案都在過去 24 小時內建立或修改,則下列規則會通過。
FileFreshness "s3://bucket/" >= (now() -1 days) FileFreshness "s3://amzn-s3-demo-bucket/artifacts/file/tickets/" >= (now() - 24 hours)
使用閾值檢查資料夾或檔案新鮮度
如果資料夾 "tickets" 中有 10% 的檔案是在過去 10 天內建立或修改的,則下列規則會通過。
FileFreshness "s3://amzn-s3-demo-bucket/artifacts/file/tickets/" < (now() - 10 days) with threshold > 0.1
檢查具有特定日期的檔案或資料夾
您可以檢查特定日期的檔案新鮮度。
FileFreshness "s3://amzn-s3-demo-bucket/artifacts/file/tickets/" > "2020-01-01" FileFreshness "s3://amzn-s3-demo-bucket/artifacts/file/tickets/" between "2023-01-01" and "2024-01-01"
使用時間檢查檔案或資料夾
您可以使用 FileFreshness 來確保檔案已根據特定時間送達。
FileFreshness "s3://amzn-s3-demo-bucket/artifacts/file/tickets/" between now() and (now() - 45 minutes) FileFreshness "s3://amzn-s3-demo-bucket/artifacts/file/tickets/" between "9:30 AM" and "9:30 PM" FileFreshness "s3://amzn-s3-demo-bucket/artifacts/file/tickets/" > (now() - 10 minutes) FileFreshness "s3://amzn-s3-demo-bucket/artifacts/file/tickets/" > now() FileFreshness "s3://amzn-s3-demo-bucket/artifacts/file/tickets/" between (now() - 2 hours) and (now() + 15 minutes) FileFreshness "s3://amzn-s3-demo-bucket/artifacts/file/tickets/" between (now() - 3 days) and (now() + 15 minutes) FileFreshness "s3://amzn-s3-demo-bucket/artifacts/file/tickets/" between "2001-02-07" and (now() + 15 minutes) FileFreshness "s3://amzn-s3-demo-bucket/artifacts/file/tickets/" > "21:45"" FileFreshness "s3://amzn-s3-demo-bucket/artifacts/file/tickets/" > "2024-01-01" FileFreshness "s3://amzn-s3-demo-bucket/artifacts/file/tickets/" between "02:30" and "04:30" FileFreshness "s3://amzn-s3-demo-bucket/artifacts/file/tickets/" between "9:30 AM" and "22:15"
關鍵考量事項:
-
FileFreshness 可以使用天、小時及分鐘單位來評估檔案
-
有時,其支援上午/下午和 24 小時
-
除非指定覆寫,否則時間會以 UTC 計算
-
日期按 UTC 時間 00:00 計算
以時間為基礎的 FileFreshness 運作方式如下:
FileFreshness "s3://amzn-s3-demo-bucket/artifacts/file/tickets/" > "21:45"
-
首先,時間 "21:45" 會與 UTC 格式的今天日期合併,以建立日期時間欄位
-
接下來,日期時間會轉換為您指定的時區
-
最後,評估規則
選用的以檔案為基礎的規則標籤:
標籤可讓您控制規則行為。
recentFiles
此標籤會先保留最新的檔案,以限制處理的檔案數目。
FileFreshness "s3://amzn-s3-demo-bucket/" between (now() - 100 minutes) and (now() + 10 minutes) with recentFiles = 1
timeZone
接受的時區覆寫,請參閱允許的時區
FileFreshness "s3://path/" > "21:45" with timeZone = "America/New_York"
FileFreshness "s3://path/" > "21:45" with timeZone = "America/Chicago"
FileFreshness "s3://path/" > "21:45" with timeZone = "Europe/Paris"
FileFreshness "s3://path/" > "21:45" with timeZone = "Asia/Shanghai"
FileFreshness "s3://path/" > "21:45" with timeZone = "Australia/Darwin"
直接從資料框推斷檔案名稱
您不一定必須提供檔案路徑。例如,當您在 AWS Glue Data Catalog 中撰寫規則時,可能很難找到型錄資料表正在使用的資料夾。AWSGlue Data Quality 可以找到用來填入資料框的特定資料夾或檔案,並可以偵測其是否新鮮。
注意
此功能只有在檔案成功讀取到 DynamicFrame 或 DataFrame 時才有效。
FileFreshness > (now() - 24 hours)
此規則會尋找用來填入動態框架或資料框的資料夾路徑或檔案。這適用於 Amazon S3 路徑或以 Amazon S3 為基礎的 AWS Glue Data Catalog 資料表。有幾個考量:
-
在 AWS Glue ETL 中,您必須在 Amazon S3 或 AWS Glue Data Catalog 轉換後立即進行 EvaluateDataQuality 轉換。
-
此規則無法在 AWS Glue 互動式工作階段中運作。
如果您在這兩種情況下嘗試這麼做,或 AWS Glue 找不到檔案時,Glue AWS 會擲回下列錯誤:“Unable to parse file path from DataFrame”