Skip to content

Commit 3b5c98c

Browse files
authored
Fix comments with SET (#492)
* Fix comments with SET * Add test case
1 parent 9553e6c commit 3b5c98c

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

pgdog/src/frontend/router/parser/query/set.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,14 @@ impl QueryParser {
121121
}
122122
}
123123

124+
let shard = if let Shard::Direct(_) = self.shard {
125+
self.shard.clone()
126+
} else {
127+
Shard::All
128+
};
129+
124130
Ok(Command::Query(
125-
Route::write(Shard::All).set_read(context.read_only),
131+
Route::write(shard).set_read(context.read_only),
126132
))
127133
}
128134
}

pgdog/src/frontend/router/parser/query/test.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -545,3 +545,20 @@ fn test_dry_run_simple() {
545545
assert_eq!(stmt.stats.lock().multi, 0);
546546
assert_eq!(command.route().shard(), &Shard::Direct(0));
547547
}
548+
549+
#[test]
550+
fn test_set_comments() {
551+
let command = query_parser!(
552+
QueryParser::default(),
553+
Query::new("/* pgdog_sharding_key: 1234 */ SET statement_timeout TO 1"),
554+
true
555+
);
556+
assert_eq!(command.route().shard(), &Shard::Direct(0));
557+
558+
let command = query_parser!(
559+
QueryParser::default(),
560+
Query::new("SET statement_timeout TO 1"),
561+
true
562+
);
563+
assert_eq!(command.route().shard(), &Shard::All);
564+
}

0 commit comments

Comments
 (0)