-- Given a user-defined schema over a raw JSON changelog, returns the -- schema elements of the latest set of live documents in the collection. -- timestamp: The Firestore timestamp at which the event took place. -- operation: One of INSERT, UPDATE, DELETE, IMPORT. -- event_id: The event that wrote this row. -- : This can be one, many, or no typed-columns -- corresponding to fields defined in the schema. SELECT document_name, document_id, timestamp, operation FROM ( SELECT document_name, document_id, FIRST_VALUE(timestamp) OVER( PARTITION BY document_name ORDER BY timestamp DESC ) AS timestamp, FIRST_VALUE(operation) OVER( PARTITION BY document_name ORDER BY timestamp DESC ) AS operation, FIRST_VALUE(operation) OVER( PARTITION BY document_name ORDER BY timestamp DESC ) = "DELETE" AS is_deleted FROM `test.test_dataset.test_table` ) WHERE NOT is_deleted GROUP BY document_name, document_id, timestamp, operation