mirror of
https://github.com/GreptimeTeam/greptimedb.git
synced 2026-05-25 09:20:40 +00:00
feat: support to create external table (#1372)
* feat: support to create external table * chore: apply suggestions from CR * test: add create external table without ts type * chore: apply suggestions from CR * fix: fix import typo * refactor: move consts to table crate * chore: apply suggestions from CR * refactor: rename create_table_schema
This commit is contained in:
@@ -28,19 +28,14 @@ use snafu::{OptionExt, ResultExt};
|
||||
use store_api::storage::RegionNumber;
|
||||
use table::error::{self as table_error, Result as TableResult};
|
||||
use table::metadata::{RawTableInfo, TableInfo, TableInfoRef, TableType};
|
||||
use table::Table;
|
||||
use table::{requests, Table};
|
||||
|
||||
use super::format::{create_physical_plan, CreateScanPlanContext, ScanPlanConfig};
|
||||
use crate::error::{self, ConvertRawSnafu, Result};
|
||||
use crate::manifest::immutable::{
|
||||
read_table_manifest, write_table_manifest, ImmutableMetadata, INIT_META_VERSION,
|
||||
};
|
||||
use crate::manifest::table_manifest_dir;
|
||||
|
||||
pub const IMMUTABLE_TABLE_META_KEY: &str = "IMMUTABLE_TABLE_META";
|
||||
pub const IMMUTABLE_TABLE_LOCATION_KEY: &str = "LOCATION";
|
||||
pub const IMMUTABLE_TABLE_PATTERN_KEY: &str = "PATTERN";
|
||||
pub const IMMUTABLE_TABLE_FORMAT_KEY: &str = "FORMAT";
|
||||
use crate::table::format::{create_physical_plan, CreateScanPlanContext, ScanPlanConfig};
|
||||
|
||||
#[derive(Debug, Clone, Default, Serialize, Deserialize, PartialEq, Eq)]
|
||||
#[serde(default)]
|
||||
@@ -125,19 +120,18 @@ impl ImmutableFileTable {
|
||||
let table_info = Arc::new(table_info);
|
||||
let options = &table_info.meta.options.extra_options;
|
||||
|
||||
let url = options.get(IMMUTABLE_TABLE_LOCATION_KEY).context(
|
||||
let url = options
|
||||
.get(requests::IMMUTABLE_TABLE_LOCATION_KEY)
|
||||
.context(error::MissingRequiredFieldSnafu {
|
||||
name: requests::IMMUTABLE_TABLE_LOCATION_KEY,
|
||||
})?;
|
||||
|
||||
let meta = options.get(requests::IMMUTABLE_TABLE_META_KEY).context(
|
||||
error::MissingRequiredFieldSnafu {
|
||||
name: IMMUTABLE_TABLE_LOCATION_KEY,
|
||||
name: requests::IMMUTABLE_TABLE_META_KEY,
|
||||
},
|
||||
)?;
|
||||
|
||||
let meta =
|
||||
options
|
||||
.get(IMMUTABLE_TABLE_META_KEY)
|
||||
.context(error::MissingRequiredFieldSnafu {
|
||||
name: IMMUTABLE_TABLE_META_KEY,
|
||||
})?;
|
||||
|
||||
let meta: ImmutableFileTableOptions =
|
||||
serde_json::from_str(meta).context(error::DecodeJsonSnafu)?;
|
||||
let format = Format::try_from(options).context(error::ParseFileFormatSnafu)?;
|
||||
|
||||
@@ -22,13 +22,13 @@ use object_store::services::Fs;
|
||||
use object_store::ObjectStore;
|
||||
use table::engine::{table_dir, EngineContext, TableEngine};
|
||||
use table::metadata::{RawTableInfo, TableInfo, TableInfoBuilder, TableMetaBuilder, TableType};
|
||||
use table::requests::{CreateTableRequest, TableOptions};
|
||||
use table::requests::{self, CreateTableRequest, TableOptions};
|
||||
use table::TableRef;
|
||||
|
||||
use crate::config::EngineConfig;
|
||||
use crate::engine::immutable::ImmutableFileTableEngine;
|
||||
use crate::manifest::immutable::ImmutableMetadata;
|
||||
use crate::table::immutable::{self, ImmutableFileTableOptions};
|
||||
use crate::table::immutable::ImmutableFileTableOptions;
|
||||
|
||||
pub const TEST_TABLE_NAME: &str = "demo";
|
||||
|
||||
@@ -98,15 +98,15 @@ pub struct TestEngineComponents {
|
||||
pub fn new_create_request(schema: SchemaRef) -> CreateTableRequest {
|
||||
let mut table_options = TableOptions::default();
|
||||
table_options.extra_options.insert(
|
||||
immutable::IMMUTABLE_TABLE_LOCATION_KEY.to_string(),
|
||||
requests::IMMUTABLE_TABLE_LOCATION_KEY.to_string(),
|
||||
"mock_path".to_string(),
|
||||
);
|
||||
table_options.extra_options.insert(
|
||||
immutable::IMMUTABLE_TABLE_META_KEY.to_string(),
|
||||
requests::IMMUTABLE_TABLE_META_KEY.to_string(),
|
||||
serde_json::to_string(&ImmutableFileTableOptions::default()).unwrap(),
|
||||
);
|
||||
table_options.extra_options.insert(
|
||||
immutable::IMMUTABLE_TABLE_FORMAT_KEY.to_string(),
|
||||
requests::IMMUTABLE_TABLE_FORMAT_KEY.to_string(),
|
||||
"csv".to_string(),
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user