Skip to main content
An S3Queue table has the virtual columns _path and _file. To store them with every ingested row, name them in the SELECT of the materialized view that reads from the queue, and insert them into ordinary columns of the target table. They are not part of SELECT *, which is why a view defined with SELECT * leaves such columns empty.

Example

The example uses the unordered mode, in which S3Queue tracks the processed files in ClickHouse Keeper, so the server needs a Keeper (or ZooKeeper) configuration. Replace the bucket URL and the credentials with your own.
source_path and source_file are regular columns of events: they are returned by SELECT * and can be used like any other column. Once files are ingested, you can for example count the rows that came from each file:
_path is the path of the file and _file is its name, the part of the path after the last /. The engine has more virtual columns, such as _size and _time. See the list of virtual columns.

Why the columns are empty with SELECT *

SELECT * never returns virtual columns. A view written as follows selects only id and message:
The rows are still inserted, but source_path and source_file get their default value, an empty string. If you want to keep the asterisk, add the virtual columns next to it:

Add the columns to an existing pipeline

If the queue, the target table and the view already exist, add the columns to the target table and change the query of the view with ALTER TABLE ... MODIFY QUERY:
S3Queue does not read a file again while the file is recorded as processed, so the rows that were ingested before the change keep empty values in the new columns. In the unordered mode that record is limited. ClickHouse Keeper keeps the records of at most tracked_files_limit processed files (1000 by default) and, if tracked_file_ttl_sec is set, only for that many seconds. A file that is still in the bucket when its record is removed is read again, and its rows are inserted a second time. To prevent this, use the after_processing setting to delete or move the files once they are ingested, or set tracked_files_limit higher than the number of files that the bucket will ever hold.