Skip to content

Commit 6ad4d1c

Browse files
committed
Fix it:test when no SparkContext is set
1 parent e2a88e8 commit 6ad4d1c

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

connector/src/it/scala/com/datastax/spark/connector/datasource/CassandraCatalogTableReadSpec.scala

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,17 +78,17 @@ class CassandraCatalogTableReadSpec extends CassandraCatalogSpecBase {
7878
it should "handle count pushdowns" in {
7979
setupBasicTable()
8080
val request = spark.sql(s"""SELECT COUNT(*) from $defaultKs.$testTable""")
81-
val reader = request
81+
var factory = request
8282
.queryExecution
8383
.executedPlan
8484
.collectFirst {
85-
case batchScanExec: BatchScanExec=> batchScanExec.readerFactory.createReader(EmptyInputPartition)
86-
case adaptiveSparkPlanExec: AdaptiveSparkPlanExec => adaptiveSparkPlanExec.executedPlan.collectLeaves().collectFirst{
87-
case batchScanExec: BatchScanExec=> batchScanExec.readerFactory.createReader(EmptyInputPartition)
88-
}.get
85+
case batchScanExec: BatchScanExec=> batchScanExec.readerFactory
86+
case adaptiveSparkPlanExec: AdaptiveSparkPlanExec => adaptiveSparkPlanExec.executedPlan.collectLeaves().collectFirst{
87+
case batchScanExec: BatchScanExec=> batchScanExec.readerFactory
88+
}.get
8989
}
9090

91-
reader.get.isInstanceOf[CassandraCountPartitionReader] should be (true)
91+
factory.get.asInstanceOf[CassandraScanPartitionReaderFactory].isCountQuery should be (true)
9292
request.collect()(0).get(0) should be (101)
9393
}
9494

connector/src/main/scala/com/datastax/spark/connector/datasource/CassandraScanPartitionReaderFactory.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,12 @@ case class CassandraScanPartitionReaderFactory(
4040
readConf: ReadConf,
4141
queryParts: CqlQueryParts) extends PartitionReaderFactory {
4242

43+
def isCountQuery: Boolean = queryParts.selectedColumnRefs.contains(RowCountRef)
44+
4345
override def createReader(partition: InputPartition): PartitionReader[InternalRow] = {
4446

4547
val cassandraPartition = partition.asInstanceOf[CassandraPartition[Any, _ <: Token[Any]]]
46-
if (queryParts.selectedColumnRefs.contains(RowCountRef)) {
48+
if (isCountQuery) {
4749
//Count Pushdown
4850
CassandraCountPartitionReader(
4951
connector,

0 commit comments

Comments
 (0)