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

chore: use x.to_string() instead of format!("{}", x) #5359

Merged
merged 2 commits into from
May 13, 2022
Merged
Show file tree
Hide file tree
Changes from all 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: 1 addition & 1 deletion common/base/src/base/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ impl Runtime {
fn create(tracker: Arc<RuntimeTracker>, builder: &mut tokio::runtime::Builder) -> Result<Self> {
let runtime = builder
.build()
.map_err(|tokio_error| ErrorCode::TokioError(format!("{}", tokio_error)))?;
.map_err(|tokio_error| ErrorCode::TokioError(tokio_error.to_string()))?;

let (send_stop, recv_stop) = oneshot::channel();

Expand Down
2 changes: 1 addition & 1 deletion common/datablocks/src/data_block_debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ fn create_table(results: &[DataBlock]) -> Result<Table> {
let mut cells = Vec::new();
for col in 0..batch.num_columns() {
let column = batch.column(col);
let str = format!("{}", column.get_checked(row)?);
let str = column.get_checked(row)?.to_string();
cells.push(Cell::new(&str));
}
table.add_row(cells);
Expand Down
8 changes: 4 additions & 4 deletions common/datavalues/src/data_value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ impl DataValue {
DataTypeImpl::Array(ArrayType::create(inner_type))
}
DataValue::Struct(x) => {
let names = (0..x.len()).map(|i| format!("{}", i)).collect::<Vec<_>>();
let names = (0..x.len()).map(|i| i.to_string()).collect::<Vec<_>>();
let types = x.iter().map(|v| v.data_type()).collect::<Vec<_>>();
DataTypeImpl::Struct(StructType::create(names, types))
}
Expand All @@ -154,7 +154,7 @@ impl DataValue {
DataTypeImpl::Array(ArrayType::create(inner_type))
}
DataValue::Struct(x) => {
let names = (0..x.len()).map(|i| format!("{}", i)).collect::<Vec<_>>();
let names = (0..x.len()).map(|i| i.to_string()).collect::<Vec<_>>();
let types = x.iter().map(|v| v.data_type()).collect::<Vec<_>>();
DataTypeImpl::Struct(StructType::create(names, types))
}
Expand Down Expand Up @@ -408,7 +408,7 @@ impl fmt::Display for DataValue {
f,
"[{}]",
v.iter()
.map(|v| format!("{}", v))
.map(|v| v.to_string())
.collect::<Vec<_>>()
.join(", ")
)
Expand Down Expand Up @@ -440,6 +440,6 @@ pub fn format_datavalue_sql(value: &DataValue) -> String {
match value {
DataValue::String(_) | DataValue::Variant(_) => format!("'{}'", value),
DataValue::Float64(value) => format!("'{:?}'", value),
_ => format!("{}", value),
_ => value.to_string(),
}
}
2 changes: 1 addition & 1 deletion common/datavalues/src/types/serializations/number.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ where T: PrimitiveType
_format: &FormatSettings,
) -> Result<Vec<String>> {
let column: &PrimitiveColumn<T> = Series::check_get(column)?;
let result: Vec<String> = column.iter().map(|x| format!("{}", x)).collect();
let result: Vec<String> = column.iter().map(|x| x.to_string()).collect();
Ok(result)
}

Expand Down
2 changes: 1 addition & 1 deletion common/datavalues/src/types/type_interval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ impl DataType for IntervalType {
fn custom_arrow_meta(&self) -> Option<BTreeMap<String, String>> {
let mut mp = BTreeMap::new();
mp.insert(ARROW_EXTENSION_NAME.to_string(), "Interval".to_string());
mp.insert(ARROW_EXTENSION_META.to_string(), format!("{}", self.kind));
mp.insert(ARROW_EXTENSION_META.to_string(), self.kind.to_string());
Some(mp)
}

Expand Down
5 changes: 1 addition & 4 deletions common/datavalues/src/types/type_timestamp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,7 @@ impl DataType for TimestampType {
fn custom_arrow_meta(&self) -> Option<BTreeMap<String, String>> {
let mut mp = BTreeMap::new();
mp.insert(ARROW_EXTENSION_NAME.to_string(), "Timestamp".to_string());
mp.insert(
ARROW_EXTENSION_META.to_string(),
format!("{}", self.precision),
);
mp.insert(ARROW_EXTENSION_META.to_string(), self.precision.to_string());
Some(mp)
}

Expand Down
4 changes: 2 additions & 2 deletions common/exception/src/exception.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ impl ErrorCode {
pub fn from_std_error<T: std::error::Error>(error: T) -> Self {
ErrorCode {
code: 1002,
display_text: format!("{}", error),
display_text: error.to_string(),
cause: None,
backtrace: Some(ErrorCodeBacktrace::Origin(Arc::new(Backtrace::capture()))),
}
Expand Down Expand Up @@ -171,7 +171,7 @@ impl ErrorCode {
///
/// assert_eq!(
/// "Code: 1067, displayText = 123, cause: an error occurred when formatting an argument.",
/// format!("{}", y.unwrap_err())
/// y.unwrap_err().to_string()
/// );
/// ```
pub trait ToErrorCode<T, E, CtxFn>
Expand Down
2 changes: 1 addition & 1 deletion common/exception/src/exception_into.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ impl From<std::convert::Infallible> for ErrorCode {

impl From<sqlparser::parser::ParserError> for ErrorCode {
fn from(error: sqlparser::parser::ParserError) -> Self {
ErrorCode::SyntaxException(format!("{}", error))
ErrorCode::SyntaxException(error.to_string())
}
}

Expand Down
16 changes: 8 additions & 8 deletions common/exception/tests/it/exception.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,20 @@ fn test_format_with_error_codes() {
use common_exception::exception::*;

assert_eq!(
format!("{}", ErrorCode::Ok("test message 1")),
ErrorCode::Ok("test message 1").to_string(),
"Code: 0, displayText = test message 1."
);

assert_eq!(
format!("{}", ErrorCode::Ok("test message 2")),
ErrorCode::Ok("test message 2").to_string(),
"Code: 0, displayText = test message 2."
);
assert_eq!(
format!("{}", ErrorCode::UnknownException("test message 1")),
ErrorCode::UnknownException("test message 1").to_string(),
"Code: 1067, displayText = test message 1."
);
assert_eq!(
format!("{}", ErrorCode::UnknownException("test message 2")),
ErrorCode::UnknownException("test message 2").to_string(),
"Code: 1067, displayText = test message 2."
);
}
Expand All @@ -62,15 +62,15 @@ fn test_derive_from_std_error() {

assert_eq!(
"Code: 1067, displayText = 123, cause: an error occurred when formatting an argument.",
format!("{}", rst1.as_ref().unwrap_err())
rst1.as_ref().unwrap_err().to_string()
);

let rst2: common_exception::exception::Result<()> =
rst1.map_err_to_code(ErrorCode::Ok, || "wrapper");

assert_eq!(
"Code: 0, displayText = wrapper, cause: Code: 1067, displayText = 123, cause: an error occurred when formatting an argument..",
format!("{}", rst2.as_ref().unwrap_err())
rst2.as_ref().unwrap_err().to_string()
);
}

Expand All @@ -86,7 +86,7 @@ fn test_derive_from_display() {

assert_eq!(
"Code: 1067, displayText = 123, cause: 3.",
format!("{}", rst1.as_ref().unwrap_err())
rst1.as_ref().unwrap_err().to_string()
);
}

Expand All @@ -98,7 +98,7 @@ fn test_from_and_to_serialized_error() {
let ec2: ErrorCode = se.into();
assert_eq!(ec.code(), ec2.code());
assert_eq!(ec.message(), ec2.message());
assert_eq!(format!("{}", ec), format!("{}", ec2));
assert_eq!(ec.to_string(), ec2.to_string());
assert_eq!(ec.backtrace_str(), ec2.backtrace_str());
}

Expand Down
2 changes: 1 addition & 1 deletion common/exception/tests/it/prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ fn test_prelude() -> anyhow::Result<()> {

assert_eq!(
"Code: 1067, displayText = 123, cause: an error occurred when formatting an argument.",
format!("{}", y.unwrap_err())
y.unwrap_err().to_string()
);
Ok(())
}
2 changes: 1 addition & 1 deletion common/meta/api/src/schema_api_test_suite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1584,7 +1584,7 @@ impl SchemaApiTestSuite {
assert_eq!("Unknown database 'nonexistent'", err.message());
assert_eq!(
"Code: 1003, displayText = Unknown database 'nonexistent'.",
format!("{}", err)
err.to_string()
);
}

Expand Down
2 changes: 1 addition & 1 deletion common/meta/raft-store/src/log/raft_log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ impl RaftLog {
}

/// Insert a single log.
#[tracing::instrument(level = "debug", skip(self, log), fields(log_id=format!("{}",log.log_id).as_str()))]
#[tracing::instrument(level = "debug", skip(self, log), fields(log_id=log.log_id.to_string().as_str()))]
pub async fn insert(
&self,
log: &Entry<LogEntry>,
Expand Down
2 changes: 1 addition & 1 deletion common/meta/sled-store/src/sled_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ impl SledTree {
tracing::debug!("SledTree opened tree: {}", tree_name);

let rl = SledTree {
name: format!("{}", tree_name),
name: tree_name.to_string(),
sync,
tree: t,
};
Expand Down
2 changes: 1 addition & 1 deletion common/meta/types/src/meta_storage_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ pub enum MetaStorageError {
/// Output message for end users, with sensitive info stripped.
pub trait AppErrorMessage: Display {
fn message(&self) -> String {
format!("{}", self)
self.to_string()
}
}

Expand Down
6 changes: 3 additions & 3 deletions common/meta/types/tests/it/match_seq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,9 @@ fn test_match_seq_from_opt_u64() -> Result<(), ()> {

#[test]
fn test_match_seq_display() -> Result<(), ()> {
assert_eq!("is any value", format!("{}", MatchSeq::Any));
assert_eq!("== 3", format!("{}", MatchSeq::Exact(3)));
assert_eq!(">= 3", format!("{}", MatchSeq::GE(3)));
assert_eq!("is any value", MatchSeq::Any.to_string());
assert_eq!("== 3", MatchSeq::Exact(3).to_string());
assert_eq!(">= 3", MatchSeq::GE(3).to_string());

Ok(())
}
2 changes: 1 addition & 1 deletion common/planners/src/plan_expression_monotonicity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ impl ExpressionVisitor for ExpressionMonotonicityVisitor {
column_name,
data_type,
} => {
let name = column_name.clone().unwrap_or(format!("{}", value));
let name = column_name.clone().unwrap_or_else(|| value.to_string());
let data_field = DataField::new(&name, data_type.clone());
let col = data_type.create_constant_column(value, 1)?;
let data_column_field = ColumnWithField::new(col, data_field);
Expand Down
2 changes: 1 addition & 1 deletion metasrv/tests/it/tests/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ impl MetaSrvTestContext {

config.raft_config.id = id;

config.raft_config.config_id = format!("{}", config_id);
config.raft_config.config_id = config_id.to_string();

// By default, create a meta node instead of open an existent one.
config.raft_config.single = true;
Expand Down
3 changes: 2 additions & 1 deletion query/src/interpreters/interpreter_explain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ impl ExplainInterpreter {
&self.explain.input,
)?;
let formatted_plan = Series::from_data(
format!("{}", plan.display_graphviz())
plan.display_graphviz()
.to_string()
.lines()
.map(|s| s.as_bytes())
.collect::<Vec<_>>(),
Expand Down
4 changes: 2 additions & 2 deletions query/src/interpreters/interpreter_query_log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ impl InterpreterQueryLog {
let user = self.ctx.get_current_user()?;
let sql_user = user.name;
let sql_user_quota = format!("{:?}", user.quota);
let sql_user_privileges = format!("{}", user.grants);
let sql_user_privileges = user.grants.to_string();

// Query.
let query_id = self.ctx.get_id();
Expand Down Expand Up @@ -338,7 +338,7 @@ impl InterpreterQueryLog {
let user = self.ctx.get_current_user()?;
let sql_user = user.name;
let sql_user_quota = format!("{:?}", user.quota);
let sql_user_privileges = format!("{}", user.grants);
let sql_user_privileges = user.grants.to_string();

// Query.
let query_id = self.ctx.get_id();
Expand Down
2 changes: 1 addition & 1 deletion query/src/interpreters/interpreter_table_describe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ impl Interpreter for DescribeTableInterpreter {

None => {
let value = field.data_type().default_value();
default_exprs.push(format!("{}", value));
default_exprs.push(value.to_string());
}
}
extras.push("".to_string());
Expand Down
2 changes: 1 addition & 1 deletion query/src/servers/mysql/writers/init_result_writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ impl<'a, W: std::io::Write> DFInitResultWriter<'a, W> {

fn err(error: &ErrorCode, writer: InitWriter<'a, W>) -> Result<()> {
tracing::error!("OnInit Error: {:?}", error);
writer.error(ErrorKind::ER_UNKNOWN_ERROR, format!("{}", error).as_bytes())?;
writer.error(ErrorKind::ER_UNKNOWN_ERROR, error.to_string().as_bytes())?;
Ok(())
}
}
4 changes: 2 additions & 2 deletions query/src/servers/mysql/writers/query_result_writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,11 +206,11 @@ impl<'a, W: std::io::Write> DFQueryResultWriter<'a, W> {
fn err(error: &ErrorCode, writer: QueryResultWriter<'a, W>) -> Result<()> {
if error.code() != ABORT_QUERY && error.code() != ABORT_SESSION {
tracing::error!("OnQuery Error: {:?}", error);
writer.error(ErrorKind::ER_UNKNOWN_ERROR, format!("{}", error).as_bytes())?;
writer.error(ErrorKind::ER_UNKNOWN_ERROR, error.to_string().as_bytes())?;
} else {
writer.error(
ErrorKind::ER_ABORTING_CONNECTION,
format!("{}", error).as_bytes(),
error.to_string().as_bytes(),
)?;
}

Expand Down
4 changes: 2 additions & 2 deletions query/src/sql/parsers/parser_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ impl<'a> DfParser<'a> {
if self.consume_token("AS") {
let native_query = self.parser.parse_query()?;
let query = DfQueryStatement::try_from(native_query.clone())?;
let subquery = format!("{}", native_query);
let subquery = native_query.to_string();
let create = DfCreateView {
if_not_exists,
name,
Expand Down Expand Up @@ -68,7 +68,7 @@ impl<'a> DfParser<'a> {
if self.consume_token("AS") {
let native_query = self.parser.parse_query()?;
let query = DfQueryStatement::try_from(native_query.clone())?;
let subquery = format!("{}", native_query);
let subquery = native_query.to_string();
let alter = DfAlterView {
name,
subquery,
Expand Down
4 changes: 2 additions & 2 deletions query/src/sql/statements/statement_show_databases.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ impl AnalyzableStatement for DfShowDatabases {
match &self.kind {
DfShowKind::All => {}
DfShowKind::Like(v) => {
kind = PlanShowKind::Like(format!("{v}"));
kind = PlanShowKind::Like(v.to_string());
}
DfShowKind::Where(v) => {
kind = PlanShowKind::Where(format!("{v}"));
kind = PlanShowKind::Where(v.to_string());
}
}

Expand Down
4 changes: 2 additions & 2 deletions query/src/sql/statements/statement_show_functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ impl AnalyzableStatement for DfShowFunctions {
match &self.kind {
DfShowKind::All => {}
DfShowKind::Like(v) => {
kind = PlanShowKind::Like(format!("{}", v));
kind = PlanShowKind::Like(v.to_string());
}
DfShowKind::Where(v) => {
kind = PlanShowKind::Where(format!("{}", v));
kind = PlanShowKind::Where(v.to_string());
}
}

Expand Down
4 changes: 2 additions & 2 deletions query/src/sql/statements/statement_show_tab_stat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ impl AnalyzableStatement for DfShowTabStat {
match &self.kind {
DfShowKind::All => {}
DfShowKind::Like(v) => {
kind = PlanShowKind::Like(format!("{}", v));
kind = PlanShowKind::Like(v.to_string());
}
DfShowKind::Where(v) => {
kind = PlanShowKind::Where(format!("{}", v));
kind = PlanShowKind::Where(v.to_string());
}
}

Expand Down
4 changes: 2 additions & 2 deletions query/src/sql/statements/statement_show_tables.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ impl AnalyzableStatement for DfShowTables {
match &self.kind {
DfShowKind::All => {}
DfShowKind::Like(v) => {
kind = PlanShowKind::Like(format!("{}", v));
kind = PlanShowKind::Like(v.to_string());
}
DfShowKind::Where(v) => {
kind = PlanShowKind::Where(format!("{}", v));
kind = PlanShowKind::Where(v.to_string());
}
}

Expand Down
2 changes: 1 addition & 1 deletion query/src/storages/system/tracing_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ impl TracingTable {
.filter_map(|dir_entry| match dir_entry {
Ok(entry) if entry.path().is_dir() => None,
Ok(entry) => Some(Ok(entry.path().display().to_string())),
Err(cause) => Some(Err(ErrorCode::UnknownException(format!("{}", cause)))),
Err(cause) => Some(Err(ErrorCode::UnknownException(cause.to_string()))),
})
.collect::<Result<VecDeque<String>>>()
}
Expand Down
2 changes: 1 addition & 1 deletion query/tests/it/interpreters/interpreter_setting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ async fn test_setting_interpreter_error() -> Result<()> {
let executor = InterpreterFactory::get(ctx.clone(), plan)?;
if let Err(e) = executor.execute(None).await {
let expect = "Code: 1020, displayText = Unknown variable: \"xx\".";
assert_eq!(expect, format!("{}", e));
assert_eq!(expect, e.to_string());
}

Ok(())
Expand Down
Loading