Skip to content

Commit

Permalink
feat: gRPC auto create table hint (#4700)
Browse files Browse the repository at this point in the history
* feat: gRPC auto create table hint

* chore: remove the checking of auto_create_table_hint
  • Loading branch information
fengjiachun committed Sep 9, 2024
1 parent 8bf549c commit dc89944
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 17 deletions.
48 changes: 31 additions & 17 deletions src/operator/src/insert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ use store_api::metric_engine_consts::{
};
use store_api::mito_engine_options::{APPEND_MODE_KEY, MERGE_MODE_KEY};
use store_api::storage::{RegionId, TableId};
use table::requests::{InsertRequest as TableInsertRequest, TTL_KEY};
use table::requests::{InsertRequest as TableInsertRequest, AUTO_CREATE_TABLE_KEY, TTL_KEY};
use table::table_reference::TableReference;
use table::TableRef;

Expand Down Expand Up @@ -517,25 +517,39 @@ impl Inserter {
AutoCreateTableType::Physical
| AutoCreateTableType::Log
| AutoCreateTableType::LastNonNull => {
for req in create_tables {
let table = self
.create_non_logical_table(
req,
ctx,
statement_executor,
auto_create_table_type.clone(),
)
.await?;
let table_info = table.table_info();
table_name_to_ids.insert(table_info.name.clone(), table_info.table_id());
}
for alter_expr in alter_tables.into_iter() {
statement_executor
.alter_table_inner(alter_expr, ctx.clone())
.await?;
let auto_create_table_hint = ctx
.extension(AUTO_CREATE_TABLE_KEY)
.map(|v| v.parse::<bool>())
.transpose()
.map_err(|_| {
InvalidInsertRequestSnafu {
reason: "`auto_create_table` hint must be a boolean",
}
.build()
})?
.unwrap_or(true);
if auto_create_table_hint {
for req in create_tables {
let table = self
.create_non_logical_table(
req,
ctx,
statement_executor,
auto_create_table_type.clone(),
)
.await?;
let table_info = table.table_info();
table_name_to_ids.insert(table_info.name.clone(), table_info.table_id());
}
for alter_expr in alter_tables.into_iter() {
statement_executor
.alter_table_inner(alter_expr, ctx.clone())
.await?;
}
}
}
}

Ok(table_name_to_ids)
}

Expand Down
1 change: 1 addition & 0 deletions src/table/src/requests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ pub const WRITE_BUFFER_SIZE_KEY: &str = "write_buffer_size";
pub const TTL_KEY: &str = "ttl";
pub const STORAGE_KEY: &str = "storage";
pub const COMMENT_KEY: &str = "comment";
pub const AUTO_CREATE_TABLE_KEY: &str = "auto_create_table";

impl TableOptions {
pub fn try_from_iter<T: ToString, U: IntoIterator<Item = (T, T)>>(
Expand Down

0 comments on commit dc89944

Please sign in to comment.