forked from apache/incubator-retired-amaterasu
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request apache#19 from amezng/amaterasu-21
AMATERASU-21 Fix Spark scala tests
- Loading branch information
Showing
6 changed files
with
66 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,5 @@ | ||
import org.apache.amaterasu.executor.runtime.AmaContext | ||
|
||
val oddRdd = AmaContext.getRDD[Int]("start", "rdd").filter(x=>x/2 == 0) | ||
oddRdd.take(5).foreach(println) | ||
|
||
val highNoDf = AmaContext.getDataFrame("start", "x").where("_1 > 3") | ||
val highNoDf = AmaContext.getDataFrame("start", "x").where("age > 20") | ||
highNoDf.show |
Binary file added
BIN
+583 Bytes
...st/resources/tmp/job/start/x/part-r-00000-c370548d-1371-4c08-81d6-f2ba72defa12.gz.parquet
Binary file not shown.
Binary file added
BIN
+574 Bytes
...st/resources/tmp/job/start/x/part-r-00001-c370548d-1371-4c08-81d6-f2ba72defa12.gz.parquet
Binary file not shown.
110 changes: 56 additions & 54 deletions
110
executor/src/test/scala/org/apache/amaterasu/spark/SparkScalaRunnerTests.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,56 @@ | ||
//package org.apache.amaterasu.spark | ||
// | ||
//import java.io.File | ||
// | ||
//import org.apache.amaterasu.common.runtime._ | ||
//import org.apache.amaterasu.common.configuration.ClusterConfig | ||
//import org.apache.amaterasu.utilities.TestNotifier | ||
// | ||
//import scala.collection.JavaConverters._ | ||
//import org.apache.commons.io.FileUtils | ||
//import java.io.ByteArrayOutputStream | ||
// | ||
//import org.apache.spark.SparkConf | ||
//import org.apache.spark.repl.Main | ||
//import org.apache.spark.repl.amaterasu.runners.spark.{SparkRunnerHelper, SparkScalaRunner} | ||
//import org.apache.spark.sql.SparkSession | ||
//import org.scalatest.{BeforeAndAfterAll, FlatSpec, Matchers} | ||
// | ||
//class SparkScalaRunnerTests extends FlatSpec with Matchers with BeforeAndAfterAll { | ||
// | ||
// var runner: SparkScalaRunner = _ | ||
// | ||
// override protected def beforeAll(): Unit = { | ||
// | ||
// FileUtils.deleteQuietly(new File("/tmp/job_5/")) | ||
// | ||
// val env = Environment() | ||
// env.workingDir = "file:///tmp" | ||
// env.master = "local[*]" | ||
// | ||
// | ||
// val spark = SparkRunnerHelper.createSpark(env, "job_5", Seq.empty[String], Map.empty) | ||
// | ||
// | ||
// val notifier = new TestNotifier() | ||
// val strm = new ByteArrayOutputStream() | ||
// runner = SparkScalaRunner(env, "job_5", spark, strm, notifier, Seq.empty[String]) | ||
// super.beforeAll() | ||
// } | ||
// | ||
// "SparkScalaRunner" should "execute the simple-spark.scala" in { | ||
// | ||
// val script = getClass.getResource("/simple-spark.scala").getPath | ||
// runner.executeSource(script, "start", Map.empty[String, String].asJava) | ||
// | ||
// } | ||
// | ||
// "SparkScalaRunner" should "execute step-2.scala and access data from simple-spark.scala" in { | ||
// | ||
// val script = getClass.getResource("/step-2.scala").getPath | ||
// runner.executeSource(script, "cont", Map.empty[String, String].asJava) | ||
// | ||
// } | ||
//} | ||
/* | ||
* 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.amaterasu.spark | ||
|
||
|
||
import scala.collection.JavaConverters._ | ||
import org.apache.amaterasu.executor.common.executors.ProvidersFactory | ||
import org.apache.amaterasu.executor.runtime.AmaContext | ||
import org.apache.spark.repl.amaterasu.runners.spark.SparkScalaRunner | ||
import org.scalatest.{BeforeAndAfterAll, DoNotDiscover, FlatSpec, Matchers} | ||
|
||
import scala.io.Source | ||
|
||
@DoNotDiscover | ||
class SparkScalaRunnerTests extends FlatSpec with Matchers with BeforeAndAfterAll { | ||
var factory: ProvidersFactory = _ | ||
var runner: SparkScalaRunner = _ | ||
|
||
|
||
"SparkScalaRunner" should "execute the simple-spark.scala" in { | ||
|
||
|
||
val sparkRunner =factory.getRunner("spark", "scala").get.asInstanceOf[SparkScalaRunner] | ||
val script = getClass.getResource("/simple-spark.scala").getPath | ||
val sourceCode = Source.fromFile(script).getLines().mkString("\n") | ||
sparkRunner.executeSource(sourceCode, "start", Map.empty[String, String].asJava) | ||
|
||
} | ||
|
||
"SparkScalaRunner" should "execute step-2.scala and access data from simple-spark.scala" in { | ||
|
||
val sparkRunner =factory.getRunner("spark", "scala").get.asInstanceOf[SparkScalaRunner] | ||
val script = getClass.getResource("/step-2.scala").getPath | ||
sparkRunner.env.workingDir = s"${getClass.getResource("/tmp").getPath}" | ||
AmaContext.init(sparkRunner.spark,"job",sparkRunner.env) | ||
val sourceCode = Source.fromFile(script).getLines().mkString("\n") | ||
sparkRunner.executeSource(sourceCode, "cont", Map.empty[String, String].asJava) | ||
|
||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters