Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 2 additions & 3 deletions core/src/main/scala/org/apache/spark/SparkContext.scala
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,8 @@ class SparkContext(config: SparkConf) extends Logging {
this(SparkContext.updatedConf(new SparkConf(), master, appName, sparkHome, jars, environment))
}

// NOTE: The below constructors could be consolidated using default arguments. Due to
// Scala bug SI-8479, however, this causes the compile step to fail when generating docs.
// Until we have a good workaround for that bug the constructors remain broken out.
// The following constructors are required when Java code accesses SparkContext directly.
// Please see SI-4278

/**
* Alternative constructor that allows setting common Spark properties directly
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* 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 test.org.apache.spark;

import java.io.*;

import scala.collection.immutable.List;
import scala.collection.immutable.List$;
import scala.collection.immutable.Map;
import scala.collection.immutable.Map$;

import org.junit.Test;

import org.apache.spark.api.java.*;
import org.apache.spark.*;

/**
* Java apps can uses both Java-friendly JavaSparkContext and Scala SparkContext.
*/
public class JavaSparkContextSuite implements Serializable {

@Test
public void javaSparkContext() {
String[] jars = new String[] {};
java.util.Map<String, String> environment = new java.util.HashMap<>();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nit: just import these classes as usual?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Thank you for review, @srowen !
This is due to the import conflicts on Map. Java code still doesn't allow import aliasing. We can do aliasing only in Scala code.


new JavaSparkContext(new SparkConf().setMaster("local").setAppName("name")).stop();
new JavaSparkContext("local", "name", new SparkConf()).stop();
new JavaSparkContext("local", "name").stop();
new JavaSparkContext("local", "name", "sparkHome", "jarFile").stop();
new JavaSparkContext("local", "name", "sparkHome", jars).stop();
new JavaSparkContext("local", "name", "sparkHome", jars, environment).stop();
}

@Test
public void scalaSparkContext() {
List<String> jars = List$.MODULE$.empty();
Map<String, String> environment = Map$.MODULE$.empty();

new SparkContext(new SparkConf().setMaster("local").setAppName("name")).stop();
new SparkContext("local", "name", new SparkConf()).stop();
new SparkContext("local", "name").stop();
new SparkContext("local", "name", "sparkHome").stop();
new SparkContext("local", "name", "sparkHome", jars).stop();
new SparkContext("local", "name", "sparkHome", jars, environment).stop();
}
}