diff --git a/src/main/java/com/google/cloud/spanner/pgadapter/statements/TableParser.java b/src/main/java/com/google/cloud/spanner/pgadapter/statements/TableParser.java index 4bf2aa30c..1a09e2e59 100644 --- a/src/main/java/com/google/cloud/spanner/pgadapter/statements/TableParser.java +++ b/src/main/java/com/google/cloud/spanner/pgadapter/statements/TableParser.java @@ -89,21 +89,13 @@ Tuple, Statement> detectAndReplaceTables( parseTableList(detectAndReplaceMap, replacedTables, detectedTablesBuilder, multipleTables) || detectedOrReplacedTable; } - // Reset to start and search for the WHERE clause. + // Reset to start replace full-qualified column names of tables that have been replaced. parser.setPos(0); - parser.parseExpressionUntilKeyword(ImmutableList.of("where"), true, false, false); - // Check whether we found a keyword. - if (parser.peekKeyword("where")) { - int positionBeforeWhereClause = parser.getPos(); - String replaced = - replaceFullyQualifiedColumnNames( - detectAndReplaceMap, - replacedTables, - positionBeforeWhereClause, - parser.getSql().length()); - if (replaced != null) { - parser.setSql(parser.getSql().substring(0, positionBeforeWhereClause) + replaced); - } + String replaced = + replaceFullyQualifiedColumnNames( + detectAndReplaceMap, replacedTables, 0, parser.getSql().length()); + if (replaced != null) { + parser.setSql(replaced); } return detectedOrReplacedTable diff --git a/src/test/java/com/google/cloud/spanner/pgadapter/statements/TableParserTest.java b/src/test/java/com/google/cloud/spanner/pgadapter/statements/TableParserTest.java index 31747e710..0e2fe3cfe 100644 --- a/src/test/java/com/google/cloud/spanner/pgadapter/statements/TableParserTest.java +++ b/src/test/java/com/google/cloud/spanner/pgadapter/statements/TableParserTest.java @@ -139,12 +139,12 @@ public void testReplaceTables() { "pg_type")); assertEquals( Statement.of( - "select * from pg_namespace " + "select pg_class.relname from pg_namespace " + "inner join pg_class on pg_namespace.oid = pg_class.relnamespace " + "where pg_class.relname = $1::VARCHAR AND pg_class.relkind = ANY (ARRAY[$2::VARCHAR, $3::VARCHAR, $4::VARCHAR, $5::VARCHAR, $6::VARCHAR]) AND true AND pg_namespace.nspname != $7::VARCHAR'"), replace( Statement.of( - "select * from pg_catalog.pg_namespace " + "select pg_catalog.pg_class.relname from pg_catalog.pg_namespace " + "inner join pg_catalog.pg_class on pg_catalog.pg_namespace.oid = pg_catalog.pg_class.relnamespace " + "where pg_catalog.pg_class.relname = $1::VARCHAR AND pg_catalog.pg_class.relkind = ANY (ARRAY[$2::VARCHAR, $3::VARCHAR, $4::VARCHAR, $5::VARCHAR, $6::VARCHAR]) AND true AND pg_catalog.pg_namespace.nspname != $7::VARCHAR'"), ImmutableMap.of(