-
Notifications
You must be signed in to change notification settings - Fork 99
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
95 additions
and
4 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
69 changes: 69 additions & 0 deletions
69
src/it/scala/net/snowflake/spark/snowflake/OnErrorSuite.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,69 @@ | ||
package net.snowflake.spark.snowflake | ||
|
||
import net.snowflake.client.jdbc.SnowflakeSQLException | ||
import net.snowflake.spark.snowflake.Utils.SNOWFLAKE_SOURCE_NAME | ||
import org.apache.spark.sql.{Row, SaveMode} | ||
import org.apache.spark.sql.types.{StringType, StructField, StructType} | ||
|
||
class OnErrorSuite extends IntegrationSuiteBase{ | ||
lazy val table = "test_table"//s"spark_test_table_$randomSuffix" | ||
|
||
lazy val schema = new StructType( | ||
Array( | ||
StructField("var", StringType, nullable = false) | ||
) | ||
) | ||
|
||
|
||
lazy val df = sqlContext.createDataFrame( | ||
sc.parallelize( | ||
Seq( | ||
Row("{\"dsadas\nadsa\":12311}"), | ||
Row("{\"abc\":334}") | ||
) //invalid json key | ||
), | ||
schema | ||
) | ||
|
||
override def beforeAll(): Unit = { | ||
super.beforeAll() | ||
jdbcUpdate(s"create or replace table $table(var variant)") | ||
} | ||
|
||
override def afterAll(): Unit = { | ||
//jdbcUpdate(s"drop table $table") | ||
super.afterAll() | ||
} | ||
|
||
test("continue_on_error off") { | ||
|
||
assertThrows[SnowflakeSQLException]{ | ||
df.write | ||
.format(SNOWFLAKE_SOURCE_NAME) | ||
.options(connectorOptionsNoTable) | ||
.option("dbtable", table) | ||
.mode(SaveMode.Append) | ||
.save() | ||
} | ||
} | ||
|
||
test("continue_on_error on") { | ||
df.write | ||
.format(SNOWFLAKE_SOURCE_NAME) | ||
.options(connectorOptionsNoTable) | ||
.option("continue_on_error", "on") | ||
.option("dbtable", table) | ||
.mode(SaveMode.Append) | ||
.save() | ||
|
||
val result = sqlContext.read | ||
.format(SNOWFLAKE_SOURCE_NAME) | ||
.options(connectorOptionsNoTable) | ||
.option("dbtable", table) | ||
.load() | ||
|
||
assert(result.collect().length == 1) | ||
} | ||
|
||
|
||
} |
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