Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add User Stage Type #8550

Merged
merged 7 commits into from
Oct 31, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/meta/proto-conv/src/user_from_to_protobuf_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,7 @@ impl FromToProto for mt::StageType {
pb::user_stage_info::StageType::LegacyInternal => Ok(mt::StageType::LegacyInternal),
pb::user_stage_info::StageType::External => Ok(mt::StageType::External),
pb::user_stage_info::StageType::Internal => Ok(mt::StageType::Internal),
pb::user_stage_info::StageType::User => Ok(mt::StageType::User),
}
}

Expand All @@ -410,6 +411,7 @@ impl FromToProto for mt::StageType {
mt::StageType::LegacyInternal => Ok(pb::user_stage_info::StageType::LegacyInternal),
mt::StageType::External => Ok(pb::user_stage_info::StageType::External),
mt::StageType::Internal => Ok(pb::user_stage_info::StageType::Internal),
mt::StageType::User => Ok(pb::user_stage_info::StageType::User),
}
}
}
Expand Down
1 change: 1 addition & 0 deletions src/meta/proto-conv/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ const META_CHANGE_LOG: &[(u64, &str)] = &[
(16, "2022-09-29: Add: CopyOptions::split_size"),
(17, "2022-10-28: Add: StageType::LegacyInternal"),
(18, "2022-10-28: Add: FILEFormatOptions::escape"),
(19, "2022-10-31: Add: StageType::UserStage"),
];

pub const VER: u64 = META_CHANGE_LOG.last().unwrap().0;
Expand Down
30 changes: 30 additions & 0 deletions src/meta/proto-conv/tests/it/user_proto_conv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -679,3 +679,33 @@ pub(crate) fn test_internal_stage_info_v17() -> mt::UserStageInfo {
..Default::default()
}
}

pub(crate) fn test_user_stage_info_v18() -> mt::UserStageInfo {
mt::UserStageInfo {
stage_name: "root".to_string(),
stage_type: mt::StageType::User,
stage_params: mt::StageParams {
storage: StorageParams::Fs(StorageFsConfig {
root: "/dir/to/files".to_string(),
}),
},
file_format_options: mt::FileFormatOptions {
format: mt::StageFileFormatType::Json,
skip_header: 1024,
field_delimiter: "|".to_string(),
record_delimiter: "//".to_string(),
escape: "".to_string(),
compression: mt::StageFileCompression::Bz2,
},
copy_options: mt::CopyOptions {
on_error: mt::OnErrorMode::SkipFileNum(666),
size_limit: 1038,
split_size: 0,
purge: true,
single: false,
max_file_size: 0,
},
comment: "test".to_string(),
..Default::default()
}
}
46 changes: 46 additions & 0 deletions src/meta/proto-conv/tests/it/user_stage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ use crate::user_proto_conv::test_gcs_stage_info;
use crate::user_proto_conv::test_internal_stage_info_v17;
use crate::user_proto_conv::test_oss_stage_info;
use crate::user_proto_conv::test_s3_stage_info;
use crate::user_proto_conv::test_user_stage_info_v18;

#[test]
fn test_user_stage_fs_latest() -> anyhow::Result<()> {
Expand Down Expand Up @@ -851,3 +852,48 @@ fn test_internal_stage_v17() -> anyhow::Result<()> {
common::test_load_old(func_name!(), internal_stage_v17.as_slice(), want)?;
Ok(())
}

#[test]
fn test_user_stage_v18() -> anyhow::Result<()> {
common::test_pb_from_to("user_stage_v18", test_user_stage_info_v18())?;

// Encoded data of version v18 of user_stage:
// It is generated with common::test_pb_from_to.
let user_stage_v18 = vec![
10, 4, 114, 111, 111, 116, 16, 3, 26, 25, 10, 23, 18, 21, 10, 13, 47, 100, 105, 114, 47,
116, 111, 47, 102, 105, 108, 101, 115, 160, 6, 19, 168, 6, 1, 34, 20, 8, 1, 16, 128, 8, 26,
1, 124, 34, 2, 47, 47, 40, 2, 160, 6, 19, 168, 6, 1, 42, 10, 10, 3, 32, 154, 5, 16, 142, 8,
24, 1, 50, 4, 116, 101, 115, 116, 160, 6, 19, 168, 6, 1,
];

let want = mt::UserStageInfo {
stage_name: "root".to_string(),
stage_type: mt::StageType::User,
stage_params: mt::StageParams {
storage: StorageParams::Fs(StorageFsConfig {
root: "/dir/to/files".to_string(),
}),
},
file_format_options: mt::FileFormatOptions {
format: mt::StageFileFormatType::Json,
skip_header: 1024,
field_delimiter: "|".to_string(),
record_delimiter: "//".to_string(),
escape: "".to_string(),
compression: mt::StageFileCompression::Bz2,
},
copy_options: mt::CopyOptions {
on_error: mt::OnErrorMode::SkipFileNum(666),
size_limit: 1038,
split_size: 0,
purge: true,
single: false,
max_file_size: 0,
},
comment: "test".to_string(),
..Default::default()
};

common::test_load_old(func_name!(), user_stage_v18.as_slice(), want)?;
Ok(())
}
1 change: 1 addition & 0 deletions src/meta/protos/proto/user.proto
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ message UserStageInfo {
LegacyInternal = 0;
External = 1;
Internal = 2;
User = 3;
}

message StageStorage {
Expand Down
8 changes: 8 additions & 0 deletions src/meta/types/src/user_stage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ pub enum StageType {
LegacyInternal,
External,
Internal,
/// User Stage is the stage for every sql user.
///
/// This is a stage that just in memory. We will not persist in metasrv
User,
}

impl fmt::Display for StageType {
Expand All @@ -68,6 +72,7 @@ impl fmt::Display for StageType {
StageType::LegacyInternal => "Internal",
StageType::External => "External",
StageType::Internal => "Internal",
StageType::User => "User",
};
write!(f, "{}", name)
}
Expand Down Expand Up @@ -245,7 +250,9 @@ pub struct UserStageInfo {
pub file_format_options: FileFormatOptions,
pub copy_options: CopyOptions,
pub comment: String,
/// TODO(xuanwo): stage doesn't have this info anymore, remove it.
pub number_of_files: u64,
/// TODO(xuanwo): stage doesn't have this info anymore, remove it.
pub creator: Option<UserIdentity>,
}

Expand Down Expand Up @@ -273,6 +280,7 @@ impl UserStageInfo {
unreachable!("stage_prefix should never be called on external stage, must be a bug")
}
StageType::Internal => format!("/stage/internal/{}/", self.stage_name),
StageType::User => format!("/stage/user/{}/", self.stage_name),
}
}
}
Expand Down
12 changes: 2 additions & 10 deletions src/query/storages/preludes/src/system/stages_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ use common_exception::Result;
use common_meta_app::schema::TableIdent;
use common_meta_app::schema::TableInfo;
use common_meta_app::schema::TableMeta;
use common_meta_types::StageType;
use common_users::UserApiProvider;

use super::table::AsyncOneBlockSystemTable;
Expand Down Expand Up @@ -59,15 +58,8 @@ impl AsyncSystemTable for StagesTable {
stage_params.push(format!("{:?}", stage.stage_params).into_bytes());
copy_options.push(format!("{:?}", stage.copy_options).into_bytes());
file_format_options.push(format!("{:?}", stage.file_format_options).into_bytes());
match stage.stage_type {
StageType::LegacyInternal | StageType::Internal => {
number_of_files.push(Some(stage.number_of_files));
}
StageType::External => {
number_of_files.push(None);
}
};
creator.push(stage.creator.map(|c| c.to_string().into_bytes()));
number_of_files.push(None);
creator.push(None);
comment.push(stage.comment.clone().into_bytes());
}
Ok(DataBlock::create(self.table_info.schema(), vec![
Expand Down