Joe 9 月之前
父節點
當前提交
ee4674543f
共有 1 個文件被更改,包括 16 次插入7 次删除
  1. 16 7
      qiaojialiang/checkHiveDataUtil.py

+ 16 - 7
qiaojialiang/checkHiveDataUtil.py

@@ -40,14 +40,23 @@ def check_data(project, table, partitionDt, partitionDtHh) -> int:
     try:
         t = odps.get_table(name=table)
         # check_res = t.exist_partition(partition_spec=f'dt={partition}')
-        check_res = t.exist_partition(partition_spec=f'dt={partitionDt},hh={partitionDtHh}')
-        if check_res:
-            # sql = f'select * from {project}.{table} where dt = {partition} limit 0,100'
-            sql = f'select * from {project}.{table} where dt = {partitionDt} and hh={partitionDtHh}'
-            with odps.execute_sql(sql=sql).open_reader() as reader:
-                data_count = reader.count
+        # 含有hh分区
+        if not {partitionDtHh}:
+            check_res = t.exist_partition(partition_spec=f'dt={partitionDt},hh={partitionDtHh}')
+            if check_res:
+                sql = f'select * from {project}.{table} where dt = {partitionDt} and hh={partitionDtHh}'
+                with odps.execute_sql(sql=sql).open_reader() as reader:
+                    data_count = reader.count
+            else:
+                data_count = 0
         else:
-            data_count = 0
+            check_res = t.exist_partition(partition_spec=f'dt={partitionDt}')
+            if check_res:
+                sql = f'select * from {project}.{table} where dt = {partitionDt}'
+                with odps.execute_sql(sql=sql).open_reader() as reader:
+                    data_count = reader.count
+            else:
+                data_count = 0
     except Exception as e:
         print("error:" + str(e))
         data_count = 0