Skip to content
Closed
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
9fdd5b3
set access credentials on the Configuration, so reads can succeed
koeninger Jul 30, 2015
9d280ec
Update build to test using official Amazon JDBC driver.
JoshRosen Aug 18, 2015
b479bb1
Move from .sbt to .scala SBT build definition.
JoshRosen Aug 18, 2015
47bb64b
Import Kai's Redshift tests.
JoshRosen Aug 18, 2015
6cba042
WIP towards documenting how to run tests.
JoshRosen Aug 18, 2015
9b257e1
Nicer error message for missing configurations
JoshRosen Aug 18, 2015
695183f
Merge remote-tracking branch 'koeninger/set-credentials' into integra…
JoshRosen Aug 18, 2015
4b203c7
Move creation of temporary tables into beforeEach() method.
JoshRosen Aug 18, 2015
ffa00d3
Fix deletion of S3 files in afterAll()
JoshRosen Aug 18, 2015
8371d6a
Ignore tests that are currently failing
JoshRosen Aug 18, 2015
3652056
Add encrypted credentials to Travis build.
JoshRosen Aug 18, 2015
e08b513
Change Redshift password
JoshRosen Aug 18, 2015
4e517ae
Require S3N URLs to be used
JoshRosen Aug 19, 2015
55c7724
Use randomized table names + dir name to avoid conflicts between Trav…
JoshRosen Aug 19, 2015
cf1d516
Use multi-row insert statement
JoshRosen Aug 19, 2015
14e3cc2
Only use positive numbers in table names.
JoshRosen Aug 19, 2015
b62646f
Merge remote-tracking branch 'db/master' into integration-tests
JoshRosen Aug 19, 2015
66c166d
Update assertions and unignore tests
JoshRosen Aug 19, 2015
bffe6eb
Use HiveContext in integration tests
JoshRosen Aug 19, 2015
da4800a
Use TestHiveContext to work around temp. metastore issues
JoshRosen Aug 19, 2015
7c4f64b
Pass options to save commands.
JoshRosen Aug 19, 2015
2959a9c
Copy Spark code to minimize reliance on private APIs.
JoshRosen Aug 19, 2015
78a6ccb
Merge branch 'remove-private-sql-usage' into integration-tests
JoshRosen Aug 19, 2015
b86d74e
Fix test compile
JoshRosen Aug 19, 2015
24f9a9e
Two minor fixes
JoshRosen Aug 19, 2015
a74a950
Fix problem in reflection code
JoshRosen Aug 19, 2015
39edc80
Merge remote-tracking branch 'origin/master' into integration-tests
JoshRosen Aug 19, 2015
40581fe
Add Scalastyle for integration tests; code cleanup.
JoshRosen Aug 19, 2015
681b5f2
Remove failing test
JoshRosen Aug 19, 2015
7fabdd7
Merge remote-tracking branch 'origin/master' into integration-tests
JoshRosen Aug 20, 2015
a1f0146
Revert "set access credentials on the Configuration, so reads can suc…
JoshRosen Aug 20, 2015
93faac2
Address review comments.
JoshRosen Aug 20, 2015
b82e5fd
Style fix.
JoshRosen Aug 20, 2015
2e6e274
Change credential variable names
JoshRosen Aug 20, 2015
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
21 changes: 18 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,25 @@ cache:
directories:
- $HOME/.ivy2
env:
- HADOOP_VERSION="1.0.4"
- HADOOP_VERSION="1.2.1"
- HADOOP_VERSION="2.2.0"
matrix:
- HADOOP_VERSION="1.0.4"
- HADOOP_VERSION="1.2.1"
- HADOOP_VERSION="2.2.0"
global:
# AWS_REDSHIFT_JDBC_URL
- secure: "RNkxdKcaKEYuJqxli8naazp42qO5/pgueIzs+J5rHwl39jcBvJMgW3DX8kT7duzdoBb/qrolj/ttbQ3l/30P45+djn0BEwcJMX7G/FGpZYD23yd03qeq7sOKPQl2Ni/OBttYHJMah5rI6aPmAysBZMQO7Wijdenb/RUiU2YcZp0="
# AWS_REDSHIFT_PASSWORD
- secure: "Bzre/ohanBt6wrj5asn8+iaIU5qm2QBZ+P/PiAeg55R5sqfyI/pwCYZKdtKSG7SuKzsoiAOtnjvcXMD2hickTLIDz3GmrvFcpx7yn3PEKoLQfT4Ry1/RMOsqa1+sj6zJ7J2dl4w0AURJ7Jb9/7GRylNnL0jkUvqUnWet8PBb7R8="
# AWS_REDSHIFT_USER
- secure: "LIkY/ZpBXK3vSFsdpBSRXEsgfD2wDF52X8OZOlyBJOiZpS4y1/obj8b3VQABDPyPH95bGX/LOpM0vVM137rYgF0pskgVEzLMyZOPpwYqNGPf/d4BtQhBRc8f7+jmr6D4Hrox4jCl0cCKaeiTazun2+Y9E+zgCUDvQ8y9qGctR2k="
# AWS_ACCESS_KEY_ID
- secure: "CDlql+nrgdi7sUr7bYyXF4CFoOUCiJG9WEYNRV4k/lC37eS/al3iVYicnXqF+6UrPv5a4kHulG4d3g78J4hzn4ZVJuEhn6v8beoOBUoJJ7W/J05hVwGiQFxUq86wT3tIaBrAuDmOXaAnPEvDmPfJGNZL9ZG1CaQJo70R/HkbbVA="
# AWS_SECRET_ACCESS_KEY
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wonder if I should purposely give these different names than the ones expected by the Amazon SDKs; this might be necessary in order to be able to test credential mechanisms (e.g. for writing a regression test for #32)

- secure: "V/Ac0ZkTslNpNc8wszalFqZYWnl910PgSORlA2tyTUCC/xfqX+CdtN9RNuVb3LBrvrkYiOBKF7ANMGOxnc/yazLNFBUmByf+rwEfR7NDCCz+SKXSNwIOPpDraOpNVd1KLyrJ9uKivFojW/IweN9bsJAEji8ql/Lpeb7qKfDbVWY="
# AWS_S3_SCRATCH_SPACE
- secure: "LvndQIW6dHs6nyaMHtblGI/oL+s460lOezFs2BoD0Isenb/O/IM+nY5K9HepTXjJIcq8qvUYnojZX1FCrxxOXX2/+/Iihiq7GzJYdmdMC6hLg9bJYeAFk0dWYT88/AwadrJCBOa3ockRLhiO3dkai7Ki5+M1erfaFiAHHMpJxYQ="
script:
- sbt -Dhadoop.version=$HADOOP_VERSION coverage test
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: is there a reason to not test style and other fast stuff first?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wanted the tests to still be able to run even if style checks failed. I figured this wasn't a huge deal here compared to what we do in Spark because the test time is really fast.

- if [ "$TRAVIS_SECURE_ENV_VARS" ]; then sbt -Dhadoop.version=$HADOOP_VERSION coverage it:test; fi
after_success:
- bash <(curl -s https://codecov.io/bash)
17 changes: 9 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ Further, as Redshift is an AWS product, some AWS libraries will be required. Thi
your deployment environment will include `hadoop-aws`, or other things necessary to access S3, credentials,
etc. Check the dependencies with "provided" scope in <tt>build.sbt</tt> if you're at all unclear.

You're also going to need a JDBC driver that is compatible with Redshift. The one used for testing can be
found in <tt>build.sbt</tt>, however Amazon recommend that you use [their driver](http://docs.aws.amazon.com/redshift/latest/mgmt/configure-jdbc-connection.html).
You're also going to need a JDBC driver that is compatible with Redshift. Amazon recommend that you
use [their driver](http://docs.aws.amazon.com/redshift/latest/mgmt/configure-jdbc-connection.html),
although this library has also been successfully tested using the Postgres JDBC driver.

## Usage

Expand All @@ -49,7 +50,7 @@ val sqlContext = new SQLContext(sc)
// Get some data from a Redshift table
val df: DataFrame = sqlContext.read
.format("com.databricks.spark.redshift")
.option("url", "jdbc:postgresql://redshifthost:5439/database?user=username&password=pass")
.option("url", "jdbc:redshift://redshifthost:5439/database?user=username&password=pass")
.option("dbtable" -> "my_table")
.option("tempdir" -> "s3://path/for/temp/data")
.load()
Expand All @@ -59,7 +60,7 @@ val df: DataFrame = sqlContext.read

df.write
.format("com.databricks.spark.redshift")
.option("url", "jdbc:postgresql://redshifthost:5439/database?user=username&password=pass")
.option("url", "jdbc:redshift://redshifthost:5439/database?user=username&password=pass")
.option("dbtable" -> "my_table_copy")
.option("tempdir" -> "s3://path/for/temp/data")
.mode("error")
Expand All @@ -77,15 +78,15 @@ sql_context = SQLContext(sc)
# Read data from a table
df = sql_context.read \
.format("com.databricks.spark.redshift") \
.option("url", "jdbc:postgresql://redshifthost:5439/database?user=username&password=pass") \
.option("url", "jdbc:redshift://redshifthost:5439/database?user=username&password=pass") \
.option("dbtable" -> "my_table") \
.option("tempdir" -> "s3://path/for/temp/data") \
.load()

# Write back to a table
df.write \
.format("com.databricks.spark.redshift")
.option("url", "jdbc:postgresql://redshifthost:5439/database?user=username&password=pass") \
.option("url", "jdbc:redshift://redshifthost:5439/database?user=username&password=pass") \
.option("dbtable" -> "my_table_copy") \
.option("tempdir" -> "s3://path/for/temp/data") \
.mode("error")
Expand All @@ -99,7 +100,7 @@ CREATE TABLE my_table
USING com.databricks.spark.redshift
OPTIONS (dbtable 'my_table',
tempdir 's3://my_bucket/tmp',
url 'jdbc:postgresql://host:port/db?user=username&password=pass');
url 'jdbc:redshift://host:port/db?user=username&password=pass');
```

### Scala helper functions
Expand Down Expand Up @@ -204,7 +205,7 @@ and use that as a temp location for this data.
<tr>
<td><tt>jdbcdriver</tt></td>
<td>No</td>
<td><tt>org.postgresql.Driver</tt></td>
<td><tt>com.amazon.redshift.jdbc4.Driver</tt></td>
<td>The class name of the JDBC driver to load before JDBC operations. Must be on classpath.</td>
</tr>
<tr>
Expand Down
49 changes: 0 additions & 49 deletions build.sbt

This file was deleted.

66 changes: 66 additions & 0 deletions project/SparkRedshiftBuild.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* Copyright 2015 Databricks
*
* Licensed 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.
*/

import sbt._
import sbt.Keys._
import sbtsparkpackage.SparkPackagePlugin.autoImport._
import scoverage.ScoverageSbtPlugin

object SparkRedshiftBuild extends Build {
val hadoopVersion = settingKey[String]("Hadoop version")

// Define a custom test configuration so that unit test helper classes can be re-used under
// the integration tests configuration; see http://stackoverflow.com/a/20635808.
lazy val IntegrationTest = config("it") extend Test

lazy val root = Project("spark-redshift", file("."))
.configs(IntegrationTest)
.settings(net.virtualvoid.sbt.graph.Plugin.graphSettings: _*)
.settings(Defaults.itSettings: _*)
.settings(Seq(
name := "spark-redshift",
organization := "com.databricks",
version := "0.4.1-SNAPSHOT",
scalaVersion := "2.10.4",
Copy link
Contributor

Choose a reason for hiding this comment

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

Doesn't have to be here, but in a followup can we make sure to cross publish 2.11?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep, I plan to add Scala versions to the Matrix build configuration.

sparkVersion := sys.props.get("spark.version").getOrElse("1.4.1"),
hadoopVersion := sys.props.get("hadoop.version").getOrElse("2.2.0"),
spName := "databricks/spark-redshift",
sparkComponents += "sql",
licenses += "Apache-2.0" -> url("http://opensource.org/licenses/Apache-2.0"),
credentials += Credentials(Path.userHome / ".ivy2" / ".credentials"),
resolvers +=
"Sonatype OSS Snapshots" at "https://oss.sonatype.org/content/repositories/snapshots",
libraryDependencies ++= Seq(
"com.amazonaws" % "aws-java-sdk-core" % "1.9.40" % "provided",
// We require spark-avro, but avro-mapred must be provided to match Hadoop version:
"com.databricks" %% "spark-avro" % "1.0.0",
Copy link
Contributor

Choose a reason for hiding this comment

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

Another comment so I don't forget, we should update this when we publish a new version of avro (and I guess this creates a cross publishing ordering dependency).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes. The fact that spark-avro is not currently cross-published for 2.11 is one of the main blockers to 2.11 support here.

"org.apache.avro" % "avro-mapred" % "1.7.6" % "provided" exclude("org.mortbay.jetty", "servlet-api"),
// A Redshift-compatible JDBC driver must be present on the classpath for spark-redshift to work.
// For testing, we use an Amazon driver, which is available from
// http://docs.aws.amazon.com/redshift/latest/mgmt/configure-jdbc-connection.html
"com.amazon.redshift" % "jdbc4" % "1.1.7.1007" % "test" from "https://s3.amazonaws.com/redshift-downloads/drivers/RedshiftJDBC4-1.1.7.1007.jar",
"com.google.guava" % "guava" % "14.0.1" % "test",
"org.scalatest" %% "scalatest" % "2.1.5" % "test",
"org.scalamock" %% "scalamock-scalatest-support" % "3.2" % "test"
),
ScoverageSbtPlugin.ScoverageKeys.coverageHighlighting := {
if (scalaBinaryVersion.value == "2.10") false
else false
},
// Display full-length stacktraces from ScalaTest:
testOptions in Test += Tests.Argument("-oF")
): _*)
}
Loading