Search in sources :

Example 11 with SparkContext

use of org.apache.spark.SparkContext in project Gaffer by gchq.

the class GetDataFrameOfElementsExample method runExamples.

@Override
public void runExamples() {
    // Need to actively turn logging on and off as needed as Spark produces some logs
    // even when the log level is set to off.
    ROOT_LOGGER.setLevel(Level.OFF);
    final SparkConf sparkConf = new SparkConf().setMaster("local").setAppName("getDataFrameOfElementsWithEntityGroup").set("spark.serializer", "org.apache.spark.serializer.KryoSerializer").set("spark.kryo.registrator", "uk.gov.gchq.gaffer.spark.serialisation.kryo.Registrator").set("spark.driver.allowMultipleContexts", "true");
    final SparkContext sc = new SparkContext(sparkConf);
    sc.setLogLevel("OFF");
    final SQLContext sqlc = new SQLContext(sc);
    final Graph graph = getGraph();
    try {
        getDataFrameOfElementsWithEntityGroup(sqlc, graph);
        getDataFrameOfElementsWithEdgeGroup(sqlc, graph);
    } catch (final OperationException e) {
        throw new RuntimeException(e);
    }
    sc.stop();
    ROOT_LOGGER.setLevel(Level.INFO);
}
Also used : SparkContext(org.apache.spark.SparkContext) Graph(uk.gov.gchq.gaffer.graph.Graph) SparkConf(org.apache.spark.SparkConf) SQLContext(org.apache.spark.sql.SQLContext) OperationException(uk.gov.gchq.gaffer.operation.OperationException)

Example 12 with SparkContext

use of org.apache.spark.SparkContext in project geode by apache.

the class JavaAPITest method createCommonMocks.

@SuppressWarnings("unchecked")
public Tuple3<SparkContext, GeodeConnectionConf, GeodeConnection> createCommonMocks() {
    SparkContext mockSparkContext = mock(SparkContext.class);
    GeodeConnectionConf mockConnConf = mock(GeodeConnectionConf.class);
    GeodeConnection mockConnection = mock(GeodeConnection.class);
    when(mockConnConf.getConnection()).thenReturn(mockConnection);
    when(mockConnConf.locators()).thenReturn(new LinkedList());
    return new Tuple3<>(mockSparkContext, mockConnConf, mockConnection);
}
Also used : SparkContext(org.apache.spark.SparkContext) JavaSparkContext(org.apache.spark.api.java.JavaSparkContext) Tuple3(scala.Tuple3) LinkedList(scala.collection.mutable.LinkedList)

Example 13 with SparkContext

use of org.apache.spark.SparkContext in project geode by apache.

the class JavaAPITest method testJavaSparkContextFunctions.

@Test
public void testJavaSparkContextFunctions() throws Exception {
    SparkContext mockSparkContext = mock(SparkContext.class);
    JavaSparkContext mockJavaSparkContext = mock(JavaSparkContext.class);
    when(mockJavaSparkContext.sc()).thenReturn(mockSparkContext);
    GeodeJavaSparkContextFunctions wrapper = javaFunctions(mockJavaSparkContext);
    assertTrue(mockSparkContext == wrapper.sc);
}
Also used : SparkContext(org.apache.spark.SparkContext) JavaSparkContext(org.apache.spark.api.java.JavaSparkContext) JavaSparkContext(org.apache.spark.api.java.JavaSparkContext) Test(org.junit.Test)

Example 14 with SparkContext

use of org.apache.spark.SparkContext in project incubator-systemml by apache.

the class MLContextUtil method getSparkContextFromProxy.

/**
	 * Obtain the Spark Context from the MLContextProxy
	 *
	 * @return the Spark Context
	 */
public static SparkContext getSparkContextFromProxy() {
    MLContext activeMLContext = MLContextProxy.getActiveMLContextForAPI();
    SparkContext sc = getSparkContext(activeMLContext);
    return sc;
}
Also used : SparkContext(org.apache.spark.SparkContext) JavaSparkContext(org.apache.spark.api.java.JavaSparkContext)

Example 15 with SparkContext

use of org.apache.spark.SparkContext in project cdap by caskdata.

the class NaiveBayesClassifier method initialize.

@Override
public void initialize(SparkExecutionPluginContext context) throws Exception {
    FileSet fileSet = context.getDataset(config.fileSetName);
    Location modelLocation = fileSet.getBaseLocation().append(config.path);
    if (!modelLocation.exists()) {
        throw new IllegalArgumentException(String.format("Failed to find model to use for classification. Location does not exist: %s.", modelLocation));
    }
    // load the model from a file in the model fileset
    JavaSparkContext javaSparkContext = context.getSparkContext();
    SparkContext sparkContext = JavaSparkContext.toSparkContext(javaSparkContext);
    loadedModel = NaiveBayesModel.load(sparkContext, modelLocation.toURI().getPath());
    tf = new HashingTF(100);
}
Also used : SparkContext(org.apache.spark.SparkContext) JavaSparkContext(org.apache.spark.api.java.JavaSparkContext) FileSet(co.cask.cdap.api.dataset.lib.FileSet) HashingTF(org.apache.spark.mllib.feature.HashingTF) JavaSparkContext(org.apache.spark.api.java.JavaSparkContext) Location(org.apache.twill.filesystem.Location)

Aggregations

SparkContext (org.apache.spark.SparkContext)15 Configuration (org.apache.hadoop.conf.Configuration)6 SparkConf (org.apache.spark.SparkConf)5 JavaSparkContext (org.apache.spark.api.java.JavaSparkContext)5 Test (org.junit.Test)5 Graph (uk.gov.gchq.gaffer.graph.Graph)5 DataOutputStream (java.io.DataOutputStream)4 HashSet (java.util.HashSet)4 ByteArrayOutputStream (org.apache.commons.io.output.ByteArrayOutputStream)4 Edge (uk.gov.gchq.gaffer.data.element.Edge)4 Element (uk.gov.gchq.gaffer.data.element.Element)4 Entity (uk.gov.gchq.gaffer.data.element.Entity)4 User (uk.gov.gchq.gaffer.user.User)4 File (java.io.File)3 SQLContext (org.apache.spark.sql.SQLContext)3 Tuple2 (scala.Tuple2)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 Method (java.lang.reflect.Method)2 ArrayList (java.util.ArrayList)2 ArrayBuffer (scala.collection.mutable.ArrayBuffer)2