From 795e6bbee671fa9fd769502810ed27801a56499a Mon Sep 17 00:00:00 2001 From: changxing <1278729001@qq.com> Date: Tue, 28 May 2024 13:22:48 +0800 Subject: [PATCH] =?UTF-8?q?#26=EF=BC=9A=E4=BF=AE=E5=A4=8D=20Hive=20?= =?UTF-8?q?=E5=BB=BA=E8=A1=A8=E8=AF=AD=E5=8F=A5=E4=B8=AD=20DECIMAL?= =?UTF-8?q?=E3=80=81VARCHAR=E3=80=81CHAR=20=E7=B1=BB=E5=9E=8B=E6=B2=A1?= =?UTF-8?q?=E6=9C=89=E5=8F=82=E6=95=B0=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- metasequoia_sql/core/node.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/metasequoia_sql/core/node.py b/metasequoia_sql/core/node.py index 1a15281..a0b9edc 100644 --- a/metasequoia_sql/core/node.py +++ b/metasequoia_sql/core/node.py @@ -1348,8 +1348,15 @@ class ASTColumnTypeExpression(ASTBase): params: Optional[Tuple[ASTExpressionBase, ...]] = dataclasses.field(kw_only=True, default=None) def source(self, sql_type: SQLType = SQLType.DEFAULT) -> str: - """返回语法节点的 SQL 源码""" - if self.params is None or sql_type == SQLType.HIVE: + """返回语法节点的 SQL 源码 + + TODO:后续计划将类型的处理,移动到翻译器中,而不是放置在 Node 节点中,因为这并不是一个适用于所有应用场景的功能,可能会引发特殊的 Bug + """ + # 如果没有参数,则不添加参数 + if self.params is None: + return self.name + # 如果为 Hive 中没有参数的类型,也不添加参数 + if sql_type == SQLType.HIVE and self.name.upper() not in {"DECIMAL", "VARCHAR", "CHAR"}: return self.name # MySQL 标准导出逗号间没有空格 type_params = "(" + ",".join([param.source(sql_type) for param in self.params]) + ")"