Skip to content

fix the bug about rule_rewrite #26

@BoyuXiao

Description

@BoyuXiao

关于方言规则列表中没有pg的问题

Image

translate.py中一共有三种转换方式,第一种便是sqlglot提供的转换方式,正如这个官方文件https://github.com/tobymao/sqlglot/blob/main/sqlglot/dialects/__init__.py,里面所示,也定义了一个列表,是为了判断方言在不在列表中,进而去正确使用sqlglot方法

Image

为了和官方sqlglot的方言列表完全一致,这里不是选择加入“pg”,因为原来的列表中已经存在“postgres”,甚至还有多余的“postgresql”

修改如下:在utils/constants.py中加入一个映射DIALECT_ABBREVIATIONS来临时转换,并删除原来DIALECT_LIST_RULE列表中冗余的的“postgresql”

Image

对应的translate.py中也需要做对应的修改,即用临时转换映射去暂时把pg变换一下,且不影响后面的其他两种方言转换方式

Image

关于使用rule_rewrite的情况

我认为原来代码translate.py下图的这个地方或许有些错误?应该是源方言和目的方言都在方言规则列表中,才会进行rule_rewrite,修改为如上图所示的and运算符

Image

最后运行结果如下所示,没有问题

Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions