#pragma once #include #include #include #include namespace DB { using DiskPtr = std::shared_ptr; /// This class helps with the handling of temporary files or directories. /// A unique name for the temporary file or directory is automatically chosen based on a specified prefix. /// Create a directory in the constructor. /// The destructor always removes the temporary file or directory with all contained files. class TemporaryFileOnDisk { public: explicit TemporaryFileOnDisk(const DiskPtr & disk_, CurrentMetrics::Metric metric_scope); explicit TemporaryFileOnDisk(const DiskPtr & disk_, const String & prefix = "tmp"); ~TemporaryFileOnDisk(); DiskPtr getDisk() const { return disk; } /// Return absolute path (disk + relative_path) String getAbsolutePath() const; /// Return relative path (without disk) const String & getRelativePath() const { return relative_path; } private: DiskPtr disk; /// Relative path in disk to the temporary file or directory String relative_path; CurrentMetrics::Increment metric_increment; /// Specified if we know what for file is used (sort/aggregate/join). std::optional sub_metric_increment = {}; }; using TemporaryFileOnDiskHolder = std::unique_ptr; }