ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dma...@apache.org
Subject [15/17] ignite git commit: IGNITE-2538 - IgniteRDD count() and isEmpty() method use IgniteCache API
Date Fri, 27 May 2016 11:30:54 GMT
IGNITE-2538 - IgniteRDD count() and isEmpty() method use IgniteCache API


Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/6fcc7a41
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/6fcc7a41
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/6fcc7a41

Branch: refs/heads/master
Commit: 6fcc7a41d8676956983792717483318b85781479
Parents: e2db87b
Author: MaBiao <mabiaocas@gmail.com>
Authored: Wed May 25 12:54:40 2016 +0300
Committer: Valentin Kulichenko <valentin.lulichenko@gmail.com>
Committed: Wed May 25 12:56:38 2016 +0300

----------------------------------------------------------------------
 .../org/apache/ignite/spark/IgniteRDD.scala     | 20 +++++++++++++++
 .../org/apache/ignite/spark/IgniteRDDSpec.scala | 27 ++++++++++++++++++++
 2 files changed, 47 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/6fcc7a41/modules/spark/src/main/scala/org/apache/ignite/spark/IgniteRDD.scala
----------------------------------------------------------------------
diff --git a/modules/spark/src/main/scala/org/apache/ignite/spark/IgniteRDD.scala b/modules/spark/src/main/scala/org/apache/ignite/spark/IgniteRDD.scala
index 9112040..0d8e730 100644
--- a/modules/spark/src/main/scala/org/apache/ignite/spark/IgniteRDD.scala
+++ b/modules/spark/src/main/scala/org/apache/ignite/spark/IgniteRDD.scala
@@ -95,6 +95,26 @@ class IgniteRDD[K, V] (
     }
 
     /**
+     * Tells whether this IgniteRDD is empty or not.
+     *
+     * @return Whether this IgniteRDD is empty or not.
+     */
+    override def isEmpty(): Boolean = {
+        count() == 0
+    }
+
+    /**
+     * Gets number of tuples in this IgniteRDD.
+     *
+     * @return Number of tuples in this IgniteRDD.
+     */
+    override def count(): Long = {
+        val cache = ensureCache()
+
+        cache.size()
+    }
+
+    /**
      * Runs an object SQL on corresponding Ignite cache.
      *
      * @param typeName Type name to run SQL against.

http://git-wip-us.apache.org/repos/asf/ignite/blob/6fcc7a41/modules/spark/src/test/scala/org/apache/ignite/spark/IgniteRDDSpec.scala
----------------------------------------------------------------------
diff --git a/modules/spark/src/test/scala/org/apache/ignite/spark/IgniteRDDSpec.scala b/modules/spark/src/test/scala/org/apache/ignite/spark/IgniteRDDSpec.scala
index a25eaac..8e36275 100644
--- a/modules/spark/src/test/scala/org/apache/ignite/spark/IgniteRDDSpec.scala
+++ b/modules/spark/src/test/scala/org/apache/ignite/spark/IgniteRDDSpec.scala
@@ -192,6 +192,33 @@ class IgniteRDDSpec extends FunSpec with Matchers with BeforeAndAfterAll
with Be
                 sc.stop()
             }
         }
+
+        it("should properly count RDD size") {
+            val sc = new SparkContext("local[*]", "test")
+
+            try {
+                val ic = new IgniteContext[Integer, WithObjectField](sc,
+                    () ⇒ configuration("client", client = true))
+
+                val cache: IgniteRDD[Integer, WithObjectField] = ic.fromCache(PARTITIONED_CACHE_NAME)
+
+                assert(cache.count() == 0)
+                assert(cache.isEmpty())
+
+                cache.savePairs(sc.parallelize(0 until 1000, 2).map(i ⇒ (i:java.lang.Integer,
new WithObjectField(i, new Entity(i, "", i)))))
+
+                assert(cache.count() == 1000)
+                assert(!cache.isEmpty())
+
+                cache.clear()
+
+                assert(cache.count() == 0)
+                assert(cache.isEmpty())
+            }
+            finally {
+                sc.stop()
+            }
+        }
     }
 
     override protected def beforeEach() = {


Mime
View raw message