Skip to content
Open
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
7 changes: 4 additions & 3 deletions pgdog/src/frontend/router/parser/query/delete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ use super::*;
impl QueryParser {
pub(super) fn delete(
&mut self,
stmt: &DeleteStmt,
#[cfg(feature = "new_parser")] new_stmt: pg_raw_parse::Node<'_>,
#[cfg(not(feature = "new_parser"))] stmt: &DeleteStmt,
#[cfg(feature = "new_parser")] stmt: pg_raw_parse::Node<'_>,
context: &mut QueryParserContext,
) -> Result<Command, Error> {
let mut parser = StatementParser::from_delete(
#[cfg(not(feature = "new_parser"))]
stmt,
#[cfg(feature = "new_parser")]
new_stmt,
stmt,
context.router_context.bind,
&context.sharding_schema,
self.recorder_mut(),
Expand Down
6 changes: 6 additions & 0 deletions pgdog/src/frontend/router/parser/query/explain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,25 @@ impl QueryParser {
new_stmt,
context,
),
#[cfg_attr(feature = "new_parser", allow(unused))]
NodeEnum::InsertStmt(stmt) => self.insert(
#[cfg(not(feature = "new_parser"))]
stmt,
#[cfg(feature = "new_parser")]
new_stmt,
context,
),
#[cfg_attr(feature = "new_parser", allow(unused))]
NodeEnum::UpdateStmt(stmt) => self.update(
#[cfg(not(feature = "new_parser"))]
stmt,
#[cfg(feature = "new_parser")]
new_stmt,
context,
),
#[cfg_attr(feature = "new_parser", allow(unused))]
NodeEnum::DeleteStmt(stmt) => self.delete(
#[cfg(not(feature = "new_parser"))]
stmt,
#[cfg(feature = "new_parser")]
new_stmt,
Expand Down
13 changes: 10 additions & 3 deletions pgdog/src/frontend/router/parser/query/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -314,21 +314,27 @@ impl QueryParser {
// COPY statements.
Some(NodeEnum::CopyStmt(ref stmt)) => Self::copy(stmt, context),
// INSERT statements.
#[cfg_attr(feature = "new_parser", allow(unused))]
Some(NodeEnum::InsertStmt(ref stmt)) => self.insert(
#[cfg(not(feature = "new_parser"))]
stmt,
#[cfg(feature = "new_parser")]
new_root,
context,
),
// UPDATE statements.
#[cfg_attr(feature = "new_parser", allow(unused))]
Some(NodeEnum::UpdateStmt(ref stmt)) => self.update(
#[cfg(not(feature = "new_parser"))]
stmt,
#[cfg(feature = "new_parser")]
new_root,
context,
),
// DELETE statements.
#[cfg_attr(feature = "new_parser", allow(unused))]
Some(NodeEnum::DeleteStmt(ref stmt)) => self.delete(
#[cfg(not(feature = "new_parser"))]
stmt,
#[cfg(feature = "new_parser")]
new_root,
Expand Down Expand Up @@ -552,8 +558,8 @@ impl QueryParser {
///
fn insert(
&mut self,
stmt: &InsertStmt,
#[cfg(feature = "new_parser")] new_stmt: pg_raw_parse::Node<'_>,
#[cfg(not(feature = "new_parser"))] stmt: &InsertStmt,
#[cfg(feature = "new_parser")] stmt: pg_raw_parse::Node<'_>,
context: &mut QueryParserContext,
) -> Result<Command, Error> {
let schema_lookup = SchemaLookupContext {
Expand All @@ -562,9 +568,10 @@ impl QueryParser {
search_path: context.router_context.parameter_hints.search_path,
};
let mut parser = StatementParser::from_insert(
#[cfg(not(feature = "new_parser"))]
stmt,
#[cfg(feature = "new_parser")]
new_stmt,
stmt,
context.router_context.bind,
&context.sharding_schema,
self.recorder_mut(),
Expand Down
2 changes: 2 additions & 0 deletions pgdog/src/frontend/router/parser/query/select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ impl QueryParser {

let (advisory_locks, mut omnisharded) = {
let mut parser = StatementParser::from_select(
#[cfg(not(feature = "new_parser"))]
stmt,
#[cfg(feature = "new_parser")]
new_stmt,
Expand All @@ -67,6 +68,7 @@ impl QueryParser {

let (shard, is_sharded, tables) = {
let mut statement_parser = StatementParser::from_select(
#[cfg(not(feature = "new_parser"))]
stmt,
#[cfg(feature = "new_parser")]
new_stmt,
Expand Down
6 changes: 4 additions & 2 deletions pgdog/src/frontend/router/parser/query/test/test_insert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ fn test_insert_multi_row() {
}

#[test]
#[cfg_attr(not(feature = "new_parser"), should_panic)] // Fixed in port
fn test_insert_select() {
let mut test = QueryParserTest::new();

Expand All @@ -77,10 +78,11 @@ fn test_insert_select() {
]);

assert!(command.route().is_write());
assert!(command.route().is_all_shards());
assert!(command.route().shard().is_direct());
}

#[test]
#[cfg_attr(not(feature = "new_parser"), should_panic)] // Fixed in port
fn test_insert_default_values() {
let mut test = QueryParserTest::new();

Expand All @@ -89,5 +91,5 @@ fn test_insert_default_values() {
]);

assert!(command.route().is_write());
assert!(command.route().is_all_shards());
assert!(command.route().shard().is_direct());
}
7 changes: 4 additions & 3 deletions pgdog/src/frontend/router/parser/query/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ use super::*;
impl QueryParser {
pub(super) fn update(
&mut self,
stmt: &UpdateStmt,
#[cfg(feature = "new_parser")] new_stmt: pg_raw_parse::Node<'_>,
#[cfg(not(feature = "new_parser"))] stmt: &UpdateStmt,
#[cfg(feature = "new_parser")] stmt: pg_raw_parse::Node<'_>,
context: &mut QueryParserContext,
) -> Result<Command, Error> {
let mut parser = StatementParser::from_update(
#[cfg(not(feature = "new_parser"))]
stmt,
#[cfg(feature = "new_parser")]
new_stmt,
stmt,
context.router_context.bind,
&context.sharding_schema,
self.recorder_mut(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ impl StatementRewrite<'_> {
if let NodeEnum::InsertStmt(insert) = node.node.as_ref()? {
let relation = insert.relation.as_ref()?;
let is_sharded = StatementParser::from_insert(
#[cfg(not(feature = "new_parser"))]
insert,
#[cfg(feature = "new_parser")]
new_stmt,
Expand Down
Loading
Loading