Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ import java.util.Properties

import org.apache.spark.tags.DockerTest

import org.apache.spark.sql.types._
import org.apache.spark.sql.{DataFrame, Row}

@DockerTest
class MsSqlServerIntegrationSuite extends DockerJDBCIntegrationSuite {
override val db = new DatabaseOnDocker {
Expand Down Expand Up @@ -202,4 +205,32 @@ class MsSqlServerIntegrationSuite extends DockerJDBCIntegrationSuite {
df2.write.jdbc(jdbcUrl, "datescopy", new Properties)
df3.write.jdbc(jdbcUrl, "stringscopy", new Properties)
}

def create_df() : DataFrame = {
val tableSchema = StructType(Seq(
StructField("serialNum",ByteType,true)
))

val tableData = Seq (
Row(10)
)

spark.createDataFrame(spark.sparkContext.parallelize(tableData),tableSchema)
}

test("SPARK-28151 Test write table with BYTETYPE") {
val df1 = create_df()
df1.write
.format("jdbc")
.mode("overwrite")
.option("url",jdbcUrl)
.option("dbtable","testTable")
.save()
val df2 = spark.read
.format("jdbc")
.option("url",jdbcUrl)
.option("dbtable","byteTable")
.load()
df2.show()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,7 @@ object JdbcUtils extends Logging {

case ByteType =>
(stmt: PreparedStatement, row: Row, pos: Int) =>
stmt.setInt(pos + 1, row.getByte(pos))
stmt.setByte(pos + 1, row.getByte(pos))

case BooleanType =>
(stmt: PreparedStatement, row: Row, pos: Int) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ private object MsSqlServerDialect extends JdbcDialect {
sqlType match {
case java.sql.Types.SMALLINT => Some(ShortType)
case java.sql.Types.REAL => Some(FloatType)
case java.sql.Types.TINYINT => Some(ByteType)
case _ => None
}
}
Expand All @@ -44,6 +45,7 @@ private object MsSqlServerDialect extends JdbcDialect {
case BooleanType => Some(JdbcType("BIT", java.sql.Types.BIT))
case BinaryType => Some(JdbcType("VARBINARY(MAX)", java.sql.Types.VARBINARY))
case ShortType => Some(JdbcType("SMALLINT", java.sql.Types.SMALLINT))
case ByteType => Some(JdbcType("TINYINT", java.sql.Types.TINYINT))
case _ => None
}

Expand Down