Skip to content

Commit

Permalink
fix: updated the regex expression to correctly identify the table nam… (
Browse files Browse the repository at this point in the history
#35361)

**Description**

When the user tries to add a postgres datasource and add any query, if
the table name has hyphens in it, then quotes get assigned to first word
after the schema and the dot. For example, public."counter"-with-db
The quotes should be applied to the whole table name. For example:
public."counter-with-db"

Fixes #10631
Fixes #30692

**changes in PR:**

1.updated the regec expression to idetify the table name properly with
table name consists of hypens.

2.added a test case for this scenario.

**snapshots:**
before:

![Screenshot from 2024-07-30
17-15-27](https://github.com/user-attachments/assets/98f969da-4cf1-4367-be29-1f3465179a9d)

After:

![Screenshot from 2024-08-01
10-46-53](https://github.com/user-attachments/assets/29411eb7-77af-4a10-9988-a0c076043945)


Hi @ajinkyakulkarni @rohan-arthur @Nikhil-Nandagopal ,Please review this
PR.

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

## Summary by CodeRabbit

- **New Features**
- Enhanced handling of table names in the Postgres plugin to support a
wider variety of characters, including hyphens and special characters.
- Introduced multiple new database tables for improved testing coverage.

- **Bug Fixes**
- Adjusted table name processing to correctly format names containing a
broader range of characters.

- **Tests**
- Added new tests to verify the structure and integrity of tables with
various naming conventions.
	- Expanded existing tests to accommodate additional table structures.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
  • Loading branch information
Naveen-Goud committed Aug 27, 2024
1 parent 7053632 commit cbd7ccc
Show file tree
Hide file tree
Showing 2 changed files with 311 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -884,7 +884,7 @@ public Mono<DatasourceStructure> getStructure(
setFragments.deleteCharAt(setFragments.length() - 1);
}

final String quotedTableName = table.getName().replaceFirst("\\.(\\w+)", ".\"$1\"");
final String quotedTableName = table.getName().replaceFirst("\\.(.+)", ".\"$1\"");
table.getTemplates()
.addAll(List.of(
new DatasourceStructure.Template(
Expand Down
Loading

0 comments on commit cbd7ccc

Please sign in to comment.