2.4.7 特定のオフセットからのKafkaデータの検索
Oracle SQL access to Kafka (OSaK)では、特定のオフセットから、指定した数だけレコードを読み取ることができます。このタイプのアクセスは、1つのKafkaトピック/パーティションごとに1つのビューを作成するアプリケーションのみに限定されています。
次の例では、SEEKAPPという名前の新しいアプリケーションについて1つのビューを作成して、CSV形式のレコードを含むsensorトピックを問い合せます。この例では、SEEK_OFFSET
プロシージャを使用してオフセット100393を指定した後、1000件のレコードを問い合せます。使用可能なレコードが1000件未満の場合は、使用可能なすべてのレコードを問い合せます。
-- First create views for the seek application
DECLARE
views_created INTEGER;
application_id VARCHAR2(128);
BEGIN
ORA_KAFKA.CREATE_VIEWS
('MA1', -- The name of the cluster
'SEEKAPP', -- The name of the Kafka group
'sensor', -- The name of the Kafka topic
'CSV', -- The format of the topic record
'SENSOR_RECORD_SHAPE', -- The name of the database reference table
views_created, -- Output: number of views created
application_id, -- Output: the application id of the set of views
-- created that uniquely identifies the view
-- objects
0); -- The number of views to create. 0, the default,
-- requests the creation of 1 view per
-- Kafka partition
dbms_output.put_line(‘views created = ‘ || views_created);
dbms_output.put_line(‘application id = ‘ || application_id);
END;
/
-- Next we seek to offset 100393
SQL> execute ORA_KAFKA.SEEK_OFFSET
('KV_MA1_SEEKAPP_SENSOR_0', -- The name of the OSAK view that maps to a
-- single cluster/topic/partition
100393, -- The offset to which to seek
1000); -- The number of Kafka rows starting from the
-- offset to be retrieved
-- Now query for at most 1000 rows starting at offset 100393
SQL> SELECT max(temperature) from KV_MA1_SEEKAPP_SENSOR_0;