|
15 | 15 | use std::sync::{Arc, Weak}; |
16 | 16 |
|
17 | 17 | use common_catalog::consts::{ |
18 | | - INFORMATION_SCHEMA_SSTS_MANIFEST_TABLE_ID, INFORMATION_SCHEMA_SSTS_STORAGE_TABLE_ID, |
| 18 | + INFORMATION_SCHEMA_SSTS_INDEX_META_TABLE_ID, INFORMATION_SCHEMA_SSTS_MANIFEST_TABLE_ID, |
| 19 | + INFORMATION_SCHEMA_SSTS_STORAGE_TABLE_ID, |
19 | 20 | }; |
20 | 21 | use common_error::ext::BoxedError; |
21 | 22 | use common_recordbatch::SendableRecordBatchStream; |
22 | 23 | use common_recordbatch::adapter::AsyncRecordBatchStreamAdapter; |
23 | 24 | use datatypes::schema::SchemaRef; |
24 | 25 | use snafu::ResultExt; |
25 | | -use store_api::sst_entry::{ManifestSstEntry, StorageSstEntry}; |
| 26 | +use store_api::sst_entry::{ManifestSstEntry, PuffinIndexMetaEntry, StorageSstEntry}; |
26 | 27 | use store_api::storage::{ScanRequest, TableId}; |
27 | 28 |
|
28 | 29 | use crate::CatalogManager; |
29 | 30 | use crate::error::{ProjectSchemaSnafu, Result}; |
30 | 31 | use crate::information_schema::{ |
31 | | - DatanodeInspectKind, DatanodeInspectRequest, InformationTable, SSTS_MANIFEST, SSTS_STORAGE, |
| 32 | + DatanodeInspectKind, DatanodeInspectRequest, InformationTable, SSTS_INDEX_META, SSTS_MANIFEST, |
| 33 | + SSTS_STORAGE, |
32 | 34 | }; |
33 | 35 | use crate::system_schema::utils; |
34 | 36 |
|
@@ -140,3 +142,58 @@ impl InformationTable for InformationSchemaSstsStorage { |
140 | 142 | ))) |
141 | 143 | } |
142 | 144 | } |
| 145 | + |
| 146 | +/// Information schema table for index metadata. |
| 147 | +pub struct InformationSchemaSstsIndexMeta { |
| 148 | + schema: SchemaRef, |
| 149 | + catalog_manager: Weak<dyn CatalogManager>, |
| 150 | +} |
| 151 | + |
| 152 | +impl InformationSchemaSstsIndexMeta { |
| 153 | + pub(super) fn new(catalog_manager: Weak<dyn CatalogManager>) -> Self { |
| 154 | + Self { |
| 155 | + schema: PuffinIndexMetaEntry::schema(), |
| 156 | + catalog_manager, |
| 157 | + } |
| 158 | + } |
| 159 | +} |
| 160 | + |
| 161 | +impl InformationTable for InformationSchemaSstsIndexMeta { |
| 162 | + fn table_id(&self) -> TableId { |
| 163 | + INFORMATION_SCHEMA_SSTS_INDEX_META_TABLE_ID |
| 164 | + } |
| 165 | + |
| 166 | + fn table_name(&self) -> &'static str { |
| 167 | + SSTS_INDEX_META |
| 168 | + } |
| 169 | + |
| 170 | + fn schema(&self) -> SchemaRef { |
| 171 | + self.schema.clone() |
| 172 | + } |
| 173 | + |
| 174 | + fn to_stream(&self, request: ScanRequest) -> Result<SendableRecordBatchStream> { |
| 175 | + let schema = if let Some(p) = &request.projection { |
| 176 | + Arc::new(self.schema.try_project(p).context(ProjectSchemaSnafu)?) |
| 177 | + } else { |
| 178 | + self.schema.clone() |
| 179 | + }; |
| 180 | + |
| 181 | + let info_ext = utils::information_extension(&self.catalog_manager)?; |
| 182 | + let req = DatanodeInspectRequest { |
| 183 | + kind: DatanodeInspectKind::SstIndexMeta, |
| 184 | + scan: request, |
| 185 | + }; |
| 186 | + |
| 187 | + let future = async move { |
| 188 | + info_ext |
| 189 | + .inspect_datanode(req) |
| 190 | + .await |
| 191 | + .map_err(BoxedError::new) |
| 192 | + .context(common_recordbatch::error::ExternalSnafu) |
| 193 | + }; |
| 194 | + Ok(Box::pin(AsyncRecordBatchStreamAdapter::new( |
| 195 | + schema, |
| 196 | + Box::pin(future), |
| 197 | + ))) |
| 198 | + } |
| 199 | +} |
0 commit comments