// Copyright 2023 PingCAP, Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. #pragma once #include #include namespace DB { class WriteBuffer; /** A stream for outputting data in tsv format. */ class TabSeparatedRowOutputStream : public IRowOutputStream { public: /** with_names - output in the first line a header with column names * with_types - output the next line header with the names of the types */ TabSeparatedRowOutputStream( WriteBuffer & ostr_, const Block & sample_, bool with_names_ = false, bool with_types_ = false); void writeField(const IColumn & column, const IDataType & type, size_t row_num) override; void writeFieldDelimiter() override; void writeRowEndDelimiter() override; void writePrefix() override; void writeSuffix() override; void flush() override; void setExtremes(const Block & extremes_) override { extremes = extremes_; } /// https://www.iana.org/assignments/media-types/text/tab-separated-values String getContentType() const override { return "text/tab-separated-values; charset=UTF-8"; } protected: void writeExtremes(); WriteBuffer & ostr; const Block sample; bool with_names; bool with_types; Block extremes; }; } // namespace DB