You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by vo...@apache.org on 2015/12/16 13:26:05 UTC

[02/16] ignite git commit: IGNITE-2155 Fixed ScalarSnowflakeSchemaExample.

IGNITE-2155 Fixed ScalarSnowflakeSchemaExample.


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

Branch: refs/heads/ignite-2100
Commit: 894992d6846f8290362e43816524902a57955ee2
Parents: ed5f279
Author: AKuznetsov <ak...@gridgain.com>
Authored: Tue Dec 15 23:59:30 2015 +0700
Committer: AKuznetsov <ak...@gridgain.com>
Committed: Tue Dec 15 23:59:30 2015 +0700

----------------------------------------------------------------------
 .../examples/ScalarSnowflakeSchemaExample.scala | 31 ++++++++++++--------
 .../scala/org/apache/ignite/scalar/scalar.scala | 11 ++++++-
 2 files changed, 29 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/894992d6/examples/src/main/scala/org/apache/ignite/scalar/examples/ScalarSnowflakeSchemaExample.scala
----------------------------------------------------------------------
diff --git a/examples/src/main/scala/org/apache/ignite/scalar/examples/ScalarSnowflakeSchemaExample.scala b/examples/src/main/scala/org/apache/ignite/scalar/examples/ScalarSnowflakeSchemaExample.scala
index 33b2fcc..eb8a538 100644
--- a/examples/src/main/scala/org/apache/ignite/scalar/examples/ScalarSnowflakeSchemaExample.scala
+++ b/examples/src/main/scala/org/apache/ignite/scalar/examples/ScalarSnowflakeSchemaExample.scala
@@ -52,14 +52,14 @@ object ScalarSnowflakeSchemaExample {
     /** Configuration file name. */
     private val CONFIG = "examples/config/example-ignite.xml"
 
-    /** Name of replicated cache specified in spring configuration. */
-    private val REPL_NAME = "ScalarSnowflakeSchemaExampleReplicated"
-
     /** Name of partitioned cache specified in spring configuration. */
-    private val PART_NAME = "ScalarSnowflakeSchemaExamplePartitioned"
+    private val PARTITIONED_CACHE_NAME = "ScalarSnowflakeSchemaExamplePartitioned"
+
+    /** Name of replicated cache specified in spring configuration. */
+    private val REPLICATED_CACHE_NAME = "ScalarSnowflakeSchemaExampleReplicated"
 
     /** ID generator. */
-    private[this] val idGen = Stream.from(System.currentTimeMillis.toInt).iterator
+    private[this] val idGen = Stream.from(0).iterator
 
     /** DimStore data. */
     private[this] val dataStore = scala.collection.mutable.Map[JavaInt, DimStore]()
@@ -72,11 +72,18 @@ object ScalarSnowflakeSchemaExample {
      */
     def main(args: Array[String]) {
         scalar(CONFIG) {
-            val dimCache = createCache$[JavaInt, AnyRef](REPL_NAME, CacheMode.REPLICATED, Seq(classOf[JavaInt], classOf[DimStore],
+            println
+            println(">>> Cache star schema example started.")
+
+            // Destroy caches to clean up the data if any left from previous runs.
+            destroyCache$(PARTITIONED_CACHE_NAME)
+            destroyCache$(REPLICATED_CACHE_NAME)
+
+            val dimCache = createCache$[JavaInt, AnyRef](REPLICATED_CACHE_NAME, CacheMode.REPLICATED, Seq(classOf[JavaInt], classOf[DimStore],
                 classOf[JavaInt], classOf[DimProduct]))
 
             try {
-                val factCache = createCache$[JavaInt, FactPurchase](PART_NAME, indexedTypes = Seq(classOf[JavaInt], classOf[FactPurchase]))
+                val factCache = createCache$[JavaInt, FactPurchase](PARTITIONED_CACHE_NAME, indexedTypes = Seq(classOf[JavaInt], classOf[FactPurchase]))
 
                 try {
                     populateDimensions(dimCache)
@@ -138,10 +145,10 @@ object ScalarSnowflakeSchemaExample {
      * `FactPurchase` objects stored in `partitioned` cache.
      */
     def queryStorePurchases() {
-        val factCache = ignite$.cache[JavaInt, FactPurchase](PART_NAME)
+        val factCache = ignite$.cache[JavaInt, FactPurchase](PARTITIONED_CACHE_NAME)
 
         val storePurchases = factCache.sql(
-            "from \"" + REPL_NAME + "\".DimStore, \"" + PART_NAME + "\".FactPurchase " +
+            "from \"" + REPLICATED_CACHE_NAME + "\".DimStore, \"" + PARTITIONED_CACHE_NAME + "\".FactPurchase " +
             "where DimStore.id=FactPurchase.storeId and DimStore.name=?", "Store1")
 
         printQueryResults("All purchases made at store1:", storePurchases.getAll)
@@ -154,7 +161,7 @@ object ScalarSnowflakeSchemaExample {
      * stored in `partitioned` cache.
      */
     private def queryProductPurchases() {
-        val factCache = ignite$.cache[JavaInt, FactPurchase](PART_NAME)
+        val factCache = ignite$.cache[JavaInt, FactPurchase](PARTITIONED_CACHE_NAME)
 
         // All purchases for certain product made at store2.
         // =================================================
@@ -165,8 +172,8 @@ object ScalarSnowflakeSchemaExample {
         println("IDs of products [p1=" + p1.id + ", p2=" + p2.id + ", p3=" + p3.id + ']')
 
         val prodPurchases = factCache.sql(
-            "from \"" + REPL_NAME + "\".DimStore, \"" + REPL_NAME + "\".DimProduct, \"" +
-                PART_NAME + "\".FactPurchase " +
+            "from \"" + REPLICATED_CACHE_NAME + "\".DimStore, \"" + REPLICATED_CACHE_NAME + "\".DimProduct, \"" +
+                PARTITIONED_CACHE_NAME + "\".FactPurchase " +
             "where DimStore.id=FactPurchase.storeId and " +
                 "DimProduct.id=FactPurchase.productId and " +
                 "DimStore.name=? and DimProduct.id in(?, ?, ?)",

http://git-wip-us.apache.org/repos/asf/ignite/blob/894992d6/modules/scalar/src/main/scala/org/apache/ignite/scalar/scalar.scala
----------------------------------------------------------------------
diff --git a/modules/scalar/src/main/scala/org/apache/ignite/scalar/scalar.scala b/modules/scalar/src/main/scala/org/apache/ignite/scalar/scalar.scala
index c5bc085..998ec28 100644
--- a/modules/scalar/src/main/scala/org/apache/ignite/scalar/scalar.scala
+++ b/modules/scalar/src/main/scala/org/apache/ignite/scalar/scalar.scala
@@ -275,7 +275,7 @@ object scalar extends ScalarConversions {
         Option(Ignition.ignite.cache(cacheName))
 
     /**
-     * Creates cache cache with specified parameters in default grid.
+     * Creates cache with specified parameters in default grid.
      *
      * @param cacheName Name of the cache to get.
      */
@@ -291,6 +291,15 @@ object scalar extends ScalarConversions {
     }
 
     /**
+      * Destroy cache with specified name.
+      *
+      * @param cacheName Name of the cache to destroy.
+      */
+    @inline def destroyCache$(@Nullable cacheName: String) = {
+        Ignition.ignite.destroyCache(cacheName)
+    }
+
+    /**
      * Gets named cache from specified grid.
      *
      * @param gridName Name of the grid.