-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Changes from 1 commit
36d6c70
7cbfcde
77e7fb3
b4247e1
965ca92
930adf0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,6 +43,24 @@ | |
<version>${project.version}</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.apache.spark</groupId> | ||
<artifactId>spark-core_2.11</artifactId> | ||
<version>${spark.version}</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.apache.spark</groupId> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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> | ||
|
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 { | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||
|
||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 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") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would also demonstrate:
|
||
|
||
sparkContext.stop() | ||
} |
There was a problem hiding this comment.
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.