Skip to content

Commit 64f17ee

Browse files
authored
Merge pull request #7706 from zhang2014/chore/result
chore(base): support error type for result
2 parents 1c46ff2 + a78859b commit 64f17ee

File tree

12 files changed

+20
-19
lines changed

12 files changed

+20
-19
lines changed

src/common/exception/src/exception.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ impl From<&str> for ErrorCodeBacktrace {
4545
Self::Serialized(Arc::new(s.to_string()))
4646
}
4747
}
48+
4849
impl From<String> for ErrorCodeBacktrace {
4950
fn from(s: String) -> Self {
5051
Self::Serialized(Arc::new(s))
@@ -138,7 +139,7 @@ impl ErrorCode {
138139
}
139140
}
140141

141-
pub type Result<T> = std::result::Result<T, ErrorCode>;
142+
pub type Result<T, E = ErrorCode> = std::result::Result<T, E>;
142143

143144
impl Debug for ErrorCode {
144145
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {

src/query/config/src/outer_v0.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ impl From<InnerStorageGcsConfig> for GcsStorageConfig {
370370
impl TryInto<InnerStorageGcsConfig> for GcsStorageConfig {
371371
type Error = ErrorCode;
372372

373-
fn try_into(self) -> std::result::Result<InnerStorageGcsConfig, Self::Error> {
373+
fn try_into(self) -> Result<InnerStorageGcsConfig, Self::Error> {
374374
Ok(InnerStorageGcsConfig {
375375
endpoint_url: self.gcs_endpoint_url,
376376
bucket: self.gcs_bucket,

src/query/formats/src/output_format.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ impl Default for OutputFormatType {
222222

223223
impl FromStr for OutputFormatType {
224224
type Err = ErrorCode;
225-
fn from_str(s: &str) -> std::result::Result<Self, ErrorCode> {
225+
fn from_str(s: &str) -> Result<Self> {
226226
FormatFactory::instance().get_output(s)
227227
}
228228
}

src/query/legacy-planners/src/plan_copy.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ pub enum ValidationMode {
3333

3434
impl FromStr for ValidationMode {
3535
type Err = String;
36-
fn from_str(s: &str) -> std::result::Result<Self, String> {
36+
fn from_str(s: &str) -> Result<Self, String> {
3737
match s.to_uppercase().as_str() {
3838
"" => Ok(ValidationMode::None),
3939
"RETURN_ERRORS" => Ok(ValidationMode::ReturnErrors),

src/query/management/src/stage/stage_mgr.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ impl StageApi for StageMgr {
145145
else_then: vec![],
146146
};
147147
let tx_reply = self.kv_api.transaction(txn_req).await?;
148-
let res: std::result::Result<_, MetaError> = tx_reply.into();
148+
let res: Result<_, MetaError> = tx_reply.into();
149149
let (succ, _) = res?;
150150

151151
if succ {
@@ -208,7 +208,7 @@ impl StageApi for StageMgr {
208208
else_then: vec![],
209209
};
210210
let tx_reply = self.kv_api.transaction(txn_req).await?;
211-
let res: std::result::Result<_, MetaError> = tx_reply.into();
211+
let res: Result<_, MetaError> = tx_reply.into();
212212
let (succ, _) = res?;
213213

214214
if succ {
@@ -274,7 +274,7 @@ impl StageApi for StageMgr {
274274
else_then: vec![],
275275
};
276276
let tx_reply = self.kv_api.transaction(txn_req).await?;
277-
let res: std::result::Result<_, MetaError> = tx_reply.into();
277+
let res: Result<_, MetaError> = tx_reply.into();
278278
let (succ, _) = res?;
279279

280280
if succ {

src/query/service/src/api/rpc/flight_client.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ pub enum FlightExchange {
153153
impl FlightExchange {
154154
pub fn from_server(
155155
streaming: Request<Streaming<FlightData>>,
156-
response_tx: Sender<std::result::Result<FlightData, Status>>,
156+
response_tx: Sender<Result<FlightData, Status>>,
157157
) -> FlightExchange {
158158
let mut streaming = streaming.into_inner();
159159
let (tx, rx) = async_channel::bounded(1);
@@ -260,7 +260,7 @@ pub struct ClientFlightExchange {
260260
is_closed_request: AtomicBool,
261261
is_closed_response: AtomicBool,
262262
response_tx: Sender<FlightData>,
263-
request_rx: Receiver<std::result::Result<FlightData, Status>>,
263+
request_rx: Receiver<Result<FlightData, Status>>,
264264
}
265265

266266
impl ClientFlightExchange {
@@ -344,8 +344,8 @@ pub struct ServerFlightExchange {
344344
state: Arc<ChannelState>,
345345
is_closed_request: AtomicBool,
346346
is_closed_response: AtomicBool,
347-
request_rx: Receiver<std::result::Result<FlightData, Status>>,
348-
response_tx: Sender<std::result::Result<FlightData, Status>>,
347+
request_rx: Receiver<Result<FlightData, Status>>,
348+
response_tx: Sender<Result<FlightData, Status>>,
349349
}
350350

351351
impl Clone for ServerFlightExchange {

src/query/service/src/interpreters/interpreter_query_log.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,13 @@ pub enum LogType {
4646
Aborted = 4,
4747
}
4848

49-
fn date_str<S>(dt: &i32, s: S) -> std::result::Result<S::Ok, S::Error>
49+
fn date_str<S>(dt: &i32, s: S) -> Result<S::Ok, S::Error>
5050
where S: Serializer {
5151
let t = NaiveDateTime::from_timestamp(i64::from(*dt) * 24 * 3600, 0);
5252
s.serialize_str(t.format("%Y-%m-%d").to_string().as_str())
5353
}
5454

55-
fn datetime_str<S>(dt: &i64, s: S) -> std::result::Result<S::Ok, S::Error>
55+
fn datetime_str<S>(dt: &i64, s: S) -> Result<S::Ok, S::Error>
5656
where S: Serializer {
5757
let t = NaiveDateTime::from_timestamp(
5858
dt / 1_000_000,

src/query/service/src/sql/planner/plans/copy_v2.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ pub enum ValidationMode {
3333

3434
impl FromStr for ValidationMode {
3535
type Err = String;
36-
fn from_str(s: &str) -> std::result::Result<Self, String> {
36+
fn from_str(s: &str) -> Result<Self, String> {
3737
match s.to_uppercase().as_str() {
3838
"" => Ok(ValidationMode::None),
3939
"RETURN_ERRORS" => Ok(ValidationMode::ReturnErrors),

src/query/service/src/sql/statements/value_source.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ async fn exprs_to_datavalue(
264264
Ok(datavalues)
265265
}
266266

267-
fn parse_exprs(buf: &[u8], typ: &SessionType) -> std::result::Result<Vec<Expr>, ParserError> {
267+
fn parse_exprs(buf: &[u8], typ: &SessionType) -> Result<Vec<Expr>, ParserError> {
268268
let dialect: &dyn Dialect = match typ {
269269
SessionType::MySQL => &MySqlDialect {},
270270
_ => &GenericDialect {},

src/query/service/tests/it/servers/mysql/mysql_handler.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ async fn create_connection(port: u16) -> Result<mysql_async::Conn> {
165165
struct EmptyRow;
166166

167167
impl FromRow for EmptyRow {
168-
fn from_row_opt(_: Row) -> std::result::Result<Self, FromRowError>
168+
fn from_row_opt(_: Row) -> Result<Self, FromRowError>
169169
where Self: Sized {
170170
Ok(EmptyRow)
171171
}

0 commit comments

Comments
 (0)