最新偏移

回傳在讀取限制下最近的偏移量。

start偏移量可用來決定在限制下應讀取多少新資料。 對於第一個微批次,則 start 由返回值 initialOffset()提供。 後續的微批次則從上一次微批次延續。 如果沒有資料需要處理,來源可以回傳與起始偏移相同的偏移量。

ReadLimit 來源可用來限制回傳的資料量。 如果來源能根據來源選項限制資料,請實施 getDefaultReadLimit() 適當的 ReadLimit 資訊。

即使來源產生的讀取限制latestOffset()與 不同,引擎仍可呼叫 ReadAllAvailablegetDefaultReadLimit() 來源必須始終尊重引擎所提供的 ReadLimit 條件。

新增於 Databricks Runtime 15.2

語法

latestOffset(start: dict, limit: ReadLimit)

參數

參數 類型 說明
start dict 這是微批次的起始偏移量,可以繼續閱讀。
limit 閱讀極限 此通話回傳資料量的限制。

退貨

dict

一個鍵與值為原始型別的字條或遞迴字條,包括整數、字串和布林。

Examples

from pyspark.sql.streaming.datasource import ReadAllAvailable, ReadMaxRows

def latestOffset(self, start, limit):
    # Assume the source has 10 new records between start and latest offset
    if isinstance(limit, ReadAllAvailable):
        return {"index": start["index"] + 10}
    else:  # e.g., limit is ReadMaxRows(5)
        return {"index": start["index"] + min(10, limit.maxRows)}