Skip to content

Commit f26c296

Browse files
authored
issue #195: support scala 2.12 (#223)
* issue #195: added scala version to artifact id * issue #195: update scalatest to 3.0.8 * issue #195: update source code to be compile with scala 2.12 * issue #195: script to change scala version in maven * issue #195: bump version to 2.4.2-SNAPSHOT * issue #195: docs updated
1 parent d128b4c commit f26c296

File tree

5 files changed

+80
-7
lines changed

5 files changed

+80
-7
lines changed

.travis.yml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,17 @@ sudo: required
22
language: scala
33
jdk:
44
- openjdk8
5-
scala:
6-
- 2.11.2
75
install:
86
- wget http://download.redis.io/releases/redis-5.0.1.tar.gz
97
- tar -xzvf redis-5.0.1.tar.gz
108
- make -C redis-5.0.1 -j4
119
- export PATH=$PWD/redis-5.0.1/src:$PATH
12-
script: make test
10+
script:
11+
- make test # test with scala 2.11
12+
- sleep 5s # let redis exit gracefully (we use kill, not kill -9 in makefile)
13+
- ps aux | grep redis
14+
- ./dev/change-scala-version.sh 2.12 # switch to scala 2.12
15+
- make test # test with scala 2.12
1316
cache:
1417
directories:
1518
- $HOME/.m2

dev/change-scala-version.sh

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#!/usr/bin/env bash
2+
3+
set -e
4+
5+
VALID_VERSIONS=( 2.11 2.12 )
6+
7+
SCALA_211_MINOR_VERSION="12"
8+
SCALA_212_MINOR_VERSION="9"
9+
10+
usage() {
11+
echo "Usage: $(basename $0) [-h|--help] <version>
12+
where :
13+
-h| --help Display this help text
14+
valid version values : ${VALID_VERSIONS[*]}
15+
" 1>&2
16+
exit 1
17+
}
18+
19+
if [[ ($# -ne 1) || ( $1 == "--help") || $1 == "-h" ]]; then
20+
usage
21+
fi
22+
23+
TO_MAJOR_VERSION=$1
24+
25+
check_scala_version() {
26+
for i in ${VALID_VERSIONS[*]}; do [ $i = "$1" ] && return 0; done
27+
echo "Invalid Scala version: $1. Valid versions: ${VALID_VERSIONS[*]}" 1>&2
28+
exit 1
29+
}
30+
31+
check_scala_version "$TO_MAJOR_VERSION"
32+
33+
if [ $TO_MAJOR_VERSION = "2.12" ]; then
34+
FROM_MAJOR_VERSION="2.11"
35+
FROM_MINOR_VERSION=$SCALA_211_MINOR_VERSION
36+
TO_MINOR_VERSION=$SCALA_212_MINOR_VERSION
37+
else
38+
FROM_MAJOR_VERSION="2.12"
39+
FROM_MINOR_VERSION=$SCALA_212_MINOR_VERSION
40+
TO_MINOR_VERSION=$SCALA_211_MINOR_VERSION
41+
fi
42+
43+
sed_i() {
44+
sed -e "$1" "$2" > "$2.tmp" && mv "$2.tmp" "$2"
45+
}
46+
47+
export -f sed_i
48+
49+
# change <artifactId>
50+
BASEDIR=$(dirname $0)/..
51+
find "$BASEDIR" -name 'pom.xml' -not -path '*target*' -print \
52+
-exec bash -c "sed_i 's/\(artifactId.*\)_'$FROM_MAJOR_VERSION'/\1_'$TO_MAJOR_VERSION'/g' {}" \;
53+
54+
# change <scala.major.version>
55+
find "$BASEDIR" -name 'pom.xml' -not -path '*target*' -print \
56+
-exec bash -c "sed_i 's/\(<scala.major.version>\)'$FROM_MAJOR_VERSION'/\1'$TO_MAJOR_VERSION'/g' {}" \;
57+
58+
# change <scala.complete.version>
59+
find "$BASEDIR" -name 'pom.xml' -not -path '*target*' -print \
60+
-exec bash -c "sed_i 's/\(<scala.complete.version>.*\.\)'$FROM_MINOR_VERSION'/\1'$TO_MINOR_VERSION'/g' {}" \;
61+

doc/dev.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,12 @@ To build Spark-Redis skipping tests, run:
2525
```
2626
mvn clean package -DskipTests
2727
```
28+
29+
To change scala version use `./dev/change-scala-version.sh` script. It will change scala version in `pom.xml`. For example:
30+
```
31+
./dev/change-scala-version.sh 2.12
32+
```
33+
34+
```
35+
./dev/change-scala-version.sh 2.11
36+
```

pom.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
33
<modelVersion>4.0.0</modelVersion>
44
<groupId>com.redislabs</groupId>
5-
<artifactId>spark-redis</artifactId>
6-
<version>2.4.1-SNAPSHOT</version>
5+
<artifactId>spark-redis_2.11</artifactId>
6+
<version>2.4.2-SNAPSHOT</version>
77
<name>Spark-Redis</name>
88
<description>A Spark library for Redis</description>
99
<url>http://github.com/RedisLabs/spark-redis</url>
@@ -300,7 +300,7 @@
300300
<dependency>
301301
<groupId>org.scalatest</groupId>
302302
<artifactId>scalatest_${scala.major.version}</artifactId>
303-
<version>2.2.1</version>
303+
<version>3.0.8</version>
304304
<scope>test</scope>
305305
</dependency>
306306
</dependencies>

src/main/scala/org/apache/spark/sql/redis/RedisSourceRelation.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ class RedisSourceRelation(override val sqlContext: SQLContext,
132132
}
133133

134134
// write data
135-
data.foreachPartition { partition =>
135+
data.foreachPartition { partition: Iterator[Row] =>
136136
// grouped iterator to only allocate memory for a portion of rows
137137
partition.grouped(iteratorGroupingSize).foreach { batch =>
138138
// the following can be optimized to not create a map

0 commit comments

Comments
 (0)