#include #include #include #include #include #include namespace DB { namespace { struct FilesystemAvailable { static constexpr auto name = "filesystemAvailable"; static std::uintmax_t get(const std::filesystem::space_info & spaceinfo) { return spaceinfo.available; } }; struct FilesystemFree { static constexpr auto name = "filesystemFree"; static std::uintmax_t get(const std::filesystem::space_info & spaceinfo) { return spaceinfo.free; } }; struct FilesystemCapacity { static constexpr auto name = "filesystemCapacity"; static std::uintmax_t get(const std::filesystem::space_info & spaceinfo) { return spaceinfo.capacity; } }; template class FilesystemImpl : public IFunction { public: static constexpr auto name = Impl::name; static FunctionPtr create(const Context & context) { return std::make_shared>(std::filesystem::space(context.getConfigRef().getString("path"))); } explicit FilesystemImpl(std::filesystem::space_info spaceinfo_) : spaceinfo(spaceinfo_) { } String getName() const override { return name; } size_t getNumberOfArguments() const override { return 0; } bool isDeterministic() const override { return false; } DataTypePtr getReturnTypeImpl(const DataTypes & /*arguments*/) const override { return std::make_shared(); } void executeImpl(Block & block, const ColumnNumbers &, size_t result, size_t input_rows_count) const override { block.getByPosition(result).column = DataTypeUInt64().createColumnConst(input_rows_count, static_cast(Impl::get(spaceinfo))); } private: std::filesystem::space_info spaceinfo; }; } void registerFunctionFilesystem(FunctionFactory & factory) { factory.registerFunction>(); factory.registerFunction>(); factory.registerFunction>(); } }