我试图从cassandra中按时间查询大块数据,然后使用spark数据集来一次处理较小的块,但是,应用程序失败并出现无效的查询异常:
WARN 2018-11-22 13:16:54 org.apache.spark.scheduler.TaskSetManager: Lost task 0.0 in stage 2.0 (TID 5, 192.168.1.212, executor 0): java.io.IOException: Exception during preparation of SELECT "userid", "event_time", "value" FROM "user_1234"."data" WHERE token("userid") > ? AND token("userid") <= ? AND "event_time" >= ? AND "event_time" >= ? AND "event_time" <= ? ALLOW FILTERING: More than one restriction was found for the start bound on event_time
at com.datastax.spark.connector.rdd.CassandraTableScanRDD.createStatement(CassandraTableScanRDD.scala:323)
at com.datastax.spark.connector.rdd.CassandraTableScanRDD.com$datastax$spark$connector$rdd$CassandraTableScanRDD
$$ fetchTokenRange(CassandraTableScanRDD.scala:339) at com.datastax.spark.connector.rdd.CassandraTableScanRDD $$
anonfun$17.apply(CassandraTableScanRDD.scala:366)
at com.datastax.spark.connector.rdd.CassandraTableScanRDD
$$ anonfun$17.apply(CassandraTableScanRDD.scala:366) at scala.collection.Iterator $$
anon$12.nextCur(Iterator.scala:434)
at scala.collection.Iterator
$$ anon$12.hasNext(Iterator.scala:440) at com.datastax.spark.connector.util.CountingIterator.hasNext(CountingIterator.scala:12) at scala.collection.Iterator $$
anon$11.hasNext(Iterator.scala:408)
at org.apache.spark.sql.catalyst.expressions.GeneratedClass$GeneratedIterator.processNext(Unknown Source)
at org.apache.spark.sql.execution.BufferedRowIterator.hasNext(BufferedRowIterator.java:43)
at org.apache.spark.sql.execution.WholeStageCodegenExec
$$ anonfun$8 $$
anon$1.hasNext(WholeStageCodegenExec.scala:395)
at org.apache.spark.sql.execution.SparkPlan
$$ anonfun$2.apply(SparkPlan.scala:234) at org.apache.spark.sql.execution.SparkPlan $$
anonfun$2.apply(SparkPlan.scala:228)
at org.apache.spark.rdd.RDD
$$ anonfun$mapPartitionsInternal$1 $$
anonfun$apply$25.apply(RDD.scala:827)
at org.apache.spark.rdd.RDD
$$ anonfun$mapPartitionsInternal$1 $$
anonfun$apply$25.apply(RDD.scala:827)
at org.apache.spark.rdd.MapPartitionsRDD.compute(MapPartitionsRDD.scala:38)
at org.apache.spark.rdd.RDD.computeOrReadCheckpoint(RDD.scala:323)
at org.apache.spark.rdd.RDD.iterator(RDD.scala:287)
at org.apache.spark.scheduler.ResultTask.runTask(ResultTask.scala:87)
at org.apache.spark.scheduler.Task.run(Task.scala:109)
at org.apache.spark.executor.Executor$TaskRunner.run(Executor.scala:338)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
Caused by: com.datastax.driver.core.exceptions.InvalidQueryException: More than one restriction was found for the start bound on event_time
at com.datastax.driver.core.exceptions.InvalidQueryException.copy(InvalidQueryException.java:41)
at com.datastax.driver.core.DriverThrowables.propagateCause(DriverThrowables.java:28)
at com.datastax.driver.core.AbstractSession.prepare(AbstractSession.java:108)
at com.datastax.driver.dse.DefaultDseSession.prepare(DefaultDseSession.java:278)
at com.datastax.spark.connector.cql.PreparedStatementCache$.prepareStatement(PreparedStatementCache.scala:45)
这是我试图执行的代码段:
case class RawDataModel(userid: String, event_time: Long, value: Double)
var dtRangeEnd = System.currentTimeMillis()
var dtRangeStart = (dtRangeEnd - (60 60 1000).toLong)
val queryTimeRange = "SELECT * FROM user1234.datafile WHERE event_time >= " + dtRangeStart
val dataFrame = sparkSession.sql(queryTimeRange)
import sparkSession.implicits._
val dataSet: Dataset[RawDataModel] = dataFrame.as[RawDataModel]
dataSet.show(1)
dtRangeEnd = System.currentTimeMillis()
dtRangeStart = (dtRangeEnd - (15 60 1000).toLong)
val dtRangeData = dataSet.filter(dataSet("event_time").between(dtRangeStart, dtRangeEnd))
dtRangeData.show(1)
spark合并sparkSession.sql(queryTimeRange)和dataSet.filter(dataSet("event_time").between(dtRangeStart, dtRangeEnd))到CQL指令中,像这样:
SELECT“sensorid”,“event_time”,“value”FROM“company_5a819ee2522e572c8a16a43a”。“data”WHERE token(“sensorid”)>?AND令牌(“sensorid”)<=?和“event_time”> =?和“event_time”> =?AND“event_time”<=?
在那里你在同一个领域得到两个相同的限制"event_time" >= ?。
如果你坚持filter之前执行dataFrame. Spark将与.filter分开计算dataFrame:
val dataFrame = sparkSession.sql(queryTimeRange)
dataFrame.persist
dataSet.filter(dataSet("event_time").between(dtRangeStart, dtRangeEnd))
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。