Explorar el Código

更新查询hive方式

xueyiming hace 3 semanas
padre
commit
8992cf4bb6
Se han modificado 1 ficheros con 2 adiciones y 13 borrados
  1. 2 13
      ad/pai_flow_operator2.py

+ 2 - 13
ad/pai_flow_operator2.py

@@ -49,21 +49,10 @@ def get_data_from_odps(project, table, num):
         sql = f'select * from {table} limit {num}'
         # 执行 SQL 查询
         with odps.execute_sql(sql).open_reader() as reader:
+            df = reader.to_pandas()
             # 查询数量小于目标数量时 返回空
-            if reader.count < num:
+            if len(df) < num:
                 return None
-            # 获取字段名称
-            column_names = reader.schema.names
-            # 获取查询结果数据
-            data = []
-            for record in reader:
-                record_list = list(record)
-                numbers = []
-                for item in record_list:
-                    numbers.append(item[1])
-                data.append(numbers)
-            # 将数据和字段名称组合成 DataFrame
-            df = pd.DataFrame(data, columns=column_names)
             return df
     except Exception as e:
         print(f"发生错误: {e}")