dongjoon-hyun commented on a change in pull request #24099: [SPARK-27168][TEST] Add docker integration test for MsSql server URL: https://github.com/apache/spark/pull/24099#discussion_r266532165
########## File path: external/docker-integration-tests/src/test/scala/org/apache/spark/sql/jdbc/MsSqlServerIntegrationSuite.scala ########## @@ -0,0 +1,173 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + */ + +package org.apache.spark.sql.jdbc + +import java.math.BigDecimal +import java.sql.{Connection, Date, Timestamp} +import java.util.Properties + +import org.apache.spark.tags.DockerTest + +@DockerTest +class MsSqlServerIntegrationSuite extends DockerJDBCIntegrationSuite { + override val db = new DatabaseOnDocker { + override val imageName = "mcr.microsoft.com/mssql/server:2017-GA-ubuntu" + override val env = Map( + "SA_PASSWORD" -> "Sapass123", + "ACCEPT_EULA" -> "Y" + ) + override val usesIpc = false + override val jdbcPort: Int = 1433 + + override def getJdbcUrl(ip: String, port: Int): String = + s"jdbc:sqlserver://$ip:$port;user=sa;password=Sapass123;" + + override def getStartupProcessName: Option[String] = None + } + + override def dataPreparation(conn: Connection): Unit = { + conn.prepareStatement("CREATE TABLE tbl (x INT, y VARCHAR (50))").executeUpdate() + conn.prepareStatement("INSERT INTO tbl VALUES (42,'fred')").executeUpdate() + conn.prepareStatement("INSERT INTO tbl VALUES (17,'dave')").executeUpdate() + + conn.prepareStatement("CREATE TABLE numbers (a BIT, " + + "b DECIMAL(5,2), c NUMERIC(10,5), " + + "d FLOAT, e REAL, " + + "f BIGINT, g INT, h SMALLINT, i TINYINT, " + + "j MONEY, k SMALLMONEY)").executeUpdate() + conn.prepareStatement("INSERT INTO numbers VALUES (0, " + + "123, 12345.12, " + + "123456789012345.123, 123456789012345.123456789012345, " + + "9223372036854775807, 2147483647, 32767, 255, " + + "922337203685477.58, 214748.3647)").executeUpdate() + + conn.prepareStatement("CREATE TABLE dates (a DATE, b DATETIME, c DATETIME2, " + + "d DATETIMEOFFSET, e SMALLDATETIME, f TIME)").executeUpdate() + conn.prepareStatement("INSERT INTO dates VALUES ('1991-11-09', '1999-01-01 13:23:35', " + + "'9999-12-31 23:59:59', '1901-05-09 23:59:59 +14:00', " + + "'1996-01-01 23:23:45', '13:31:24')").executeUpdate() + + conn.prepareStatement("CREATE TABLE strings (a CHAR(10), b VARCHAR(10), c nchar(10), " + + "d nvarchar(10), e binary(4), f varbinary(4), g text, h ntext, i image)").executeUpdate() + conn.prepareStatement("INSERT INTO strings VALUES ('the', 'quick', 'brown', 'fox', 123456," + + " 123456, 'the', 'lazy', 'dog')").executeUpdate() + + } + + test("Basic test") { + val df = sqlContext.read.jdbc(jdbcUrl, "tbl", new Properties) + val rows = df.collect() + assert(rows.length == 2) + val types = rows(0).toSeq.map(x => x.getClass.toString) + assert(types.length == 2) + assert(types(0).equals("class java.lang.Integer")) + assert(types(1).equals("class java.lang.String")) + Review comment: ditto. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org