@@ -24,62 +24,62 @@ import org.apache.spark.sql.types._
2424
2525class JdbcUtilsSuite extends SparkFunSuite {
2626
27- val schema = StructType (Seq (
27+ val tableSchema = StructType (Seq (
2828 StructField (" C1" , StringType , false ), StructField (" C2" , IntegerType , false )))
2929 val caseSensitive = org.apache.spark.sql.catalyst.analysis.caseSensitiveResolution
3030 val caseInsensitive = org.apache.spark.sql.catalyst.analysis.caseInsensitiveResolution
3131
3232 test(" Parse user specified column types" ) {
3333 assert(
34- JdbcUtils .parseUserSpecifiedColumnTypes(schema , " C1 DATE, C2 STRING" , caseInsensitive) ===
34+ JdbcUtils .getCustomSchema(tableSchema , " C1 DATE, C2 STRING" , caseInsensitive) ===
3535 StructType (Seq (StructField (" C1" , DateType , true ), StructField (" C2" , StringType , true ))))
36- assert(JdbcUtils .parseUserSpecifiedColumnTypes(schema , " C1 DATE, C2 STRING" , caseSensitive) ===
36+ assert(JdbcUtils .getCustomSchema(tableSchema , " C1 DATE, C2 STRING" , caseSensitive) ===
3737 StructType (Seq (StructField (" C1" , DateType , true ), StructField (" C2" , StringType , true ))))
3838 assert(
39- JdbcUtils .parseUserSpecifiedColumnTypes(schema , " c1 DATE, C2 STRING" , caseInsensitive) ===
39+ JdbcUtils .getCustomSchema(tableSchema , " c1 DATE, C2 STRING" , caseInsensitive) ===
4040 StructType (Seq (StructField (" c1" , DateType , true ), StructField (" C2" , StringType , true ))))
41- assert(JdbcUtils .parseUserSpecifiedColumnTypes (
42- schema , " c1 DECIMAL(38, 0), C2 STRING" , caseInsensitive) ===
41+ assert(JdbcUtils .getCustomSchema (
42+ tableSchema , " c1 DECIMAL(38, 0), C2 STRING" , caseInsensitive) ===
4343 StructType (Seq (StructField (" c1" , DecimalType (38 , 0 ), true ),
4444 StructField (" C2" , StringType , true ))))
4545
4646 // Throw AnalysisException
4747 val duplicate = intercept[AnalysisException ]{
48- JdbcUtils .parseUserSpecifiedColumnTypes(schema , " c1 DATE, c1 STRING" , caseInsensitive) ===
48+ JdbcUtils .getCustomSchema(tableSchema , " c1 DATE, c1 STRING" , caseInsensitive) ===
4949 StructType (Seq (StructField (" c1" , DateType , true ), StructField (" c1" , StringType , true )))
5050 }
5151 assert(duplicate.getMessage.contains(
5252 " Found duplicate column(s) in the customSchema option value" ))
5353
5454 val allColumns = intercept[AnalysisException ]{
55- JdbcUtils .parseUserSpecifiedColumnTypes(schema , " C1 STRING" , caseSensitive) ===
55+ JdbcUtils .getCustomSchema(tableSchema , " C1 STRING" , caseSensitive) ===
5656 StructType (Seq (StructField (" C1" , DateType , true )))
5757 }
5858 assert(allColumns.getMessage.contains(" Please provide all the columns," ))
5959
6060 val caseSensitiveColumnNotFound = intercept[AnalysisException ]{
61- JdbcUtils .parseUserSpecifiedColumnTypes(schema , " c1 DATE, C2 STRING" , caseSensitive) ===
61+ JdbcUtils .getCustomSchema(tableSchema , " c1 DATE, C2 STRING" , caseSensitive) ===
6262 StructType (Seq (StructField (" c1" , DateType , true ), StructField (" C2" , StringType , true )))
6363 }
6464 assert(caseSensitiveColumnNotFound.getMessage.contains(
65- s " ${ JDBCOptions . JDBC_CUSTOM_DATAFRAME_COLUMN_TYPES } option column c1 not found in schema " ))
65+ " Please provide all the columns, all columns are: C1,C2; " ))
6666
6767 val caseInsensitiveColumnNotFound = intercept[AnalysisException ]{
68- JdbcUtils .parseUserSpecifiedColumnTypes(schema , " c3 DATE, C2 STRING" , caseInsensitive) ===
68+ JdbcUtils .getCustomSchema(tableSchema , " c3 DATE, C2 STRING" , caseInsensitive) ===
6969 StructType (Seq (StructField (" c3" , DateType , true ), StructField (" C2" , StringType , true )))
7070 }
7171 assert(caseInsensitiveColumnNotFound.getMessage.contains(
72- s " ${ JDBCOptions . JDBC_CUSTOM_DATAFRAME_COLUMN_TYPES } option column c3 not found in schema " ))
72+ " Please provide all the columns, all columns are: C1,C2; " ))
7373
7474 // Throw ParseException
7575 val dataTypeNotSupported = intercept[ParseException ]{
76- JdbcUtils .parseUserSpecifiedColumnTypes(schema , " c3 DATEE, C2 STRING" , caseInsensitive) ===
76+ JdbcUtils .getCustomSchema(tableSchema , " c3 DATEE, C2 STRING" , caseInsensitive) ===
7777 StructType (Seq (StructField (" c3" , DateType , true ), StructField (" C2" , StringType , true )))
7878 }
7979 assert(dataTypeNotSupported.getMessage.contains(" DataType datee is not supported" ))
8080
8181 val mismatchedInput = intercept[ParseException ]{
82- JdbcUtils .parseUserSpecifiedColumnTypes(schema , " c3 DATE. C2 STRING" , caseInsensitive) ===
82+ JdbcUtils .getCustomSchema(tableSchema , " c3 DATE. C2 STRING" , caseInsensitive) ===
8383 StructType (Seq (StructField (" c3" , DateType , true ), StructField (" C2" , StringType , true )))
8484 }
8585 assert(mismatchedInput.getMessage.contains(" mismatched input '.' expecting" ))
0 commit comments