-
Notifications
You must be signed in to change notification settings - Fork 345
Use metadata to set column comments and encoding #178
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from 8 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
f10c0ff
Allow setting comments of table and columns from metadata
emlyn 9ea7896
Allow setting column encoding from metadata
emlyn 05078f6
Update README
emlyn 0066e7e
Tests
emlyn d1b3bae
Escape quotes in columns and comments
emlyn 8b38090
Add integration tests
emlyn 2e47c2c
Remove reference to spark-redshift in README
emlyn 5e42923
Address review comments
88ba25a
Fix integration tests.
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -386,6 +386,93 @@ class RedshiftIntegrationSuite extends IntegrationSuiteBase { | |
| } | ||
| } | ||
|
|
||
| test("configuring compression on columns") { | ||
| val tableName = s"configuring_compression_on_columns_$randomSuffix" | ||
| try { | ||
| val metadata = new MetadataBuilder().putString("encoding", "LZO").build() | ||
| val schema = StructType( | ||
| StructField("x", StringType, metadata = metadata) :: Nil) | ||
| sqlContext.createDataFrame(sc.parallelize(Seq(Row("a" * 128))), schema).write | ||
| .format("com.databricks.spark.redshift") | ||
| .option("url", jdbcUrl) | ||
| .option("dbtable", tableName) | ||
| .option("tempdir", tempDir) | ||
| .mode(SaveMode.ErrorIfExists) | ||
| .save() | ||
| assert(DefaultJDBCWrapper.tableExists(conn, tableName)) | ||
| val loadedDf = sqlContext.read | ||
| .format("com.databricks.spark.redshift") | ||
| .option("url", jdbcUrl) | ||
| .option("dbtable", tableName) | ||
| .option("tempdir", tempDir) | ||
| .load() | ||
| checkAnswer(loadedDf, Seq(Row("a" * 128))) | ||
| val encodingDF = sqlContext.read | ||
| .format("com.databricks.spark.redshift") | ||
| .option("url", jdbcUrl) | ||
| .option("dbtable", | ||
| s"""(SELECT "column", encoding FROM pg_table_def WHERE tablename='$tableName')""") | ||
| .option("tempdir", tempDir) | ||
| .load() | ||
| checkAnswer(encodingDF, Seq(Row("x", "LZO"))) | ||
| } finally { | ||
| conn.prepareStatement(s"drop table if exists $tableName").executeUpdate() | ||
| conn.commit() | ||
| } | ||
| } | ||
|
|
||
| test("configuring comments on columns") { | ||
| val tableName = s"configuring_comments_on_columns_$randomSuffix" | ||
| try { | ||
| val metadata = new MetadataBuilder().putString("description", "Hello Column").build() | ||
| val schema = StructType( | ||
| StructField("x", StringType, metadata = metadata) :: Nil) | ||
| sqlContext.createDataFrame(sc.parallelize(Seq(Row("a" * 128))), schema).write | ||
| .format("com.databricks.spark.redshift") | ||
| .option("url", jdbcUrl) | ||
| .option("dbtable", tableName) | ||
| .option("tempdir", tempDir) | ||
| .mode(SaveMode.ErrorIfExists) | ||
| .save() | ||
| assert(DefaultJDBCWrapper.tableExists(conn, tableName)) | ||
| val loadedDf = sqlContext.read | ||
| .format("com.databricks.spark.redshift") | ||
| .option("url", jdbcUrl) | ||
| .option("dbtable", tableName) | ||
| .option("tempdir", tempDir) | ||
| .option("description", "Hello Table") | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The "description" field isn't relevant for loads. Did you mean to put this up on line 434 instead? |
||
| .load() | ||
| checkAnswer(loadedDf, Seq(Row("a" * 128))) | ||
| val tableDF = sqlContext.read | ||
| .format("com.databricks.spark.redshift") | ||
| .option("url", jdbcUrl) | ||
| .option("dbtable", s"(SELECT pg_catalog.obj_description('$tableName'::regclass))") | ||
| .option("tempdir", tempDir) | ||
| .load() | ||
| checkAnswer(tableDF, Seq(Row("Hello Table"))) | ||
| val commentQuery = | ||
| s""" | ||
| |(SELECT c.column_name, pgd.description | ||
| |FROM pg_catalog.pg_statio_all_tables st | ||
| |INNER JOIN pg_catalog.pg_description pgd | ||
| | ON (pgd.objoid=st.relid) | ||
| |INNER JOIN information_schema.columns c | ||
| | ON (pgd.objsubid=c.ordinal_position AND c.table_name=st.relname) | ||
| |WHERE c.table_name='$tableName') | ||
| """.stripMargin; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Semicolon is unnecessary. |
||
| val columnDF = sqlContext.read | ||
| .format("com.databricks.spark.redshift") | ||
| .option("url", jdbcUrl) | ||
| .option("dbtable", commentQuery) | ||
| .option("tempdir", tempDir) | ||
| .load() | ||
| checkAnswer(columnDF, Seq(Row("x", "Hello Column"))) | ||
| } finally { | ||
| conn.prepareStatement(s"drop table if exists $tableName").executeUpdate() | ||
| conn.commit() | ||
| } | ||
| } | ||
|
|
||
| test("informative error message when saving a table with string that is longer than max length") { | ||
| val tableName = s"error_message_when_string_too_long_$randomSuffix" | ||
| try { | ||
|
|
||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interestingly, this query is now failing for me with the following error:
I received a bug report from a user who hit this problem but was never able to get to the bottom of it as far as I could tell (since I didn't have access to any logs or queries to even know which query was triggering that error). I'm going to see if I can add some additional logging to help figure out what's going on here now that I've stumbled across a reproduction.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Err, here's a better copy of the stacktrace:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a client-side error; I added
?loglevel=1to the end of my JDBC URL in order to get the Redshift JDBC driver to perform more logging and usedDriverManager.setLogWriter(new PrintWriter(System.out))to direct those logs to stdout.This produced the following output:
It looks like what's happening here is that we're trying to perform an
UNLOADon a leader-only table, which is unsupported: https://stackoverflow.com/questions/28719808/how-to-unload-pg-table-def-table-to-s3There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think what you'll have to do here is to use the regular JDBC data source to query these Redshift system tables rather than using
spark-redshift.