Apache Ignite C++ Client
Loading...
Searching...
No Matches
result_set_metadata.h
1/*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18#pragma once
19
20#include "ignite/client/sql/column_metadata.h"
21
22#include <string>
23#include <unordered_map>
24#include <vector>
25
26namespace ignite {
27
31class result_set_metadata {
32public:
33 // Default
34 result_set_metadata() = default;
35
41 result_set_metadata(std::vector<column_metadata> columns)
42 : m_columns(std::move(columns)) {}
43
49 [[nodiscard]] const std::vector<column_metadata> &columns() const { return m_columns; }
50
58 [[nodiscard]] std::int32_t index_of(const std::string &name) const {
59 if (m_indices.empty()) {
60 for (size_t i = 0; i < m_columns.size(); ++i) {
61 m_indices[m_columns[i].name()] = i;
62 }
63 }
64
65 auto it = m_indices.find(name);
66 if (it == m_indices.end())
67 return -1;
68 return std::int32_t(it->second);
69 }
70
71private:
73 std::vector<column_metadata> m_columns;
74
76 mutable std::unordered_map<std::string, size_t> m_indices;
77};
78
79} // namespace ignite
const std::vector< column_metadata > & columns() const
Definition result_set_metadata.h:49
std::int32_t index_of(const std::string &name) const
Definition result_set_metadata.h:58
result_set_metadata(std::vector< column_metadata > columns)
Definition result_set_metadata.h:41