@@ -18,21 +18,22 @@ package org.apache.spark.sql
1818
1919
2020import com .pivotal .gemfirexd .internal .engine .Misc
21- import io .snappydata .Property
2221import io .snappydata .cluster .ClusterManagerTestBase
2322import io .snappydata .test .dunit .{AvailablePortHelper , SerializableCallable }
2423import io .snappydata .util .TestUtils
24+ import io .snappydata .{Property , SnappyFunSuite }
2525import org .scalatest .Assertions
2626
2727import org .apache .spark .internal .Logging
2828import org .apache .spark .scheduler .{SparkListener , SparkListenerTaskEnd , SparkListenerTaskStart }
29+ import org .apache .spark .sql .execution .ui .SQLExecutionUIData
2930
3031case class TestRecord (col1 : Int , col2 : Int , col3 : Int )
3132
3233class ColumnBatchAndExternalTableDUnitTest (s : String ) extends ClusterManagerTestBase (s)
3334 with Assertions with Logging with SparkSupport {
3435
35- private def activeExecutionIds (session : SparkSession ): Set [Long ] = {
36+ private def sqlExecutionIds (session : SparkSession ): Set [Long ] = {
3637 session.sharedState.statusStore.executionsList().map(_.executionId).toSet
3738 }
3839
@@ -53,144 +54,148 @@ class ColumnBatchAndExternalTableDUnitTest(s: String) extends ClusterManagerTest
5354
5455 import session .implicits ._
5556
56- val ds = session.createDataset(sc.range(1 , 101 ).map(i =>
57+ val ds = session.createDataset(sc.range(1 , 1001 ).map(i =>
5758 AirlineData (2015 , 2 , 15 , 1002 , i.toInt, " AA" + i)))
5859 ds.write.insertInto(" airline" )
5960
6061 // ***Check for the case when all the column batches are scanned ****
61- var previousExecutionIds = activeExecutionIds (session)
62+ var previousExecutionIds = sqlExecutionIds (session)
6263
6364 val df_allColumnBatchesScan = session.sql(
6465 " select AVG(ArrDelay) arrivalDelay, UniqueCarrier carrier " +
65- " from AIRLINE where ArrDelay < 101 " +
66+ " from AIRLINE where ArrDelay < 1001 " +
6667 " group by UniqueCarrier order by arrivalDelay" )
6768
68- df_allColumnBatchesScan.count ()
69+ df_allColumnBatchesScan.collect ()
6970
70- var executionIds = activeExecutionIds (session).diff(previousExecutionIds)
71+ var executionIds = sqlExecutionIds (session).diff(previousExecutionIds)
7172
7273 var executionId = executionIds.head
7374
74- val (scanned1, skipped1) =
75- findColumnBatchStats(df_allColumnBatchesScan, session, executionId)
75+ val (scanned1, skipped1) = findColumnBatchStats(session, executionId)
7676 assert(skipped1 == 0 , " All Column batches should have been scanned" )
7777 assert(scanned1 > 0 , " All Column batches should have been scanned" )
7878
7979 // ***Check for the case when all the column batches are skipped****
80- previousExecutionIds = activeExecutionIds (session)
80+ previousExecutionIds = sqlExecutionIds (session)
8181
8282 val df_noColumnBatchesScan = session.sql(
8383 " select AVG(ArrDelay) arrivalDelay, UniqueCarrier carrier " +
84- " from AIRLINE where ArrDelay > 101 " +
84+ " from AIRLINE where ArrDelay > 1001 " +
8585 " group by UniqueCarrier order by arrivalDelay" )
8686
87- df_noColumnBatchesScan.count ()
87+ df_noColumnBatchesScan.collect ()
8888
89- executionIds = activeExecutionIds (session).diff(previousExecutionIds)
89+ executionIds = sqlExecutionIds (session).diff(previousExecutionIds)
9090
9191 executionId = executionIds.head
9292
93- val (scanned2, skipped2) =
94- findColumnBatchStats(df_allColumnBatchesScan, session, executionId)
93+ val (scanned2, skipped2) = findColumnBatchStats(session, executionId)
9594 assert(scanned2 == skipped2, " No Column batches should have been scanned" )
9695 assert(skipped2 > 0 , " No Column batches should have been scanned" )
9796
9897 // ***Check for the case when some of the column batches are scanned ****
99- previousExecutionIds = activeExecutionIds (session)
98+ previousExecutionIds = sqlExecutionIds (session)
10099
101100 val df_someColumnBatchesScan = session.sql(
102101 " select AVG(ArrDelay) arrivalDelay, UniqueCarrier carrier " +
103102 " from AIRLINE where ArrDelay < 20 " +
104103 " group by UniqueCarrier order by arrivalDelay" )
105104
106- df_someColumnBatchesScan.count ()
105+ df_someColumnBatchesScan.collect ()
107106
108- executionIds = activeExecutionIds (session).diff(previousExecutionIds)
107+ executionIds = sqlExecutionIds (session).diff(previousExecutionIds)
109108
110109 executionId = executionIds.head
111110
112- val (scanned3, skipped3) =
113- findColumnBatchStats(df_allColumnBatchesScan, session, executionId)
111+ val (scanned3, skipped3) = findColumnBatchStats(session, executionId)
114112
115113 assert(skipped3 > 0 , " Some Column batches should have been skipped" )
116114 assert(scanned3 != skipped3, " Some Column batches should have been skipped - comparison" )
117115
118116 // check for StartsWith predicate with MAX/MIN handling
119117
120118 // first all batches chosen
121- previousExecutionIds = activeExecutionIds (session)
119+ previousExecutionIds = sqlExecutionIds (session)
122120
123121 val df_allColumnBatchesLikeScan = session.sql(
124122 " select AVG(ArrDelay) arrivalDelay, UniqueCarrier carrier " +
125123 " from AIRLINE where UniqueCarrier like 'AA%' " +
126124 " group by UniqueCarrier order by arrivalDelay" )
127125
128- var count = df_allColumnBatchesLikeScan.count()
129- assert(count == 100 , s " Unexpected count = $count, expected 100 " )
126+ var count = df_allColumnBatchesLikeScan.collect().length
127+ assert(count == 1000 , s " Unexpected count = $count, expected 1000 " )
130128
131- executionIds = activeExecutionIds (session).diff(previousExecutionIds)
129+ executionIds = sqlExecutionIds (session).diff(previousExecutionIds)
132130
133131 executionId = executionIds.head
134132
135- val (scanned4, skipped4) =
136- findColumnBatchStats(df_allColumnBatchesLikeScan, session, executionId)
133+ val (scanned4, skipped4) = findColumnBatchStats(session, executionId)
137134
138135 assert(skipped4 == 0 , " No Column batches should have been skipped" )
139136 assert(scanned4 > 0 , " All Column batches should have been scanned" )
140137
141138 // next some batches skipped
142- previousExecutionIds = activeExecutionIds (session)
139+ previousExecutionIds = sqlExecutionIds (session)
143140
144141 val df_someColumnBatchesLikeScan = session.sql(
145142 " select AVG(ArrDelay) arrivalDelay, UniqueCarrier carrier " +
146143 " from AIRLINE where UniqueCarrier like 'AA1%' " +
147144 " group by UniqueCarrier order by arrivalDelay" )
148145
149- count = df_someColumnBatchesLikeScan.count()
150- assert(count == 12 , s " Unexpected count = $count, expected 12 " )
146+ count = df_someColumnBatchesLikeScan.collect().length
147+ assert(count == 112 , s " Unexpected count = $count, expected 112 " )
151148
152- executionIds = activeExecutionIds (session).diff(previousExecutionIds)
149+ executionIds = sqlExecutionIds (session).diff(previousExecutionIds)
153150
154151 executionId = executionIds.head
155152
156- val (scanned5, skipped5) =
157- findColumnBatchStats(df_someColumnBatchesLikeScan, session, executionId)
153+ val (scanned5, skipped5) = findColumnBatchStats(session, executionId)
158154
159155 assert(skipped5 > 0 , " Some Column batches should have been skipped" )
160156 assert(scanned5 != skipped5, " Some Column batches should have been skipped - comparison" )
161157
162158 // last all batches skipped
163- previousExecutionIds = activeExecutionIds (session)
159+ previousExecutionIds = sqlExecutionIds (session)
164160
165161 val df_noColumnBatchesLikeScan = session.sql(
166162 " select AVG(ArrDelay) arrivalDelay, UniqueCarrier carrier " +
167163 " from AIRLINE where UniqueCarrier like 'AA0%' " +
168164 " group by UniqueCarrier order by arrivalDelay" )
169165
170- count = df_noColumnBatchesLikeScan.count()
166+ count = df_noColumnBatchesLikeScan.collect().length
171167 assert(count == 0 , s " Unexpected count = $count, expected 0 " )
172168
173- executionIds = activeExecutionIds (session).diff(previousExecutionIds)
169+ executionIds = sqlExecutionIds (session).diff(previousExecutionIds)
174170
175171 executionId = executionIds.head
176172
177- val (scanned6, skipped6) =
178- findColumnBatchStats(df_noColumnBatchesLikeScan, session, executionId)
173+ val (scanned6, skipped6) = findColumnBatchStats(session, executionId)
179174
180175 assert(scanned6 == skipped6, " No Column batches should have been returned" )
181176 assert(skipped6 > 0 , " No Column batches should have been returned" )
182177 }
183178
184- private def findColumnBatchStats (df : DataFrame ,
185- session : SnappySession , executionId : Long ): (Long , Long ) = {
179+ private def getAccumulatorValue (execData : SQLExecutionUIData , name : String ): Long = {
180+ execData.metrics.find(_.name == name) match {
181+ case Some (id) => execData.metricValues.get(id.accumulatorId) match {
182+ case Some (v) => v.toLong
183+ case _ => 0L
184+ }
185+ case _ => 0L
186+ }
187+ }
186188
187- val execData = session.sharedState.statusStore.executionsList().find(
188- _.executionId == executionId).get
189- val seenId = execData.metrics.find(_.name == " column batches seen" ).get
190- val skippedId = execData.metrics.find(_.name == " column batches skipped by the predicate" ).get
189+ private def findColumnBatchStats (session : SnappySession , executionId : Long ): (Long , Long ) = {
190+ var execData : SQLExecutionUIData = null
191+ SnappyFunSuite .waitForCriterion({
192+ execData = session.sharedState.statusStore.executionsList().find(
193+ _.executionId == executionId).get
194+ execData.metricValues ne null
195+ }, s " waiting for metricValues of executionId = $executionId" , 10000 , 10 )
191196
192- (execData.metricValues.filter(_._1 == seenId).head._2.toInt ,
193- execData.metricValues.filter(_._1 == skippedId).head._2.toInt )
197+ (getAccumulatorValue(execData, " column batches seen " ) ,
198+ getAccumulatorValue(execData, " column batches skipped by the predicate " ) )
194199 }
195200
196201 def testCreateColumnTablesFromOtherTables (): Unit = {
0 commit comments