#pragma once #include "config.h" #if USE_AVRO #include #include #include #include #include #include #include #include #include namespace DB { class WriteBuffer; class AvroSerializerTraits; class AvroSerializer { public: AvroSerializer(const ColumnsWithTypeAndName & columns, std::unique_ptr, const FormatSettings & settings_); const avro::ValidSchema & getSchema() const { return valid_schema; } void serializeRow(const Columns & columns, size_t row_num, avro::Encoder & encoder); using SerializeFn = std::function; struct SchemaWithSerializeFn { avro::Schema schema; SerializeFn serialize; }; private: /// Type names for different complex types (e.g. enums, fixed strings) must be unique. We use simple incremental number to give them different names. SchemaWithSerializeFn createSchemaWithSerializeFn(const DataTypePtr & data_type, size_t & type_name_increment, const String & column_name); std::vector serialize_fns; avro::ValidSchema valid_schema; std::unique_ptr traits; const FormatSettings & settings; }; class AvroRowOutputFormat final : public IRowOutputFormat { public: AvroRowOutputFormat(WriteBuffer & out_, const Block & header_, const FormatSettings & settings_); ~AvroRowOutputFormat() override; String getName() const override { return "AvroRowOutputFormat"; } private: void write(const Columns & columns, size_t row_num) override; void writeField(const IColumn &, const ISerialization &, size_t) override {} void writePrefix() override; void finalizeImpl() override; void resetFormatterImpl() override; void createFileWriter(); FormatSettings settings; AvroSerializer serializer; std::unique_ptr file_writer_ptr; }; } #endif