@@ -24,6 +24,7 @@ import org.apache.spark.sql.types._
2424import org .apache .spark .sql .{Row , SaveMode }
2525
2626import java .sql .DriverManager
27+ import java .time .{LocalDate , ZoneId }
2728import java .util .Date
2829import scala .collection .mutable
2930import scala .collection .mutable .ListBuffer
@@ -243,30 +244,6 @@ class PhoenixSparkDatasourceV1IT extends AbstractPhoenixSparkIT {
243244 count shouldEqual 1L
244245 }
245246
246- test(" Can use extraOptions to set configs for workers during reads" ) {
247- // Pass in true, so we will get null when fetching the current row, leading to an NPE
248- var extraOptions = PhoenixTestingInputPartitionReader .RETURN_NULL_CURR_ROW + " =true"
249- var rdd = spark.sqlContext.read
250- .format(PhoenixTestingDataSource .TEST_SOURCE )
251- .options( Map (" table" -> " TABLE1" , PhoenixDataSource .ZOOKEEPER_URL -> quorumAddress,
252- PhoenixDataSource .PHOENIX_CONFIGS -> extraOptions)).load
253-
254- // Expect to get a NullPointerException in the executors
255- var error = intercept[SparkException ] {
256- rdd.take(2 )(0 )(1 )
257- }
258- assert(error.getCause.isInstanceOf [NullPointerException ])
259-
260- // Pass in false, so we will get the expected rows
261- extraOptions = PhoenixTestingInputPartitionReader .RETURN_NULL_CURR_ROW + " =false"
262- rdd = spark.sqlContext.read
263- .format(PhoenixTestingDataSource .TEST_SOURCE )
264- .options( Map (" table" -> " TABLE1" , PhoenixDataSource .ZOOKEEPER_URL -> quorumAddress,
265- PhoenixDataSource .PHOENIX_CONFIGS -> extraOptions)).load
266- val stringValue = rdd.take(2 )(0 )(1 )
267- stringValue shouldEqual " test_row_1"
268- }
269-
270247 test(" Can save to phoenix table from Spark without specifying all the columns" ) {
271248 val dataSet = List (Row (1L , " 1" , 1 ), Row (2L , " 2" , 2 ), Row (3L , " 3" , 3 ))
272249
@@ -300,47 +277,6 @@ class PhoenixSparkDatasourceV1IT extends AbstractPhoenixSparkIT {
300277 }
301278 }
302279
303- test(" Can use extraOptions to set configs for workers during writes" ) {
304- val totalRecords = 100
305- val upsertBatchSize = 5
306-
307- val records = new mutable.MutableList [Row ]
308- for (x <- 1 to totalRecords) {
309- records += Row (x.toLong, x.toString, x)
310- }
311- val dataSet = records.toList
312-
313- val schema = StructType (
314- Seq (StructField (" ID" , LongType , nullable = false ),
315- StructField (" COL1" , StringType ),
316- StructField (" COL2" , IntegerType )))
317-
318- // Distribute the dataset into an RDD with just 1 partition so we use only 1 executor.
319- // This makes it easy to deterministically count the batched commits from that executor
320- // since it corresponds to exactly 1 input partition. In case of multiple executors with
321- // an uneven distribution of input partitions, if
322- // (number of records in that partition) % batchSize != 0, some updates would also be committed
323- // via PhoenixDataWriter#commit rather than the batch commits via PhoenixDataWriter#write
324- // and those would thus, not be counted by PhoenixTestingDataWriter.
325- val rowRDD = spark.sparkContext.parallelize(dataSet, 1 )
326-
327- // Apply the schema to the RDD.
328- val df = spark.sqlContext.createDataFrame(rowRDD, schema)
329- val extraOptions = PhoenixConfigurationUtil .UPSERT_BATCH_SIZE + " =" + upsertBatchSize.toString
330-
331- // Initially, this should be zero
332- PhoenixTestingDataSourceWriter .TOTAL_BATCHES_COMMITTED_COUNT shouldEqual 0
333- df.write
334- .format(PhoenixTestingDataSource .TEST_SOURCE )
335- .options(Map (" table" -> " OUTPUT_TEST_TABLE" , PhoenixDataSource .ZOOKEEPER_URL -> quorumAddress,
336- PhoenixDataSource .PHOENIX_CONFIGS -> extraOptions))
337- .mode(SaveMode .Overwrite )
338- .save()
339-
340- // Verify the number of times batched updates are committed via DataWriters
341- PhoenixTestingDataSourceWriter .TOTAL_BATCHES_COMMITTED_COUNT shouldEqual totalRecords/ upsertBatchSize
342- }
343-
344280 test(" Can save dates to Phoenix using java.sql.Date" ) {
345281 val date = java.sql.Date .valueOf(" 2016-09-30" )
346282
@@ -703,14 +639,14 @@ class PhoenixSparkDatasourceV1IT extends AbstractPhoenixSparkIT {
703639 .options(Map (" table" -> " DATE_TEST" , PhoenixDataSource .ZOOKEEPER_URL -> quorumAddress))
704640 .load
705641 val dt = df.select(" COL1" ).first().getDate(0 ).getTime
706- val epoch = new Date ().getTime
642+ val expected = LocalDate .of( 2021 , 1 , 1 ).atStartOfDay( ZoneId .systemDefault()).toInstant.toEpochMilli
707643
708644 // NOTE: Spark DateType drops hour, minute, second, as per the java.sql.Date spec
709645 // Use 'dateAsTimestamp' option to coerce DATE to TIMESTAMP without losing resolution
710646
711647 // Note that Spark also applies the timezone offset to the returned date epoch. Rather than perform timezone
712648 // gymnastics, just make sure we're within 24H of the epoch generated just now
713- assert(Math .abs(epoch - dt) < 86400000 )
649+ assert(expected == dt)
714650
715651 df.createOrReplaceTempView(" DATE_TEST" )
716652 val df2 = spark.sql(" SELECT * FROM DATE_TEST WHERE COL1 > TO_DATE('1990-01-01 00:00:01', 'yyyy-MM-dd HH:mm:ss')" )
@@ -773,9 +709,9 @@ class PhoenixSparkDatasourceV1IT extends AbstractPhoenixSparkIT {
773709 .load
774710 val dtRes = df.select(" COL1" ).first()
775711 val ts = dtRes.getTimestamp(0 ).getTime
776- val epoch = new Date ().getTime
712+ val expected = LocalDate .of( 2021 , 1 , 1 ).atStartOfDay( ZoneId .systemDefault()).toInstant.toEpochMilli
777713
778- assert(Math .abs(epoch - ts) < 300000 )
714+ assert(expected == ts)
779715 }
780716
781717 test(" Can load Phoenix Time columns through DataFrame API" ) {
@@ -784,8 +720,9 @@ class PhoenixSparkDatasourceV1IT extends AbstractPhoenixSparkIT {
784720 .options(Map (" table" -> " TIME_TEST" , PhoenixDataSource .ZOOKEEPER_URL -> quorumAddress))
785721 .load
786722 val time = df.select(" COL1" ).first().getTimestamp(0 ).getTime
787- val epoch = new Date ().getTime
788- assert(Math .abs(epoch - time) < 86400000 )
723+ val expected = LocalDate .of(2021 , 1 , 1 ).atStartOfDay(ZoneId .systemDefault()).toInstant.toEpochMilli
724+
725+ assert(expected == time)
789726 }
790727
791728 test(" can read all Phoenix data types" ) {
0 commit comments