shardingsphere icon indicating copy to clipboard operation
shardingsphere copied to clipboard

Refactor PG/OG statement inheritance relationship

Open RaigorJiang opened this issue 1 year ago • 5 comments

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), 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.

RaigorJiang avatar Oct 12 '23 04:10 RaigorJiang

Hi, can I take a look at this question? Thank you

Before starting to solve the problem, I have some doubts about the OpenGaussAlterRuleStatement inheriting from PostgreSQLAlterRuleExtension on the graph Alter RULE is an extension of PostgreSQL statements. Why should OpenGaussAlterRuleStatement inherit from PostgreSQLAlterRuleExtension? Does this indicate that the OpenGaussAlterRuleStatement dialect is based on an extension of PostgreSQL? Additionally, I did not find a description of the Alter RULE statement on the official OpenGauss documentation, as this SQL statement does not seem to belong to the dialect of OpenGauss

141102

zihaoAK47 avatar Oct 27 '23 06:10 zihaoAK47

@zihaoAK47 It is in the 2.0 documentation (link)

In fact, openGauss has so many similarities with PostgreSQL (SQL protocol and syntax), so we should sort out the common parts and reuse them in ShardingSphere. At the same time, since some statements do not belong to the SQL standards, they should be placed under the PostgreSQL extension.

RaigorJiang avatar Oct 27 '23 07:10 RaigorJiang

However, letting openGauss inherit the PostgreSQL class will also lead to a large number of duplicate Classes. It may be necessary to redesign how to reduce duplicate classes.

RaigorJiang avatar Oct 27 '23 07:10 RaigorJiang

@zihaoAK47 It is in the 2.0 documentation (link)

In fact, openGauss has so many similarities with PostgreSQL (SQL protocol and syntax), so we should sort out the common parts and reuse them in ShardingSphere. At the same time, since some statements do not belong to the SQL standards, they should be placed under the PostgreSQL extension.

Thank you for your reply. I understand

zihaoAK47 avatar Oct 27 '23 07:10 zihaoAK47

There hasn't been any activity on this issue recently, and in order to prioritize active issues, it will be marked as stale.

github-actions[bot] avatar Nov 26 '23 20:11 github-actions[bot]