#pragma once #include #include #include #include #include #include #include #include #include #include #include #include namespace DB { /* * BlockInputStream implementation for external dictionaries * read() returns single block consisting of the in-memory contents of the dictionaries */ template class DictionaryBlockInputStream : public DictionaryBlockInputStreamBase { public: using DictionatyPtr = std::shared_ptr; DictionaryBlockInputStream(std::shared_ptr dictionary, size_t max_block_size, PaddedPODArray && ids, const Names & column_names); DictionaryBlockInputStream(std::shared_ptr dictionary, size_t max_block_size, const std::vector & keys, const Names & column_names); using GetColumnsFunction = std::function& attributes)>; // Used to separate key columns format for storage and view. // Calls get_key_columns_function to get key column for dictionary get fuction call // and get_view_columns_function to get key representation. // Now used in trie dictionary, where columns are stored as ip and mask, and are showed as string DictionaryBlockInputStream(std::shared_ptr dictionary, size_t max_block_size, const Columns & data_columns, const Names & column_names, GetColumnsFunction && get_key_columns_function, GetColumnsFunction && get_view_columns_function); String getName() const override { return "DictionaryBlockInputStream"; } protected: Block getBlock(size_t start, size_t size) const override; private: // pointer types to getXXX functions // for single key dictionaries template using DictionaryGetter = void (DictionaryType::*)( const std::string &, const PaddedPODArray &, PaddedPODArray &) const; using DictionaryStringGetter = void (DictionaryType::*)( const std::string &, const PaddedPODArray &, ColumnString *) const; // for complex complex key dictionaries template using GetterByKey = void (DictionaryType::*)( const std::string &, const Columns &, const DataTypes &, PaddedPODArray & out) const; using StringGetterByKey = void (DictionaryType::*)( const std::string &, const Columns &, const DataTypes &, ColumnString * out) const; // call getXXX // for single key dictionaries template void callGetter(DictionaryGetter getter, const PaddedPODArray & ids, const Columns & keys, const DataTypes & data_types, Container & container, const DictionaryAttribute & attribute, const DictionaryType & dictionary) const; template void callGetter(DictionaryStringGetter getter, const PaddedPODArray & ids, const Columns & keys, const DataTypes & data_types, Container & container, const DictionaryAttribute & attribute, const DictionaryType & dictionary) const; // for complex complex key dictionaries template void callGetter(GetterByKey getter, const PaddedPODArray & ids, const Columns & keys, const DataTypes & data_types, Container & container, const DictionaryAttribute & attribute, const DictionaryType & dictionary) const; template void callGetter(StringGetterByKey getter, const PaddedPODArray & ids, const Columns & keys, const DataTypes & data_types, Container & container, const DictionaryAttribute & attribute, const DictionaryType & dictionary) const; template