@@ -134,27 +134,48 @@ Result<std::shared_ptr<GlobalIndexEvaluator>> GlobalIndexScanImpl::GetOrCreateIn
134134Result<std::vector<std::shared_ptr<GlobalIndexReader>>> GlobalIndexScanImpl::CreateReaders (
135135 int32_t field_id, const std::optional<RowRangeIndex>& row_range_index) const {
136136 PAIMON_ASSIGN_OR_RAISE (DataField field, table_schema_->GetField (field_id));
137- return CreateReaders (field, row_range_index);
137+ return CreateReaders (field, /* index_type= */ std:: nullopt , row_range_index);
138138}
139139
140140Result<std::vector<std::shared_ptr<GlobalIndexReader>>> GlobalIndexScanImpl::CreateReaders (
141141 const std::string& field_name, const std::optional<RowRangeIndex>& row_range_index) const {
142142 PAIMON_ASSIGN_OR_RAISE (DataField field, table_schema_->GetField (field_name));
143- return CreateReaders (field, row_range_index);
143+ return CreateReaders (field, /* index_type=*/ std::nullopt , row_range_index);
144+ }
145+
146+ Result<std::shared_ptr<GlobalIndexReader>> GlobalIndexScanImpl::CreateReader (
147+ const std::string& field_name, const std::string& index_type,
148+ const std::optional<RowRangeIndex>& row_range_index) const {
149+ PAIMON_ASSIGN_OR_RAISE (DataField field, table_schema_->GetField (field_name));
150+ PAIMON_ASSIGN_OR_RAISE (
151+ std::vector<std::shared_ptr<GlobalIndexReader>> readers,
152+ CreateReaders (field, std::optional<std::string>(index_type), row_range_index));
153+ if (readers.empty ()) {
154+ return std::shared_ptr<GlobalIndexReader>();
155+ }
156+ if (readers.size () != 1 ) {
157+ return Status::Invalid (
158+ fmt::format (" invalid global index reader size, expected 1, actual {}" , readers.size ()));
159+ }
160+ return readers[0 ];
144161}
145162
146163Result<std::vector<std::shared_ptr<GlobalIndexReader>>> GlobalIndexScanImpl::CreateReaders (
147- const DataField& field, const std::optional<RowRangeIndex>& row_range_index) const {
164+ const DataField& field, const std::optional<std::string>& index_type,
165+ const std::optional<RowRangeIndex>& row_range_index) const {
148166 auto field_iter = index_metas_.find (field.Id ());
149167 if (field_iter == index_metas_.end ()) {
150168 return std::vector<std::shared_ptr<GlobalIndexReader>>();
151169 }
152170 const auto & index_type_to_metas = field_iter->second ;
153171 std::vector<std::shared_ptr<GlobalIndexReader>> readers;
154- readers.reserve (index_type_to_metas.size ());
155- for (const auto & [index_type, range_to_metas] : index_type_to_metas) {
172+ readers.reserve (index_type ? 1 : index_type_to_metas.size ());
173+ for (const auto & [current_index_type, range_to_metas] : index_type_to_metas) {
174+ if (index_type && current_index_type != index_type.value ()) {
175+ continue ;
176+ }
156177 PAIMON_ASSIGN_OR_RAISE (std::unique_ptr<GlobalIndexer> indexer,
157- GlobalIndexerFactory::Get (index_type , options_.ToMap ()));
178+ GlobalIndexerFactory::Get (current_index_type , options_.ToMap ()));
158179 if (!indexer) {
159180 continue ;
160181 }
0 commit comments