xueyiming 4 weeks ago
parent
commit
639fa904ed

+ 25 - 1
src/main/scala/com/aliyun/odps/spark/examples/makedata_ad/v20250813/makedata_ad_33_bucketData_add_Feature_20250813.scala

@@ -66,7 +66,31 @@ object makedata_ad_33_bucketData_add_Feature_20250813 {
         leftMap + ("category_name" -> categoryName)
       }
 
-      odpsOps.saveToTable(project, outputTable, partition, result, write, defaultCreate = true, overwrite = true)
+      val resultCount = result.count()
+      println(s"Result contains $resultCount records")
+
+      // 随机输出10条结果
+      val sampleRecords = result.takeSample(withReplacement = false, 10)  // 不重复的随机抽样
+      println("\nRandom sample records:")
+      sampleRecords.zipWithIndex.foreach { case (record, idx) =>
+        println(s"\nSample ${idx + 1}:")
+
+        // 只输出前10个字段,避免输出过长
+        record.take(10).foreach { case (key, value) =>
+          println(s"  $key: ${if (value != null) value.toString.take(50) + (if (value.toString.length > 50) "..." else "") else "null"}")
+        }
+
+        // 如果字段超过10个,显示省略信息
+        if (record.size > 10) {
+          println(s"  ... and ${record.size - 10} more fields")
+        }
+
+        // 特别输出category_name的值
+        val categoryName = record.getOrElse("category_name", "null")
+        println(s"  category_name: $categoryName")
+      }
+
+//      odpsOps.saveToTable(project, outputTable, partition, result, write, defaultCreate = true, overwrite = true)
 
     }
   }