datax_json.py 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. from typing import List, Optional
  2. from pydantic import BaseModel
  3. class HiveReaderParam(BaseModel):
  4. reader_path: str
  5. reader_default_fs: Optional[str]
  6. reader_file_type: str
  7. reader_field_delimiter: Optional[str]
  8. reader_skip_header: Optional[str]
  9. class HiveWriterParam(BaseModel):
  10. writer_default_fs: Optional[str]
  11. writer_file_type: str
  12. writer_path: str
  13. writer_filename: str
  14. writer_mode: Optional[str]='append'
  15. writer_field_delimiter: Optional[str]
  16. class RdbmsReaderParam(BaseModel):
  17. reader_split_pk: Optional[str] = ''
  18. where_param: Optional[str] = ''
  19. query_sql: Optional[str]
  20. class RdbmsWriterParam(BaseModel):
  21. pre_sql: Optional[str] = ''
  22. post_sql: Optional[str] = ''
  23. class DataXJsonParam(BaseModel):
  24. reader_datasource_id: Optional[int]
  25. reader_type: str # datasource、datalake、ailab
  26. reader_tables: List[str] = []
  27. reader_columns: List[str] = []
  28. writer_datasource_id: Optional[int]
  29. writer_type: str # datasource、ailab
  30. writer_tables: List[str] = []
  31. writer_columns: List[str] = []
  32. hive_reader: Optional[HiveReaderParam]
  33. hive_writer: Optional[HiveWriterParam]
  34. rdbms_reader: Optional[RdbmsReaderParam]
  35. rdbms_writer: Optional[RdbmsWriterParam]
  36. class Config:
  37. schema_extra = {
  38. 'examples': {
  39. 'mysql2mysql': {
  40. "reader_datasource_id": 18,
  41. "reader_type": "datasource",
  42. "reader_tables": ["job_group_copy1"],
  43. "reader_columns": ["0:id:int", "1:app_name:varchar(20)", "2:title:varchar(20)", "3:address_type:varchar(20)"],
  44. "writer_datasource_id": 18,
  45. "writer_type": "datasource",
  46. "writer_tables": ["job_group_copy2"],
  47. "writer_columns": ["0:id:int", "1:app_name:varchar(20)", "2:title:varchar(20)", "3:address_type:varchar(20)"],
  48. "rdbms_reader": {
  49. "reader_split_pk": "",
  50. "where_param": "",
  51. "query_sql": ""
  52. },
  53. "rdbms_writer": {
  54. "pre_sql": "delete from job_group_copy2",
  55. "post_sql": ""
  56. }
  57. },
  58. 'mysql2hive': {
  59. "reader_datasource_id": 18,
  60. "reader_type": "datasource",
  61. "reader_tables": ["grades"],
  62. "reader_columns": ["id", "ssn", "test2"],
  63. "writer_datasource_id": 17,
  64. "writer_type": "datasource",
  65. "writer_columns": ["0:id:int", "1:ssn:varchar", "2:test2:int"],
  66. "writer_tables": [],
  67. "rdbms_reader": {
  68. "reader_split_pk": "",
  69. "where_param": "",
  70. "query_sql": ""
  71. },
  72. "hive_writer": {
  73. "writer_default_fs": "hdfs://192.168.199.107:9000",
  74. "writer_file_type": "text",
  75. "writer_path": "/usr/hive/warehouse/test_1",
  76. "writer_filename": "test_1",
  77. "writer_mode": "append",
  78. "writer_field_delimiter": "|"
  79. }
  80. },
  81. 'hive2mysql': {
  82. "reader_datasource_id": 17,
  83. "reader_type": "datasource",
  84. "reader_tables": ["grades"],
  85. "reader_columns": ["0:id:int", "3:ssn:varchar", "5:test2:int"],
  86. "writer_datasource_id": 18,
  87. "writer_type": "datasource",
  88. "writer_tables": ["grades"],
  89. "writer_columns": ["0:id:int", "1:ssn:varchar", "2:test2:int"],
  90. "hive_reader": {
  91. "reader_default_fs": "hdfs://192.168.199.107:9000",
  92. "reader_file_type": "csv",
  93. "reader_path": "/usr/hive/warehouse/grades/*",
  94. "reader_field_delimiter": ",",
  95. "reader_skip_header": "true"
  96. },
  97. "rdbms_writer": {
  98. "pre_sql": "delete from grades;",
  99. "post_sql": ""
  100. }
  101. }
  102. }
  103. }
  104. # class Config:
  105. # schema_extra = {
  106. # "example": {
  107. # "reader_datasource_id": 18,
  108. # "reader_tables": ["job_group_copy1"],
  109. # "reader_columns": ["id", "app_name", "title", "address_type"],
  110. # "writer_datasource_id": 18,
  111. # "writer_tables": ["job_group_copy2"],
  112. # "writer_columns": ["id", "app_name", "title", "address_type"],
  113. # "rdbms_reader": {
  114. # "reader_split_pk": "",
  115. # "where_param": "",
  116. # "query_sql": ""
  117. # },
  118. # "rdbms_writer": {
  119. # "pre_sql": "delete from job_group_copy2",
  120. # "post_sql": ""
  121. # }
  122. # }
  123. # "example": {
  124. # "reader_datasource_id": 18,
  125. # "reader_tables": ["grades"],
  126. # "reader_columns": ["id", "ssn", "test2"],
  127. # "writer_datasource_id": 17,
  128. # "writer_columns": ["id:int", "ssn:string", "test2:int"],
  129. # "writer_tables": ["grades"],
  130. # "rdbms_reader": {
  131. # "reader_split_pk": "",
  132. # "where_param": "",
  133. # },
  134. # "hive_writer": {
  135. # "writer_default_fs": "hdfs://192.168.199.107:9000",
  136. # "writer_file_type": "text",
  137. # "writer_path": "/usr/hive/warehouse/test_1",
  138. # "writer_filename": "test_1",
  139. # "write_mode": "append",
  140. # "write_field_delimiter": "|"
  141. # }
  142. # }
  143. # }
  144. class RWDataSource(BaseModel):
  145. id: Optional[int]
  146. datasource: str # musql/hive
  147. rw_type: str # datasource/datalake/ailab
  148. jdbc_url: Optional[str]
  149. jdbc_username: Optional[str]
  150. jdbc_password: Optional[str]