Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IGNITE-4526 added SharedRDD example #1403

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions examples/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,24 @@
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>org.apache.spark</groupId>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All spark 2.11 dependencies have to be placed under "scala" profile below in the xml while spark 2.10 dependencies under scala-2.10 profile.

<artifactId>spark-core_2.11</artifactId>
<version>${spark.version}</version>
</dependency>

<dependency>
<groupId>org.apache.spark</groupId>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above.

<artifactId>spark-sql_2.11</artifactId>
<version>${spark.version}</version>
</dependency>

<dependency>
<groupId>org.apache.ignite</groupId>
<artifactId>ignite-spark</artifactId>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This module belongs to "scala" profile while for "scala-2.10" we need to add ignite-spark-2.10 instead.

<version>${project.version}</version>
</dependency>

<dependency>
<groupId>org.apache.ignite</groupId>
<artifactId>ignite-spring</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.ignite.scalar.examples.spark

import org.apache.ignite.configuration.IgniteConfiguration
import org.apache.ignite.spark.{IgniteContext, IgniteRDD}
import org.apache.spark.{SparkConf, SparkContext}


/**
* This example demonstrates the simplest code that creates the IgnitedRDD and
* shares it with multiple spark workers. The goal of this particular
* example is to provide the simplest code example of this logic.
* <p/>
* Remote nodes should always be started with special configuration file which
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think that we need to mention remote nodes here since the example starts embedded Ignite nodes for every spark worker. So, I would remove the remote nodes related paragraphs from the doc and elaborate more on Ignite "standalone" flag that is set to "false" for the purpose of this example.

* enables P2P class loading: `'ignite.{sh|bat} examples/config/example-ignite.xml'`.
* <p/>
* Alternatively you can run `ExampleNodeStartup` in another JVM which will
* start node with `examples/config/example-ignite.xml` configuration.
*/
object ScalarSharedRDDExample extends App {

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No space here.

/** Spark Configuration */
private val conf = new SparkConf()
.setAppName("IgniteRDDExample")
.setMaster("local")
.set("spark.executor.instances","2")

/** Spark context */
implicit val sparkContext = new SparkContext(conf)


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove on extra line.

/** Creates Ignite context with default configuration */
val igniteContext = new IgniteContext(sparkContext, () => new IgniteConfiguration(),false)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's define a configuration for the cache (shared RDD explicitly) showing that this is feasible. We can modify some cache parameter like cache name or atomicity mode and setup indexes for SQL queries.

As for the indexes, take a look here
https://apacheignite.readme.io/docs/indexes#queryentity-based-configuration

In your scenario both "keyType" and "valueType" will refer to Integer.


/** Creates an Ignite RDD of Type (Int,Int) Integer Pair */
val sharedRDD: IgniteRDD[Int, Int] = igniteContext.fromCache("partitioned")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's rename "partitioned" to "sharedRdd".


/** Fill IgniteRDD with data */
sharedRDD.saveValues(sparkContext.parallelize(1 to 100000, 10))

/** Transforming Pairs to contain their Squared value */
sharedRDD.mapValues(x => (x * x))

/** Retrieve RDD back from the Cache */
val transformedValues = igniteContext.fromCache("partitioned")

transformedValues.take(5).foreach(println)

igniteContext.close(true)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would also demonstrate:

  • some Spark native transformations
  • Ignite SQL queries


sparkContext.stop()
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package org.apache.ignite.scalar.tests.examples

import org.apache.ignite.scalar.examples._
import org.apache.ignite.scalar.examples.spark._
import org.apache.ignite.scalar.scalar
import org.apache.ignite.testframework.junits.common.GridAbstractExamplesTest
import org.scalatest.junit.JUnitSuiteLike
Expand Down Expand Up @@ -95,4 +96,9 @@ class ScalarExamplesSelfTest extends GridAbstractExamplesTest with JUnitSuiteLik
def testScalarSnowflakeSchemaExample() {
ScalarSnowflakeSchemaExample.main(EMPTY_ARGS)
}

/** */
def testScalarSharedRDDExample() {
ScalarSharedRDDExample.main(EMPTY_ARGS)
}
}