apache / apache/shardingsphere

Refactor PG/OG statement inheritance relationship

Open
#28,728 5 comments 0 reactions 0 assignees View on GitHub
in: SQL parse status: pending type: refactor
Dominant language
Java
Stars
20.8k
Forks
6.9k
Avg merge
11h 35m
Merged PRs (30d)
326

Description

`Alter rule` is not a standard SQL, it belongs to the PG dialect.
Therefore `AlterRuleStatement` should not exist under the `common` package.

image

Since `ALTER RULE` is a PostgreSQL language extension (see [Compatibility](https://www.postgresql.org/docs/16/sql-alterrule.html)), I want to add a package `extension` under `statement/postgresql/ddl` and rename `AlterRuleStatement` to `PostgreSQLAlterRuleExtension` so that `PostgreSQLAlterRuleStatement` and `OpenGaussAlterRuleStatement` can inherit it.

image

Why not let `OpenGaussAlterRuleStatement` directly inherit from `PostgreSQLAlterRuleStatement`?
Because `PostgreSQLAlterRuleStatement` implements the interface `PostgreSQLStatement`, and `OpenGaussAlterRuleStatement` needs to implement `OpenGaussStatement`, this is in conflict.

### shardingsphere-parser-sql-statement
- Before

```
.
├── common
│   ├── enums
│   ├── extractor
│   ├── segment
│   ├── statement
│   ├── util
│   └── value
└── dialect
├── handler
├── segment
└── statement
├── mysql
│   ├── dal
│   ├── dcl
│   ├── ddl
│   ├── dml
│   ├── rl
│   ├── segment
│   └── tcl
├── opengauss
│   ├── dal
│   ├── dcl
│   ├── ddl
│   ├── dml
│   └── tcl
├── oracle
│   ├── dal
│   ├── dcl
│   ├── ddl
│   ├── dml
│   └── tcl
├── postgresql
│   ├── dal
│   ├── dcl
│   ├── ddl
│   ├── dml
│   └── tcl
├── sql92
│   ├── dcl
│   ├── ddl
│   ├── dml
│   └── tcl
└── sqlserver
├── dal
├── dcl
├── ddl
├── dml
└── tcl
```

- After
```
.
├── common
│   ├── enums
│   ├── extractor
│   ├── segment
│   ├── statement
│   ├── util
│   └── value
└── dialect
├── handler
├── segment
└── statement
├── mysql
│   ├── dal
│   ├── dcl
│   ├── ddl
│   ├── dml
│   ├── rl
│   ├── segment
│   └── tcl
├── opengauss
│   ├── dal
│   ├── dcl
│   ├── ddl
│   ├── dml
│   └── tcl
├── oracle
│   ├── dal
│   ├── dcl
│   ├── ddl
│   ├── dml
│   └── tcl
├── postgresql
│   ├── dal
│   ├── dcl
│   ├── ddl
│   │   └── extension * (new package)
│   ├── dml
│   └── tcl
├── sql92
│   ├── dcl
│   ├── ddl
│   ├── dml
│   └── tcl
└── sqlserver
├── dal
├── dcl
├── ddl
├── dml
└── tcl

```

Similarly, there are other dialect extensions that can be refactored in this way.

Contributor guide

Open the contributing guide

Research direction

Start in the shardingsphere-parser-sql-statement module by locating AlterRuleStatement and the PostgreSQLAlterRuleStatement and OpenGaussAlterRuleStatement classes. Review their current packages and interfaces, then move the shared extension relationship into dialect/statement/postgresql/ddl/extension and verify that both dialect statements inherit it without losing their dialect-specific interfaces; consider whether the similarly mentioned dialect extensions are in scope.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, postgresql
Domain
databases
Issue type
Refactor
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.