-
Notifications
You must be signed in to change notification settings - Fork 0
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 #2 from am-giordano/v020
V020
- Loading branch information
Showing
7 changed files
with
131 additions
and
22 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,4 +3,5 @@ | |
/.idea/ | ||
/data/output/ | ||
/project/ | ||
/releases/ | ||
/target/ |
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,6 +1,10 @@ | ||
name := "spark-relational" | ||
version := "0.1.1" | ||
version := "0.2.0" | ||
organization := "com.amgiordano.spark" | ||
scalaVersion := "2.12.15" | ||
publishMavenStyle := true | ||
libraryDependencies += "org.apache.spark" % "spark-sql_2.12" % "3.3.0" | ||
|
||
libraryDependencies ++= Seq( | ||
"org.apache.spark" %% "spark-sql" % "3.3.0", | ||
"org.scalatest" %% "scalatest" % "3.3.0-SNAP3" | ||
) |
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,27 @@ | ||
username=am-giordano | ||
|
||
version=$(grep 'version :=' build.sbt | sed 's/version := "\(.*\)"/\1/') | ||
group_id=$(grep 'organization :=' build.sbt | sed 's/organization := "\(.*\)"/\1/') | ||
artifact_id=$(grep 'name :=' build.sbt | sed 's/name := "\(.*\)"/\1/') | ||
scala_version=$(grep 'scalaVersion :=' build.sbt | sed 's/scalaVersion := "\(.*\)\..*"/\1/') | ||
target_prefix=target/scala-"$scala_version"/"$artifact_id"_"$scala_version"-"$version" | ||
jar="$artifact_id"-"$version".jar | ||
pom="$artifact_id"-"$version".pom | ||
|
||
sbt publishLocal | ||
|
||
cp "$target_prefix".jar "$jar" | ||
cp "$target_prefix".pom "$pom" | ||
|
||
echo "JAR STRUCTURE" | ||
jar tf "$jar" | ||
|
||
echo "POM CONTENTS" | ||
cat "$pom" | ||
|
||
sed -ibackup "s/$group_id/$username/" "$pom" | ||
sed -ibackup "s/${artifact_id}_$scala_version/$artifact_id/" "$pom" | ||
|
||
zip "releases/$artifact_id-$version.zip" "$jar" "$pom" | ||
|
||
rm "$jar" "$pom" "$pom"backup |
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
54 changes: 54 additions & 0 deletions
54
src/test/scala/com/amgiordano/spark/relational/RelationalSchemaSuite.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 |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package com.amgiordano.spark.relational | ||
|
||
import org.apache.spark.sql.{DataFrame, SparkSession} | ||
import org.scalatest.Assertion | ||
import org.scalatest.funsuite.AnyFunSuite | ||
|
||
class RelationalSchemaSuite extends AnyFunSuite { | ||
|
||
val spark: SparkSession = SparkSession.builder.master("local[1]").getOrCreate | ||
spark.sparkContext.setLogLevel("WARN") | ||
import spark.implicits._ | ||
|
||
def assertSameRS(inputStrings: Seq[String], expectedSchema: Map[String, Seq[String]]): Assertion = { | ||
val dfInput = spark.read.json(inputStrings.toDS) | ||
val rs = RelationalSchema(dfInput) | ||
assert(rs.dataFrames.forall(item => assertSameDataFrames(item._2, spark.read.json(expectedSchema(item._1).toDS)))) | ||
} | ||
|
||
def assertSameDataFrames(dfActual: DataFrame, dfExpected: DataFrame): Boolean = { | ||
val aCols = dfActual.columns.sorted | ||
val eCols = dfExpected.columns.sorted | ||
if (aCols sameElements eCols) aCols.forall(c => values(dfActual, c) sameElements values(dfExpected, c)) else false | ||
} | ||
|
||
def values(df: DataFrame, colName: String): Array[Any] = df.select(colName).collect.map(_(0)) | ||
|
||
test("Flat document") { | ||
assertSameRS(Seq("{'a': 0}"), Map("main" -> Seq("{'main!!__id__': 0, 'a': 0}"))) | ||
} | ||
|
||
test("With object") { | ||
assertSameRS(Seq("{'a': {'b': 0}}"), Map("main" -> Seq("{'main!!__id__': 0, 'a!!b': 0}"))) | ||
} | ||
|
||
test("With array") { | ||
assertSameRS( | ||
Seq("{'a': [0]}"), | ||
Map( | ||
"main" -> Seq("{'main!!__id__': 0}"), | ||
"a" -> Seq("{'a!!__id__': 0, 'main!!__id__': 0, 'a': 0}") | ||
) | ||
) | ||
} | ||
|
||
test("With array of objects") { | ||
assertSameRS( | ||
Seq("{'a': [{'b': 0}]}"), | ||
Map( | ||
"main" -> Seq("{'main!!__id__': 0}"), | ||
"a" -> Seq("{'a!!__id__': 0, 'main!!__id__': 0, 'a!!b': 0}") | ||
) | ||
) | ||
} | ||
} |