Skip to content

Commit 6fab062

Browse files
wbtlbwangbo
andauthored
fix(sharding): fix database table strategy rewrite error (#384)
* fix(sharding): fix database table strategy rewrite error Signed-off-by: wangbo <wangbo@sphere-ex.com> * delete(sharding): delete unuse code Signed-off-by: wangbo <wangbo@sphere-ex.com> Signed-off-by: wangbo <wangbo@sphere-ex.com> Co-authored-by: wangbo <wangbo@sphere-ex.com>
1 parent 1dea9c1 commit 6fab062

File tree

2 files changed

+20
-17
lines changed

2 files changed

+20
-17
lines changed

pisa-proxy/proxy/strategy/src/sharding_rewrite/meta.rs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -525,12 +525,19 @@ impl Transformer for RewriteMetaData {
525525
self.prev_expr_type = None
526526
}
527527

528-
Expr::LiteralExpr(Value::Num { span, value, .. }) => match &mut self.state {
529-
ScanState::InsertRowValue(args) => {
530-
args.push(InsertValue { span: *span, value: value.clone() });
531-
}
532-
_ => {}
533-
},
528+
Expr::LiteralExpr(e) => {
529+
if let ScanState::InsertRowValue(args) = &mut self.state {
530+
match e {
531+
Value::Num { span, value, .. } => {
532+
args.push(InsertValue { span: *span, value: value.clone() });
533+
},
534+
Value::Text {span, value, ..} => {
535+
args.push(InsertValue { span: *span, value: value.clone() });
536+
},
537+
_ => {}
538+
}
539+
};
540+
}
534541

535542
_ => {}
536543
},

pisa-proxy/proxy/strategy/src/sharding_rewrite/mod.rs

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,6 @@ impl ShardingRewrite {
273273
if fields.is_empty() {
274274
return Err(ShardingRewriteError::FieldsIsEmpty);
275275
}
276-
277276
return self.change_insert_sql(try_tables, fields, inserts);
278277
}
279278

@@ -1063,7 +1062,6 @@ impl ShardingRewrite {
10631062
let sql_prefix_text = &self.raw_sql[0..row_start_idx];
10641063

10651064
let mut sqls = IndexMap::<(Option<u64>, Option<u64>), String>::new();
1066-
10671065
match strategy_typ {
10681066
StrategyTyp::Database => {
10691067
for change in changes.iter() {
@@ -1131,7 +1129,6 @@ impl ShardingRewrite {
11311129
}
11321130
}
11331131
}
1134-
11351132
let outputs = sqls
11361133
.into_iter()
11371134
.map(|((idx, _), v)| -> Result<ShardingRewriteOutput, ShardingRewriteError> {
@@ -1148,7 +1145,6 @@ impl ShardingRewrite {
11481145
})
11491146
})
11501147
.collect::<Result<Vec<_>, _>>()?;
1151-
11521148
Ok(outputs)
11531149
}
11541150

@@ -1173,7 +1169,6 @@ impl ShardingRewrite {
11731169
meta_base_info: ShardingMetaBaseInfo<'b>,
11741170
) -> Result<Vec<ShardingIdx>, ShardingRewriteError> {
11751171
let insert_values = Self::find_inserts(&strategy_typ, inserts, fields, &meta_base_info)?;
1176-
11771172
let mut changes = vec![];
11781173

11791174
match strategy_typ {
@@ -1244,23 +1239,25 @@ impl ShardingRewrite {
12441239
table_value: Option<&String>,
12451240
meta_base_info: &ShardingMetaBaseInfo<'b>,
12461241
) -> Result<(u64, u64), ShardingRewriteError> {
1247-
let algo = meta_base_info.algo.0.unwrap();
1248-
let sharding_count = meta_base_info.count.0.unwrap() as u64;
1249-
1242+
let database_sharding_algo = meta_base_info.algo.0.unwrap();
1243+
let table_sharding_algo = meta_base_info.algo.1.unwrap();
1244+
let database_sharding_count = meta_base_info.count.0.unwrap() as u64;
1245+
let table_sharding_count = meta_base_info.count.1.unwrap() as u64;
1246+
12501247
let db_value = db_value
12511248
.ok_or_else(|| ShardingRewriteError::CalcShardingIdxError)?
12521249
.parse::<u64>()
12531250
.map_err(ShardingRewriteError::from)?;
12541251
let db_idx = db_value
1255-
.calc(algo, sharding_count)
1252+
.calc(database_sharding_algo, database_sharding_count)
12561253
.ok_or_else(|| ShardingRewriteError::CalcShardingIdxError)?;
12571254

12581255
let table_value = table_value
12591256
.ok_or_else(|| ShardingRewriteError::CalcShardingIdxError)?
12601257
.parse::<u64>()
12611258
.map_err(ShardingRewriteError::from)?;
12621259
let table_idx = table_value
1263-
.calc(algo, sharding_count)
1260+
.calc(table_sharding_algo, table_sharding_count)
12641261
.ok_or_else(|| ShardingRewriteError::CalcShardingIdxError)?;
12651262

12661263
Ok((db_idx, table_idx))
@@ -1640,7 +1637,6 @@ impl ShardingRewrite {
16401637
let db = table.schema.as_ref().unwrap_or_else(|| self.default_db.as_ref().unwrap());
16411638

16421639
let mut target = String::with_capacity(db.len());
1643-
16441640
if actual_db.is_empty() {
16451641
target.push('`');
16461642
target.push_str(db);

0 commit comments

Comments
 (0)