-
Notifications
You must be signed in to change notification settings - Fork 190
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
BDP-7396: TransportUdf Determine scala version in CoralSpark and retu…
…rn respective ivy link (#119)
- Loading branch information
Showing
7 changed files
with
254 additions
and
44 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 |
---|---|---|
@@ -0,0 +1,32 @@ | ||
def itests = ['spark', 'spark3'] | ||
|
||
for (String itest : itests) { | ||
sourceSets { | ||
create("${itest}test", { | ||
java { | ||
compileClasspath += main.output | ||
runtimeClasspath += main.output | ||
} | ||
}) | ||
} | ||
|
||
configurations { | ||
getByName("${itest}testCompile").extendsFrom(testCompile) | ||
getByName("${itest}testRuntime").extendsFrom(testRuntime) | ||
} | ||
|
||
tasks.register("${itest}Test", Test) { | ||
description = "Run ${itest} integration tests" | ||
testClassesDirs = project.sourceSets.getByName("${itest}test").output.classesDirs | ||
classpath = project.sourceSets.getByName("${itest}test").runtimeClasspath | ||
shouldRunAfter test | ||
useTestNG() | ||
} | ||
|
||
check.dependsOn(tasks.getByName("${itest}Test")) | ||
} | ||
|
||
dependencies { | ||
sparktestCompile(deps.'spark'.'hive') | ||
spark3testCompile(deps.'spark3'.'hive') | ||
} |
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
70 changes: 70 additions & 0 deletions
70
coral-spark/src/spark3test/java/com.linkedin.coral.spark/TransportableUDFMapTest.java
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 |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/** | ||
* Copyright 2018-2021 LinkedIn Corporation. All rights reserved. | ||
* Licensed under the BSD-2 Clause license. | ||
* See LICENSE in the project root for license information. | ||
*/ | ||
package com.linkedin.coral.spark; | ||
|
||
import org.apache.spark.sql.SparkSession; | ||
import org.testng.Assert; | ||
import org.testng.annotations.Test; | ||
|
||
import com.linkedin.coral.spark.exceptions.UnsupportedUDFException; | ||
|
||
|
||
public class TransportableUDFMapTest { | ||
|
||
@Test | ||
public void testScalaVersionWithSparkSession() { | ||
SparkSession ss = SparkSession.builder().appName(TransportableUDFMapTest.class.getSimpleName()).master("local[1]") | ||
.enableHiveSupport().getOrCreate(); | ||
Assert.assertEquals(TransportableUDFMap.getScalaVersion(), TransportableUDFMap.ScalaVersion.SCALA_2_12); | ||
ss.close(); | ||
} | ||
|
||
@Test | ||
public void testDefaultScalaVersion() { | ||
// If SparkSession is not active, getScalaVersion should return Scala2.11 | ||
Assert.assertEquals(TransportableUDFMap.getScalaVersion(), TransportableUDFMap.ScalaVersion.SCALA_2_11); | ||
} | ||
|
||
@Test | ||
public void testLookupWithSparkSession() { | ||
SparkSession ss = SparkSession.builder().appName(TransportableUDFMapTest.class.getSimpleName()).master("local[1]") | ||
.enableHiveSupport().getOrCreate(); | ||
String stdDaliUdf = "com.linkedin.dali.udf.date.hive.EpochToDateFormat"; | ||
Assert.assertTrue(TransportableUDFMap.lookup(stdDaliUdf).get().getArtifactoryUrls().get(0).toString() | ||
.contains("classifier=spark_2.12")); | ||
ss.close(); | ||
} | ||
|
||
@Test | ||
public void testDefaultLookup() { | ||
// If SparkSession is not active, lookup should return Scala2.11 | ||
String stdDaliUdf = "com.linkedin.dali.udf.date.hive.EpochToDateFormat"; | ||
Assert.assertTrue(TransportableUDFMap.lookup(stdDaliUdf).get().getArtifactoryUrls().get(0).toString() | ||
.contains("classifier=spark_2.11")); | ||
} | ||
|
||
@Test | ||
public void testLookupDoesNotExist() { | ||
String stdClassName = "com.linkedin.dali.udf.date.hive.UdfDoesNotExist"; | ||
Assert.assertFalse(TransportableUDFMap.lookup(stdClassName).isPresent()); | ||
} | ||
|
||
@Test | ||
public void testLookupExistButNotReadyForSpark3() { | ||
SparkSession ss = SparkSession.builder().appName(TransportableUDFMapTest.class.getSimpleName()).master("local[1]") | ||
.enableHiveSupport().getOrCreate(); | ||
try { | ||
String stdClassName = "com.transport.test.hive.Spark3Fail"; | ||
TransportableUDFMap.add(stdClassName, "com.transport.test.spark.Spark3Fail", | ||
"com.transport:spark-udf:0.0.0?classifier=spark", null); | ||
TransportableUDFMap.lookup(stdClassName); | ||
} catch (Exception ex) { | ||
Assert.assertTrue(ex instanceof UnsupportedUDFException); | ||
} finally { | ||
ss.close(); | ||
} | ||
} | ||
} |
64 changes: 64 additions & 0 deletions
64
coral-spark/src/sparktest/java/com.linkedin.coral.spark/TransportableUDFMapTest.java
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 |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/** | ||
* Copyright 2018-2021 LinkedIn Corporation. All rights reserved. | ||
* Licensed under the BSD-2 Clause license. | ||
* See LICENSE in the project root for license information. | ||
*/ | ||
package com.linkedin.coral.spark; | ||
|
||
import org.apache.spark.sql.SparkSession; | ||
import org.testng.Assert; | ||
import org.testng.annotations.Test; | ||
|
||
|
||
public class TransportableUDFMapTest { | ||
|
||
@Test | ||
public void testScalaVersionWithSparkSession() { | ||
SparkSession ss = SparkSession.builder().appName(TransportableUDFMapTest.class.getSimpleName()).master("local[1]") | ||
.enableHiveSupport().getOrCreate(); | ||
Assert.assertEquals(TransportableUDFMap.getScalaVersion(), TransportableUDFMap.ScalaVersion.SCALA_2_11); | ||
ss.close(); | ||
} | ||
|
||
@Test | ||
public void testDefaultScalaVersion() { | ||
// If SparkSession is not active, getScalaVersion should return Scala2.11 | ||
Assert.assertEquals(TransportableUDFMap.getScalaVersion(), TransportableUDFMap.ScalaVersion.SCALA_2_11); | ||
} | ||
|
||
@Test | ||
public void testLookupWithSparkSession() { | ||
SparkSession ss = SparkSession.builder().appName(TransportableUDFMapTest.class.getSimpleName()).master("local[1]") | ||
.enableHiveSupport().getOrCreate(); | ||
String stdDaliUdf = "com.linkedin.dali.udf.date.hive.EpochToDateFormat"; | ||
Assert.assertTrue(TransportableUDFMap.lookup(stdDaliUdf).get().getArtifactoryUrls().get(0).toString() | ||
.contains("classifier=spark_2.11")); | ||
ss.close(); | ||
} | ||
|
||
@Test | ||
public void testDefaultLookup() { | ||
// If SparkSession is not active, lookup should return Scala2.11 | ||
String stdDaliUdf = "com.linkedin.dali.udf.date.hive.EpochToDateFormat"; | ||
Assert.assertTrue(TransportableUDFMap.lookup(stdDaliUdf).get().getArtifactoryUrls().get(0).toString() | ||
.contains("classifier=spark_2.11")); | ||
} | ||
|
||
@Test | ||
public void testLookupDoesNotExist() { | ||
String stdClassName = "com.linkedin.dali.udf.date.hive.UdfDoesNotExist"; | ||
Assert.assertFalse(TransportableUDFMap.lookup(stdClassName).isPresent()); | ||
} | ||
|
||
@Test | ||
public void testLookupExistButNotReadyForSpark3() { | ||
SparkSession ss = SparkSession.builder().appName(TransportableUDFMapTest.class.getSimpleName()).master("local[1]") | ||
.enableHiveSupport().getOrCreate(); | ||
String stdClassName = "com.transport.test.hive.Spark3Fail"; | ||
TransportableUDFMap.add(stdClassName, "com.transport.test.spark.Spark3Fail", | ||
"com.transport:spark-udf:0.0.0?classifier=spark_2.11", null); | ||
assert TransportableUDFMap.lookup(stdClassName).get().getArtifactoryUrls().get(0).toString() | ||
.contains("classifier=spark_2.11"); | ||
ss.close(); | ||
} | ||
} |
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
Oops, something went wrong.