apache-spark - Apache Spark - 使用和不使用案例类的性能
问题描述
我有 2 个数据集,客户和订单
我想同时加入客户密钥。
我尝试了两种方法,一种使用案例类,一种不使用。
使用案例类: -> 只需要永远完成 - 几乎 11 分钟
case class Customer(custKey: Int, name: String, address: String, phone: String, acctBal: String, mktSegment: String, comment: String) extends Serializable
case class Order(orderKey: Int, custKey: Int, orderStatus: String, totalPrice: Double, orderDate: String, orderQty: String, clerk: String, shipPriority: String, comment: String) extends Serializable
val customers = sc.textFile("customersFile").map(row => row.split('|')).map(cust => (cust(0).toInt, Customer(cust(0).toInt, cust(1), cust(2), cust(3), cust(4), cust(5), cust(6))))
val orders = sc.textFile("ordersFile").map(row => row.split('|')).map(order => (order(1).toInt, Order(order(0).toInt, order(1).toInt, order(2), order(3).toDouble, order(4), order(5), order(6), order(7), order(8))))
orders.join(customers).take(1)
没有案例类——几秒钟内完成
val customers = sc.textFile("customersFile").map(row => row.split('|'))
val orders = sc.textFile("ordersFile").map(row => row.split('|'))
val customersByCustKey = customers.map(row => (row(0), row)) // customer key is the first column in customers rdd, hence row(0)
val ordersByCustKey = orders.map(row => (row(1), row)) // customer key is the second column in orders rdd, hence row(1)
ordersByCustKey.join(customersByCustKey).take(1)
想知道这是否是由于使用案例类时序列化/反序列化所花费的时间?
如果是,建议在哪些情况下使用案例类?
解决方案
推荐阅读
- string - 在 DrRacket 中,我如何更改使用 if 语句的程序以使用条件语句
- css - 材料设计风格适用于一个模块,但不适用于另一个模块
- java - 为什么枚举不会导致无限递归?
- c# - 如何将动态 json 属性反序列化为对象?
- xcode - 从垃圾箱中恢复已删除的项目
- sql - 如果日期已经在两个值之间,如何选择日期sql server
- create-react-app - React 中没有过滤结果时如何呈现消息?
- android - Android Studio 中的 Google Maps Flutter 出错
- python - 通过“工作流程”将数据发布到数据库(例如:字段更改为 20,创建新记录)
- laravel - 如何修复“Illuminate\Support\Collection::get(), 0passed in /AMPPS/www/lsapp/vendor/laravel/framework/src/Illuminate/Support/Traits/ForwardsCalls.php”