解决错误requirement failed: numRecords must not be negative

记录spark程序启动时报错修复过程

1、问题:

spark程序挂掉几天后重启报错如下信息java.lang.IllegalArgumentException: requirement failed: numRecords must not be negative在这里插入图片描述

2、解决方案

未尝试方案1,结合环境用方案2解决
(方案1)在网上查询有说报错的原因是:删除已经使用过的kafka topic,然后新建同名topic。可以通过把topic名字换一下解决
(方案2)由于本环境offset是存储在hbase里的,有专门的offset表维护,故登录hbase,找到对应的offset表进行清空
命令:truncate 'spark:sparkoffset’

清空后重启可以正常运行

3、分析

出现这种情况是程序挂了后没有及时同步offset到hbase,导致kafka的offset和hbase存储的offset已经对应不上,hbase存储的offset已经过期了,故情况里面的offset,重新消费kafka数据,这种方式有重复消费的风险,对数据精密性要求高的谨慎操作

  • 2
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
这里是一个简单的 Spark 数据生成器,可以生成包含 `title`、`author`、`price`、`sales`、`rating` 和 `publishTime` 字段的数据。 ```scala import org.apache.spark.sql.{DataFrame, Row, SparkSession} import java.sql.Timestamp import scala.util.Random object DataGenerator { def generateData(spark: SparkSession, numRecords: Int): DataFrame = { val titles = Seq("The Great Gatsby", "To Kill a Mockingbird", "1984", "Pride and Prejudice", "The Catcher in the Rye", "The Hobbit", "The Lord of the Rings", "Animal Farm", "The Diary of a Young Girl", "The Hitchhiker's Guide to the Galaxy") val authors = Seq("F. Scott Fitzgerald", "Harper Lee", "George Orwell", "Jane Austen", "J.D. Salinger", "J.R.R. Tolkien", "George Orwell", "J.R.R. Tolkien", "Anne Frank", "Douglas Adams") val prices = Seq(9.99, 12.99, 14.99, 19.99, 24.99, 29.99, 34.99, 39.99, 44.99, 49.99) val sales = Seq(100, 200, 300, 400, 500, 600, 700, 800, 900, 1000) val ratings = Seq(3.5, 4.0, 4.5, 5.0) val dates = Seq("2021-01-01", "2021-02-01", "2021-03-01", "2021-04-01", "2021-05-01", "2021-06-01", "2021-07-01", "2021-08-01", "2021-09-01", "2021-10-01") val random = new Random() val data = (1 to numRecords).map { i => val title = titles(random.nextInt(titles.length)) val author = authors(random.nextInt(authors.length)) val price = prices(random.nextInt(prices.length)) val sale = sales(random.nextInt(sales.length)) val rating = ratings(random.nextInt(ratings.length)) val date = Timestamp.valueOf(dates(random.nextInt(dates.length)) + s" ${random.nextInt(24)}:${random.nextInt(60)}:${random.nextInt(60)}") Row(title, author, price, sale, rating, date.toString) } val schema = spark.sqlContext.createDataFrame(Seq.empty[Row]).schema .add("title", "string") .add("author", "string") .add("price", "double") .add("sales", "int") .add("rating", "double") .add("publishTime", "string") spark.createDataFrame(data, schema) } } ``` 调用 `generateData` 函数即可生成指定数量的数据,例如: ```scala val numRecords = 1000 val data = DataGenerator.generateData(spark, numRecords) data.show() ```

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值