Skip to content

Commit 1b6f482

Browse files
yaooqinncloud-fan
authored andcommitted
[SPARK-32492][SQL][FOLLOWUP][TEST-MAVEN] Fix jenkins maven jobs
### What changes were proposed in this pull request? The newly added test fails Jenkins maven jobs, see #29303 (comment) We move the test from `ThriftServerWithSparkContextSuite` to `SparkMetadataOperationSuite`, the former uses an embedded thrift server where the server and the client are in the same JVM process and the latter forks a new process to start the server where the server and client are isolated. The sbt runner seems to be fine with the test in the `ThriftServerWithSparkContextSuite`, but the maven runner with `scalates`t plugin will face the classloader issue as we will switch classloader to the one in the `sharedState` which is not the one that hive uses to load some classes. This is more like an issue that belongs to the maven runner or the `scalatest`. So in this PR, we simply move it to bypass the issue. BTW, we should test against the way of using embedded thrift server to verify whether it is just a maven issue or not, there could be some use cases with this API. ### Why are the changes needed? Jenkins recovery ### Does this PR introduce _any_ user-facing change? no ### How was this patch tested? modified uts Closes #29347 from yaooqinn/SPARK-32492-F. Authored-by: Kent Yao <yaooqinn@hotmail.com> Signed-off-by: Wenchen Fan <wenchen@databricks.com>
1 parent 3a437ed commit 1b6f482

2 files changed

Lines changed: 86 additions & 131 deletions

File tree

sql/hive-thriftserver/src/test/scala/org/apache/spark/sql/hive/thriftserver/SparkMetadataOperationSuite.scala

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ package org.apache.spark.sql.hive.thriftserver
1919

2020
import java.sql.{DatabaseMetaData, ResultSet}
2121

22+
import org.apache.spark.sql.types.{ArrayType, BinaryType, BooleanType, DecimalType, DoubleType, FloatType, IntegerType, MapType, NumericType, StringType, StructType, TimestampType}
23+
2224
class SparkMetadataOperationSuite extends HiveThriftJdbcTest {
2325

2426
override def mode: ServerMode.Value = ServerMode.binary
@@ -247,4 +249,88 @@ class SparkMetadataOperationSuite extends HiveThriftJdbcTest {
247249
checkResult(metaData.getTypeInfo, ThriftserverShimUtils.supportedType().map(_.getName))
248250
}
249251
}
252+
253+
test("check results from get columns operation from thrift server") {
254+
val schemaName = "default"
255+
val tableName = "spark_get_col_operation"
256+
val schema = new StructType()
257+
.add("c0", "boolean", nullable = false, "0")
258+
.add("c1", "tinyint", nullable = true, "1")
259+
.add("c2", "smallint", nullable = false, "2")
260+
.add("c3", "int", nullable = true, "3")
261+
.add("c4", "long", nullable = false, "4")
262+
.add("c5", "float", nullable = true, "5")
263+
.add("c6", "double", nullable = false, "6")
264+
.add("c7", "decimal(38, 20)", nullable = true, "7")
265+
.add("c8", "decimal(10, 2)", nullable = false, "8")
266+
.add("c9", "string", nullable = true, "9")
267+
.add("c10", "array<long>", nullable = false, "10")
268+
.add("c11", "array<string>", nullable = true, "11")
269+
.add("c12", "map<smallint, tinyint>", nullable = false, "12")
270+
.add("c13", "date", nullable = true, "13")
271+
.add("c14", "timestamp", nullable = false, "14")
272+
.add("c15", "struct<X: bigint,Y: double>", nullable = true, "15")
273+
.add("c16", "binary", nullable = false, "16")
274+
275+
val ddl =
276+
s"""
277+
|CREATE TABLE $schemaName.$tableName (
278+
| ${schema.toDDL}
279+
|)
280+
|using parquet""".stripMargin
281+
282+
withJdbcStatement(tableName) { statement =>
283+
statement.execute(ddl)
284+
285+
val databaseMetaData = statement.getConnection.getMetaData
286+
val rowSet = databaseMetaData.getColumns("", schemaName, tableName, null)
287+
288+
import java.sql.Types._
289+
val expectedJavaTypes = Seq(BOOLEAN, TINYINT, SMALLINT, INTEGER, BIGINT, FLOAT, DOUBLE,
290+
DECIMAL, DECIMAL, VARCHAR, ARRAY, ARRAY, JAVA_OBJECT, DATE, TIMESTAMP, STRUCT, BINARY)
291+
292+
var pos = 0
293+
294+
while (rowSet.next()) {
295+
assert(rowSet.getString("TABLE_CAT") === null)
296+
assert(rowSet.getString("TABLE_SCHEM") === schemaName)
297+
assert(rowSet.getString("TABLE_NAME") === tableName)
298+
assert(rowSet.getString("COLUMN_NAME") === schema(pos).name)
299+
assert(rowSet.getInt("DATA_TYPE") === expectedJavaTypes(pos))
300+
assert(rowSet.getString("TYPE_NAME") === schema(pos).dataType.sql)
301+
302+
val colSize = rowSet.getInt("COLUMN_SIZE")
303+
schema(pos).dataType match {
304+
case StringType | BinaryType | _: ArrayType | _: MapType => assert(colSize === 0)
305+
case o => assert(colSize === o.defaultSize)
306+
}
307+
308+
assert(rowSet.getInt("BUFFER_LENGTH") === 0) // not used
309+
val decimalDigits = rowSet.getInt("DECIMAL_DIGITS")
310+
schema(pos).dataType match {
311+
case BooleanType | _: IntegerType => assert(decimalDigits === 0)
312+
case d: DecimalType => assert(decimalDigits === d.scale)
313+
case FloatType => assert(decimalDigits === 7)
314+
case DoubleType => assert(decimalDigits === 15)
315+
case TimestampType => assert(decimalDigits === 6)
316+
case _ => assert(decimalDigits === 0) // nulls
317+
}
318+
319+
val radix = rowSet.getInt("NUM_PREC_RADIX")
320+
schema(pos).dataType match {
321+
case _: NumericType => assert(radix === 10)
322+
case _ => assert(radix === 0) // nulls
323+
}
324+
325+
assert(rowSet.getInt("NULLABLE") === 1)
326+
assert(rowSet.getString("REMARKS") === pos.toString)
327+
assert(rowSet.getInt("ORDINAL_POSITION") === pos)
328+
assert(rowSet.getString("IS_NULLABLE") === "YES")
329+
assert(rowSet.getString("IS_AUTO_INCREMENT") === "NO")
330+
pos += 1
331+
}
332+
333+
assert(pos === 17, "all columns should have been verified")
334+
}
335+
}
250336
}

sql/hive-thriftserver/src/test/scala/org/apache/spark/sql/hive/thriftserver/ThriftServerWithSparkContextSuite.scala

Lines changed: 0 additions & 131 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ package org.apache.spark.sql.hive.thriftserver
1919

2020
import java.sql.SQLException
2121

22-
import scala.collection.JavaConverters._
23-
2422
import org.apache.hive.service.cli.HiveSQLException
2523

2624
import org.apache.spark.sql.hive.HiveUtils
@@ -104,135 +102,6 @@ trait ThriftServerWithSparkContextSuite extends SharedThriftServer {
104102
}
105103
}
106104
}
107-
108-
test("check results from get columns operation from thrift server") {
109-
val schemaName = "default"
110-
val tableName = "spark_get_col_operation"
111-
val schema = new StructType()
112-
.add("c0", "boolean", nullable = false, "0")
113-
.add("c1", "tinyint", nullable = true, "1")
114-
.add("c2", "smallint", nullable = false, "2")
115-
.add("c3", "int", nullable = true, "3")
116-
.add("c4", "long", nullable = false, "4")
117-
.add("c5", "float", nullable = true, "5")
118-
.add("c6", "double", nullable = false, "6")
119-
.add("c7", "decimal(38, 20)", nullable = true, "7")
120-
.add("c8", "decimal(10, 2)", nullable = false, "8")
121-
.add("c9", "string", nullable = true, "9")
122-
.add("c10", "array<long>", nullable = false, "10")
123-
.add("c11", "array<string>", nullable = true, "11")
124-
.add("c12", "map<smallint, tinyint>", nullable = false, "12")
125-
.add("c13", "date", nullable = true, "13")
126-
.add("c14", "timestamp", nullable = false, "14")
127-
.add("c15", "struct<X: bigint,Y: double>", nullable = true, "15")
128-
.add("c16", "binary", nullable = false, "16")
129-
130-
val ddl =
131-
s"""
132-
|CREATE TABLE $schemaName.$tableName (
133-
| ${schema.toDDL}
134-
|)
135-
|using parquet""".stripMargin
136-
137-
withCLIServiceClient { client =>
138-
val sessionHandle = client.openSession(user, "")
139-
val confOverlay = new java.util.HashMap[java.lang.String, java.lang.String]
140-
val opHandle = client.executeStatement(sessionHandle, ddl, confOverlay)
141-
var status = client.getOperationStatus(opHandle)
142-
while (!status.getState.isTerminal) {
143-
Thread.sleep(10)
144-
status = client.getOperationStatus(opHandle)
145-
}
146-
val getCol = client.getColumns(sessionHandle, "", schemaName, tableName, null)
147-
val rowSet = client.fetchResults(getCol)
148-
val columns = rowSet.toTRowSet.getColumns
149-
150-
val catalogs = columns.get(0).getStringVal.getValues.asScala
151-
assert(catalogs.forall(_.isEmpty), "catalog name mismatches")
152-
153-
val schemas = columns.get(1).getStringVal.getValues.asScala
154-
assert(schemas.forall(_ == schemaName), "schema name mismatches")
155-
156-
val tableNames = columns.get(2).getStringVal.getValues.asScala
157-
assert(tableNames.forall(_ == tableName), "table name mismatches")
158-
159-
val columnNames = columns.get(3).getStringVal.getValues.asScala
160-
columnNames.zipWithIndex.foreach {
161-
case (v, i) => assert(v === "c" + i, "column name mismatches")
162-
}
163-
164-
val javaTypes = columns.get(4).getI32Val.getValues
165-
import java.sql.Types._
166-
assert(javaTypes.get(0).intValue() === BOOLEAN)
167-
assert(javaTypes.get(1).intValue() === TINYINT)
168-
assert(javaTypes.get(2).intValue() === SMALLINT)
169-
assert(javaTypes.get(3).intValue() === INTEGER)
170-
assert(javaTypes.get(4).intValue() === BIGINT)
171-
assert(javaTypes.get(5).intValue() === FLOAT)
172-
assert(javaTypes.get(6).intValue() === DOUBLE)
173-
assert(javaTypes.get(7).intValue() === DECIMAL)
174-
assert(javaTypes.get(8).intValue() === DECIMAL)
175-
assert(javaTypes.get(9).intValue() === VARCHAR)
176-
assert(javaTypes.get(10).intValue() === ARRAY)
177-
assert(javaTypes.get(11).intValue() === ARRAY)
178-
assert(javaTypes.get(12).intValue() === JAVA_OBJECT)
179-
assert(javaTypes.get(13).intValue() === DATE)
180-
assert(javaTypes.get(14).intValue() === TIMESTAMP)
181-
assert(javaTypes.get(15).intValue() === STRUCT)
182-
assert(javaTypes.get(16).intValue() === BINARY)
183-
184-
val typeNames = columns.get(5).getStringVal.getValues.asScala
185-
typeNames.zip(schema).foreach { case (tName, f) =>
186-
assert(tName === f.dataType.sql)
187-
}
188-
189-
val colSize = columns.get(6).getI32Val.getValues.asScala
190-
191-
colSize.zip(schema).foreach { case (size, f) =>
192-
f.dataType match {
193-
case StringType | BinaryType | _: ArrayType | _: MapType => assert(size === 0)
194-
case o => assert(size === o.defaultSize)
195-
}
196-
}
197-
198-
val decimalDigits = columns.get(8).getI32Val.getValues.asScala
199-
decimalDigits.zip(schema).foreach { case (dd, f) =>
200-
f.dataType match {
201-
case BooleanType | _: IntegerType => assert(dd === 0)
202-
case d: DecimalType => assert(dd === d.scale)
203-
case FloatType => assert(dd === 7)
204-
case DoubleType => assert(dd === 15)
205-
case TimestampType => assert(dd === 6)
206-
case _ => assert(dd === 0) // nulls
207-
}
208-
}
209-
210-
val radixes = columns.get(9).getI32Val.getValues.asScala
211-
radixes.zip(schema).foreach { case (radix, f) =>
212-
f.dataType match {
213-
case _: NumericType => assert(radix === 10)
214-
case _ => assert(radix === 0) // nulls
215-
}
216-
}
217-
218-
val nullables = columns.get(10).getI32Val.getValues.asScala
219-
assert(nullables.forall(_ === 1))
220-
221-
val comments = columns.get(11).getStringVal.getValues.asScala
222-
comments.zip(schema).foreach { case (c, f) => assert(c === f.getComment().get) }
223-
224-
val positions = columns.get(16).getI32Val.getValues.asScala
225-
positions.zipWithIndex.foreach { case (pos, idx) =>
226-
assert(pos === idx, "the client columns disorder")
227-
}
228-
229-
val isNullables = columns.get(17).getStringVal.getValues.asScala
230-
assert(isNullables.forall(_ === "YES"))
231-
232-
val autoIncs = columns.get(22).getStringVal.getValues.asScala
233-
assert(autoIncs.forall(_ === "NO"))
234-
}
235-
}
236105
}
237106

238107

0 commit comments

Comments
 (0)