MCPcopy Create free account
hub / github.com/ClickHouse/ClickHouse / match

Method match

src/Dictionaries/RegExpTreeDictionary.cpp:685–869  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

683};
684
685UnorderedMapWithMemoryTracking<String, ColumnPtr> RegExpTreeDictionary::match(
686 const ColumnString::Chars & keys_data,
687 const ColumnString::Offsets & keys_offsets,
688 const UnorderedMapWithMemoryTracking<String, const DictionaryAttribute &> & attributes,
689 DefaultMapOrFilter default_or_filter,
690 std::optional<size_t> collect_values_limit) const
691{
692 bool is_short_circuit = std::holds_alternative<RefFilter>(default_or_filter);
693 chassert(is_short_circuit || std::holds_alternative<RefDefaultMap>(default_or_filter));
694
695#if USE_VECTORSCAN
696 hs_scratch_t * scratch = nullptr;
697 if (use_vectorscan)
698 {
699 hs_error_t err = hs_clone_scratch(origin_scratch.get(), &scratch);
700
701 if (err != HS_SUCCESS)
702 {
703 throw Exception(ErrorCodes::CANNOT_ALLOCATE_MEMORY, "Could not clone scratch space for hyperscan");
704 }
705 }
706
707 MultiRegexps::ScratchPtr smart_scratch(scratch);
708#endif
709
710 UnorderedMapWithMemoryTracking<String, MutableColumnPtr> columns;
711
712 size_t input_rows_count = keys_offsets.size();
713
714 /// initialize columns
715 for (const auto & [name_, attr] : attributes)
716 {
717 auto col_ptr = (collect_values_limit ? std::make_shared<DataTypeArray>(attr.type) : attr.type)->createColumn();
718 col_ptr->reserve(input_rows_count);
719 columns[name_] = std::move(col_ptr);
720 }
721
722 std::optional<RefDefaultMap> default_map;
723 std::optional<RefFilter> default_mask;
724 if (is_short_circuit)
725 {
726 default_mask = std::get<RefFilter>(default_or_filter).get();
727 default_mask.value().get().resize(keys_offsets.size());
728 }
729 else
730 {
731 default_map = std::get<RefDefaultMap>(default_or_filter).get();
732 }
733
734 UInt64 curr_offset = 0;
735 for (size_t key_idx = 0; key_idx < input_rows_count; ++key_idx)
736 {
737 auto next_offset = keys_offsets[key_idx];
738 UInt64 length = next_offset - curr_offset;
739
740 const char * begin = reinterpret_cast<const char *>(keys_data.data()) + curr_offset;
741
742 MatchContext match_result(regexp_ids, topology_order, begin, length, regex_nodes);

Callers 1

insertIdxMethod · 0.45

Calls 15

insertIdxMethod · 0.80
insertNodeIDMethod · 0.80
ExceptionClass · 0.50
StringClass · 0.50
DataTypeArrayClass · 0.50
getMethod · 0.45
sizeMethod · 0.45
createColumnMethod · 0.45
reserveMethod · 0.45
resizeMethod · 0.45
valueMethod · 0.45
dataMethod · 0.45

Tested by

no test coverage detected