瀏覽代碼

fix(bin): hive-ddl-gen 字段行逗号位置 + docstring 注明只支 PG 源

(a) DDL 模板逗号原写在 STRING 后("id    STRING, COMMENT 'id'"),
    应在 COMMENT 'xxx' 末尾(Hive DDL 标准);
(b) docstring 顶部加"仅支持 PG 源",非 PG 由 sync gen 的
    resolve_datasource 直接 NotImplementedError。

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
tianyu.chu 1 周之前
父節點
當前提交
e6ce707cb8
共有 2 個文件被更改,包括 10 次插入3 次删除
  1. 5 1
      bin/hive-ddl-gen.py
  2. 5 2
      tests/unit/datax/test_hive_ddl_gen.py

+ 5 - 1
bin/hive-ddl-gen.py

@@ -3,6 +3,10 @@
 """
 Hive DDL 生成器(raw 层;ods 层占位待实施)。
 
+**仅支持 PG 源**:reader.dataSource 必须是 `postgresql/{env}-{instance}`
+形式;mysql 等其他源由复用的 datax-sync-template-gen.resolve_datasource
+直接 NotImplementedError。
+
 输入 sync ini,从 PG 抽字段中文注释,按 reader.column 顺序渲染
 全字段 STRING + dt STRING 分区 + ORC + EXTERNAL TABLE,写到 stdout
 (传 -o 时额外落盘 {table_name}_create.sql)。
@@ -149,7 +153,7 @@ def render_raw_ddl(table_name, columns, comment_dict):
     for i, col in enumerate(columns):
         comma = ',' if i < last_idx else ''
         comment = comment_dict.get(col, '').replace("'", "''")
-        lines.append("    {col:<{w}}STRING{comma} COMMENT '{comment}'".format(
+        lines.append("    {col:<{w}}STRING COMMENT '{comment}'{comma}".format(
             col=col, w=width, comma=comma, comment=comment))
     lines.extend([
         ')',

+ 5 - 2
tests/unit/datax/test_hive_ddl_gen.py

@@ -132,8 +132,11 @@ def test_render_raw_ddl_last_column_no_trailing_comma():
     out = GEN.render_raw_ddl('t', ['a', 'b'], {})
     field_lines = [l for l in out.split('\n') if l.startswith('    ')]
     assert len(field_lines) == 2
-    assert 'STRING,' in field_lines[0]
-    assert 'STRING,' not in field_lines[1]
+    assert field_lines[0].rstrip().endswith(',')
+    assert not field_lines[1].rstrip().endswith(',')
+    # 逗号在 COMMENT 'xxx' 末尾,不在 STRING 后
+    assert 'STRING,' not in out
+    assert "COMMENT ''," in field_lines[0]
 
 
 def test_render_raw_ddl_external_and_drop():