Skip to content

Commit

Permalink
feat: add column create_at for stages table
Browse files Browse the repository at this point in the history
  • Loading branch information
everpcpc committed Dec 14, 2023
1 parent 9fd1304 commit 400365b
Show file tree
Hide file tree
Showing 14 changed files with 39 additions and 17 deletions.
8 changes: 8 additions & 0 deletions scripts/build/build-debug.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,13 @@ SCRIPT_PATH="$(cd "$(dirname "$0")" >/dev/null 2>&1 && pwd)"
cd "$SCRIPT_PATH/../.." || exit

echo "Build(DEBUG) start..."

if [[ $(uname -a) =~ Darwin ]]; then
export CMAKE_CC_COMPILER=/opt/homebrew/opt/llvm/bin/clang
export CMAKE_CXX_COMPILER=/opt/homebrew/opt/llvm/bin/clang++
export JEMALLOC_SYS_WITH_LG_PAGE=14
export JEMALLOC_SYS_WITH_MALLOC_CONF=oversize_threshold:0,dirty_decay_ms:5000,muzzy_decay_ms:5000
fi

cargo build --bin=databend-query --bin=databend-meta --bin=databend-metactl --bin=databend-sqllogictests --bin=databend-sqlsmith
echo "All done..."
1 change: 1 addition & 0 deletions src/meta/app/src/principal/user_stage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,7 @@ pub struct StageInfo {
/// TODO(xuanwo): stage doesn't have this info anymore, remove it.
pub number_of_files: u64,
pub creator: Option<UserIdentity>,
pub created_on: DateTime<Utc>,
}

impl StageInfo {
Expand Down
5 changes: 5 additions & 0 deletions src/meta/proto-conv/src/stage_from_to_protobuf_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,10 @@ impl FromToProto for mt::principal::StageInfo {
Some(c) => Some(mt::principal::UserIdentity::from_pb(c)?),
None => None,
},
created_on: match p.created_on {
Some(c) => DateTime::<Utc>::from_pb(c)?,
None => DateTime::<Utc>::default(),
},
})
}

Expand All @@ -241,6 +245,7 @@ impl FromToProto for mt::principal::StageInfo {
Some(c) => Some(mt::principal::UserIdentity::to_pb(c)?),
None => None,
},
created_on: Some(self.created_on.to_pb()?),
})
}
}
Expand Down
1 change: 1 addition & 0 deletions src/meta/proto-conv/tests/it/user_proto_conv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ pub(crate) fn test_fs_stage_info() -> mt::principal::StageInfo {
username: "databend".to_string(),
hostname: "databend.rs".to_string(),
}),
created_on: Utc::now(),
}
}

Expand Down
3 changes: 3 additions & 0 deletions src/meta/proto-conv/tests/it/v025_user_stage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use chrono::DateTime;
use chrono::Utc;
use common_meta_app as mt;
use common_meta_app::principal::UserIdentity;
use common_meta_app::storage::StorageFsConfig;
Expand Down Expand Up @@ -73,6 +75,7 @@ fn test_decode_v25_user_stage() -> anyhow::Result<()> {
username: "databend".to_string(),
hostname: "databend.rs".to_string(),
}),
created_on: DateTime::<Utc>::default(),
};
common::test_load_old(func_name!(), stage_info_v25.as_slice(), 25, want())?;
common::test_pb_from_to(func_name!(), want())?;
Expand Down
3 changes: 3 additions & 0 deletions src/meta/proto-conv/tests/it/v035_user_stage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use chrono::DateTime;
use chrono::Utc;
use common_meta_app as mt;
use common_meta_app::principal::UserIdentity;
use common_meta_app::storage::StorageFsConfig;
Expand Down Expand Up @@ -70,6 +72,7 @@ fn test_decode_v35_user_stage() -> anyhow::Result<()> {
username: "databend".to_string(),
hostname: "databend.rs".to_string(),
}),
created_on: DateTime::<Utc>::default(),
};
common::test_load_old(func_name!(), stage_info_v35.as_slice(), 35, want())?;
common::test_pb_from_to(func_name!(), want())?;
Expand Down
3 changes: 3 additions & 0 deletions src/meta/proto-conv/tests/it/v042_s3_stage_new_field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use chrono::DateTime;
use chrono::Utc;
use common_meta_app as mt;
use common_meta_app::principal::UserIdentity;
use common_meta_app::storage::StorageParams;
Expand Down Expand Up @@ -74,6 +76,7 @@ fn test_decode_v42_s3_stage_new_field() -> anyhow::Result<()> {
username: "databend".to_string(),
hostname: "databend.rs".to_string(),
}),
created_on: DateTime::<Utc>::default(),
};

common::test_load_old(func_name!(), stage_info_v42.as_slice(), 42, want())?;
Expand Down
3 changes: 2 additions & 1 deletion src/meta/protos/proto/stage.proto
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ message StageInfo {
optional UserIdentity creator = 8;

FileFormatParams file_format_params = 9;

optional string created_on = 10;
}

message StageFile {
Expand All @@ -87,4 +89,3 @@ message StageFile {
optional UserIdentity creator = 5;
optional string etag = 6;
}

Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

use std::sync::Arc;

use chrono::Utc;
use common_exception::ErrorCode;
use common_exception::Result;
use common_meta_app::principal::StageType;
Expand Down Expand Up @@ -78,6 +79,7 @@ impl Interpreter for CreateUserStageInterpreter {

let mut user_stage = user_stage;
user_stage.creator = Some(self.ctx.get_current_user()?.identity());
user_stage.created_on = Utc::now();
let _create_stage = user_mgr
.add_stage(&plan.tenant, user_stage, plan.if_not_exists)
.await?;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ DB.Table: 'system'.'columns', Table: columns-table_id:1, ver:0, Engine: SystemCo
| 'created_on' | 'system' | 'background_tasks' | 'Timestamp' | 'TIMESTAMP' | '' | '' | 'NO' | '' |
| 'created_on' | 'system' | 'indexes' | 'Timestamp' | 'TIMESTAMP' | '' | '' | 'NO' | '' |
| 'created_on' | 'system' | 'locks' | 'Timestamp' | 'TIMESTAMP' | '' | '' | 'NO' | '' |
| 'created_on' | 'system' | 'stages' | 'Timestamp' | 'TIMESTAMP' | '' | '' | 'NO' | '' |
| 'created_on' | 'system' | 'streams' | 'Timestamp' | 'TIMESTAMP' | '' | '' | 'NO' | '' |
| 'created_on' | 'system' | 'tables' | 'Timestamp' | 'TIMESTAMP' | '' | '' | 'NO' | '' |
| 'created_on' | 'system' | 'tables_with_history' | 'Timestamp' | 'TIMESTAMP' | '' | '' | 'NO' | '' |
Expand Down
2 changes: 1 addition & 1 deletion src/query/sql/src/planner/binder/binder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ impl<'a> Binder {
})),

// Stages
Statement::ShowStages => self.bind_rewrite_to_query(bind_context, "SELECT name, stage_type, number_of_files, creator, comment FROM system.stages ORDER BY name", RewriteKind::ShowStages).await?,
Statement::ShowStages => self.bind_rewrite_to_query(bind_context, "SELECT name, stage_type, number_of_files, creator, created_on, comment FROM system.stages ORDER BY name", RewriteKind::ShowStages).await?,
Statement::ListStage { location, pattern } => {
let pattern = if let Some(pattern) = pattern {
format!(", pattern => '{pattern}'")
Expand Down
5 changes: 5 additions & 0 deletions src/query/storages/system/src/stages_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ use common_exception::Result;
use common_expression::types::number::UInt64Type;
use common_expression::types::NumberDataType;
use common_expression::types::StringType;
use common_expression::types::TimestampType;
use common_expression::utils::FromData;
use common_expression::DataBlock;
use common_expression::TableDataType;
Expand Down Expand Up @@ -79,6 +80,7 @@ impl AsyncSystemTable for StagesTable {
let mut comment: Vec<Vec<u8>> = Vec::with_capacity(stages.len());
let mut number_of_files: Vec<Option<u64>> = Vec::with_capacity(stages.len());
let mut creator: Vec<Option<Vec<u8>>> = Vec::with_capacity(stages.len());
let mut created_on = Vec::with_capacity(stages.len());
for stage in stages.into_iter() {
name.push(stage.stage_name.clone().into_bytes());
stage_type.push(stage.stage_type.clone().to_string().into_bytes());
Expand All @@ -95,6 +97,7 @@ impl AsyncSystemTable for StagesTable {
}
};
creator.push(stage.creator.map(|c| c.to_string().into_bytes().to_vec()));
created_on.push(stage.created_on.timestamp_micros());
comment.push(stage.comment.clone().into_bytes());
}

Expand All @@ -106,6 +109,7 @@ impl AsyncSystemTable for StagesTable {
StringType::from_data(file_format_options),
UInt64Type::from_opt_data(number_of_files),
StringType::from_opt_data(creator),
TimestampType::from_data(created_on),
StringType::from_data(comment),
]))
}
Expand All @@ -128,6 +132,7 @@ impl StagesTable {
"creator",
TableDataType::Nullable(Box::new(TableDataType::String)),
),
TableField::new("created_on", TableDataType::Timestamp),
TableField::new("comment", TableDataType::String),
]);
let table_info = TableInfo {
Expand Down
10 changes: 2 additions & 8 deletions tests/sqllogictests/suites/base/05_ddl/05_0016_ddl_stage.test
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,11 @@ CREATE STAGE test_stage_internal file_format=(type=csv compression=AUTO record_d
statement ok
LIST @test_stage_internal

onlyif mysql
query TTTTTITT
statement ok
desc stage test_stage_internal
----
test_stage_internal Internal StageParams { storage: Fs(StorageFsConfig { root: "_data" }) } CopyOptions { on_error: AbortNum(1), size_limit: 0, max_files: 0, split_size: 0, purge: false, single: false, max_file_size: 0, disable_variant_check: false, return_failed_only: false } Csv(CsvFileFormatParams { compression: Auto, headers: 0, field_delimiter: ",", record_delimiter: "\n", null_display: "\\N", nan_display: "NaN", escape: "\\", quote: "\"", error_on_column_count_mismatch: true }) 0 'root'@'%' (empty)

query TTTTT
statement ok
SHOW STAGES
----
test_stage External NULL 'root'@'%' (empty)
test_stage_internal Internal 0 'root'@'%' (empty)

statement ok
DROP STAGE test_stage
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,11 @@ DROP STAGE if exists test_stage
statement ok
CREATE STAGE test_stage

query TTITT
statement ok
SHOW STAGES
----
test_stage Internal 0 'root'@'%' (empty)


query TTTTTITT
statement ok
DESC STAGE test_stage
----
test_stage Internal StageParams { storage: Fs(StorageFsConfig { root: "_data" }) } CopyOptions { on_error: AbortNum(1), size_limit: 0, max_files: 0, split_size: 0, purge: false, single: false, max_file_size: 0, disable_variant_check: false, return_failed_only: false } Parquet(ParquetFileFormatParams) 0 'root'@'%' (empty)

statement ok
DROP STAGE test_stage

0 comments on commit 400365b

Please sign in to comment.