Skip to content

Commit 9194fe1

Browse files
committed
Fixes test failures
- Shows partition columns for EXTENDED and FORMATTED - Shows "Compressed:" field - Shows data types in lower case
1 parent 718da25 commit 9194fe1

File tree

10 files changed

+30
-11
lines changed

10 files changed

+30
-11
lines changed

sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/catalog/interface.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ case class CatalogStorageFormat(
4848
inputFormat: Option[String],
4949
outputFormat: Option[String],
5050
serde: Option[String],
51+
compressed: Boolean,
5152
serdeProperties: Map[String, String])
5253

5354

@@ -124,10 +125,11 @@ case class CatalogTable(
124125
locationUri: Option[String] = storage.locationUri,
125126
inputFormat: Option[String] = storage.inputFormat,
126127
outputFormat: Option[String] = storage.outputFormat,
128+
compressed: Boolean = false,
127129
serde: Option[String] = storage.serde,
128130
serdeProperties: Map[String, String] = storage.serdeProperties): CatalogTable = {
129131
copy(storage = CatalogStorageFormat(
130-
locationUri, inputFormat, outputFormat, serde, serdeProperties))
132+
locationUri, inputFormat, outputFormat, serde, compressed, serdeProperties))
131133
}
132134

133135
}

sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/catalog/ExternalCatalogSuite.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,7 @@ abstract class CatalogTestUtils {
507507
inputFormat = Some(tableInputFormat),
508508
outputFormat = Some(tableOutputFormat),
509509
serde = None,
510+
compressed = false,
510511
serdeProperties = Map.empty)
511512
lazy val part1 = CatalogTablePartition(Map("a" -> "1", "b" -> "2"), storageFormat)
512513
lazy val part2 = CatalogTablePartition(Map("a" -> "3", "b" -> "4"), storageFormat)

sql/core/src/main/scala/org/apache/spark/sql/execution/SparkSqlParser.scala

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -870,6 +870,7 @@ class SparkSqlAstBuilder(conf: SQLConf) extends AstBuilder {
870870
// Note: Keep this unspecified because we use the presence of the serde to decide
871871
// whether to convert a table created by CTAS to a datasource table.
872872
serde = None,
873+
compressed = false,
873874
serdeProperties = Map())
874875
}
875876
val fileStorage = Option(ctx.createFileFormat).map(visitCreateFileFormat)
@@ -881,6 +882,7 @@ class SparkSqlAstBuilder(conf: SQLConf) extends AstBuilder {
881882
inputFormat = fileStorage.inputFormat.orElse(defaultStorage.inputFormat),
882883
outputFormat = fileStorage.outputFormat.orElse(defaultStorage.outputFormat),
883884
serde = rowStorage.serde.orElse(fileStorage.serde).orElse(defaultStorage.serde),
885+
compressed = false,
884886
serdeProperties = rowStorage.serdeProperties ++ fileStorage.serdeProperties)
885887

886888
// TODO support the sql text - have a proper location for this!
@@ -934,7 +936,7 @@ class SparkSqlAstBuilder(conf: SQLConf) extends AstBuilder {
934936
}
935937

936938
/** Empty storage format for default values and copies. */
937-
private val EmptyStorageFormat = CatalogStorageFormat(None, None, None, None, Map.empty)
939+
private val EmptyStorageFormat = CatalogStorageFormat(None, None, None, None, false, Map.empty)
938940

939941
/**
940942
* Create a [[CatalogStorageFormat]].
@@ -1015,7 +1017,7 @@ class SparkSqlAstBuilder(conf: SQLConf) extends AstBuilder {
10151017
entry("field.delim", ctx.fieldsTerminatedBy) ++
10161018
entry("serialization.format", ctx.fieldsTerminatedBy) ++
10171019
entry("escape.delim", ctx.escapedBy) ++
1018-
entry("colelction.delim", ctx.collectionItemsTerminatedBy) ++
1020+
entry("collection.delim", ctx.collectionItemsTerminatedBy) ++
10191021
entry("mapkey.delim", ctx.keysTerminatedBy) ++
10201022
Option(ctx.linesSeparatedBy).toSeq.map { token =>
10211023
val value = string(token)
@@ -1154,7 +1156,7 @@ class SparkSqlAstBuilder(conf: SQLConf) extends AstBuilder {
11541156

11551157
case c: RowFormatSerdeContext =>
11561158
// Use a serde format.
1157-
val CatalogStorageFormat(None, None, None, Some(name), props) = visitRowFormatSerde(c)
1159+
val CatalogStorageFormat(None, None, None, Some(name), _, props) = visitRowFormatSerde(c)
11581160

11591161
// SPARK-10310: Special cases LazySimpleSerDe
11601162
val recordHandler = if (name == "org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe") {

sql/core/src/main/scala/org/apache/spark/sql/execution/command/createDataSourceTables.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,7 @@ object CreateDataSourceTableUtils extends Logging {
349349
inputFormat = None,
350350
outputFormat = None,
351351
serde = None,
352+
compressed = false,
352353
serdeProperties = options
353354
),
354355
properties = tableProperties.toMap)
@@ -368,6 +369,7 @@ object CreateDataSourceTableUtils extends Logging {
368369
inputFormat = serde.inputFormat,
369370
outputFormat = serde.outputFormat,
370371
serde = serde.serde,
372+
compressed = false,
371373
serdeProperties = options
372374
),
373375
schema = relation.schema.map { f =>

sql/core/src/main/scala/org/apache/spark/sql/execution/command/tables.scala

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,7 @@ case class DescribeTableCommand(table: TableIdentifier, isExtended: Boolean, isF
306306
result
307307
}
308308

309+
// Shows data columns and partitioned columns (if any)
309310
private def describe(relation: CatalogRelation, buffer: ArrayBuffer[Row]): Unit = {
310311
describeSchema(relation.catalogTable.schema, buffer)
311312

@@ -318,14 +319,16 @@ case class DescribeTableCommand(table: TableIdentifier, isExtended: Boolean, isF
318319
}
319320

320321
private def describeExtended(relation: CatalogRelation, buffer: ArrayBuffer[Row]): Unit = {
321-
describeSchema(relation.catalogTable.schema, buffer)
322+
describe(relation, buffer)
323+
322324
buffer += Row("", "", "")
323325
buffer += Row("# Detailed Table Information", relation.catalogTable.toString, "")
324326
}
325327

326328
private def describeFormatted(relation: CatalogRelation, buffer: ArrayBuffer[Row]): Unit = {
329+
describe(relation, buffer)
330+
327331
val table = relation.catalogTable
328-
describeSchema(table.schema, buffer)
329332

330333
buffer += Row("", "", "")
331334
buffer += Row("# Detailed Table Information", "", "")
@@ -346,6 +349,7 @@ case class DescribeTableCommand(table: TableIdentifier, isExtended: Boolean, isF
346349
table.storage.serde.foreach(serdeLib => buffer += Row("SerDe Library:", serdeLib, ""))
347350
table.storage.inputFormat.foreach(format => buffer += Row("InputFormat:", format, ""))
348351
table.storage.outputFormat.foreach(format => buffer += Row("OutputFormat:", format, ""))
352+
buffer += Row("Compressed:", if (table.storage.compressed) "Yes" else "No", "")
349353
buffer += Row("Num Buckets:", table.numBuckets.toString, "")
350354
buffer += Row("Bucket Columns:", table.bucketColumnNames.mkString("[", ", ", "]"), "")
351355
buffer += Row("Sort Columns:", table.sortColumnNames.mkString("[", ", ", "]"), "")
@@ -360,13 +364,13 @@ case class DescribeTableCommand(table: TableIdentifier, isExtended: Boolean, isF
360364
schema.foreach { column =>
361365
val comment =
362366
if (column.metadata.contains("comment")) column.metadata.getString("comment") else ""
363-
buffer += Row(column.name, column.dataType.sql, comment)
367+
buffer += Row(column.name, column.dataType.sql.toLowerCase, comment)
364368
}
365369
}
366370

367371
private def describeSchema(schema: Seq[CatalogColumn], buffer: ArrayBuffer[Row]): Unit = {
368372
schema.foreach { column =>
369-
buffer += Row(column.name, column.dataType, column.comment.getOrElse(""))
373+
buffer += Row(column.name, column.dataType.toLowerCase, column.comment.orNull)
370374
}
371375
}
372376
}

sql/core/src/test/scala/org/apache/spark/sql/execution/command/DDLSuite.scala

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ class DDLSuite extends QueryTest with SharedSQLContext with BeforeAndAfterEach {
7676
inputFormat = None,
7777
outputFormat = None,
7878
serde = None,
79+
compressed = false,
7980
serdeProperties = Map())
8081
catalog.createTable(CatalogTable(
8182
identifier = name,
@@ -89,7 +90,8 @@ class DDLSuite extends QueryTest with SharedSQLContext with BeforeAndAfterEach {
8990
catalog: SessionCatalog,
9091
spec: TablePartitionSpec,
9192
tableName: TableIdentifier): Unit = {
92-
val part = CatalogTablePartition(spec, CatalogStorageFormat(None, None, None, None, Map()))
93+
val part = CatalogTablePartition(
94+
spec, CatalogStorageFormat(None, None, None, None, false, Map()))
9395
catalog.createPartitions(tableName, Seq(part), ignoreIfExists = false)
9496
}
9597

@@ -264,6 +266,7 @@ class DDLSuite extends QueryTest with SharedSQLContext with BeforeAndAfterEach {
264266
inputFormat = None,
265267
outputFormat = None,
266268
serde = None,
269+
compressed = false,
267270
serdeProperties = Map())
268271
val expectedTable =
269272
CatalogTable(
@@ -288,6 +291,7 @@ class DDLSuite extends QueryTest with SharedSQLContext with BeforeAndAfterEach {
288291
inputFormat = None,
289292
outputFormat = None,
290293
serde = None,
294+
compressed = false,
291295
serdeProperties = Map())
292296
val expectedTable =
293297
CatalogTable(

sql/hive/src/main/scala/org/apache/spark/sql/hive/client/HiveClientImpl.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,7 @@ private[hive] class HiveClientImpl(
356356
inputFormat = Option(h.getInputFormatClass).map(_.getName),
357357
outputFormat = Option(h.getOutputFormatClass).map(_.getName),
358358
serde = Option(h.getSerializationLib),
359+
compressed = h.getTTable.getSd.isCompressed,
359360
serdeProperties = h.getTTable.getSd.getSerdeInfo.getParameters.asScala.toMap
360361
),
361362
properties = h.getParameters.asScala.toMap,
@@ -785,7 +786,7 @@ private[hive] class HiveClientImpl(
785786
inputFormat = Option(apiPartition.getSd.getInputFormat),
786787
outputFormat = Option(apiPartition.getSd.getOutputFormat),
787788
serde = Option(apiPartition.getSd.getSerdeInfo.getSerializationLib),
789+
compressed = apiPartition.getSd.isCompressed,
788790
serdeProperties = apiPartition.getSd.getSerdeInfo.getParameters.asScala.toMap))
789791
}
790-
791792
}

sql/hive/src/main/scala/org/apache/spark/sql/hive/execution/CreateTableAsSelect.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ case class CreateTableAsSelect(
5656
outputFormat =
5757
tableDesc.storage.outputFormat
5858
.orElse(Some(classOf[HiveIgnoreKeyTextOutputFormat[Text, Text]].getName)),
59-
serde = tableDesc.storage.serde.orElse(Some(classOf[LazySimpleSerDe].getName)))
59+
serde = tableDesc.storage.serde.orElse(Some(classOf[LazySimpleSerDe].getName)),
60+
compressed = tableDesc.storage.compressed)
6061

6162
val withSchema = if (withFormat.schema.isEmpty) {
6263
// Hive doesn't support specifying the column list for target table in CTAS

sql/hive/src/test/scala/org/apache/spark/sql/hive/MetastoreDataSourcesSuite.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -732,6 +732,7 @@ class MetastoreDataSourcesSuite extends QueryTest with SQLTestUtils with TestHiv
732732
inputFormat = None,
733733
outputFormat = None,
734734
serde = None,
735+
compressed = false,
735736
serdeProperties = Map(
736737
"path" -> sessionState.catalog.hiveDefaultTableFilePath(TableIdentifier(tableName)))
737738
),

sql/hive/src/test/scala/org/apache/spark/sql/hive/client/VersionsSuite.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ class VersionsSuite extends SparkFunSuite with Logging {
157157
outputFormat = Some(
158158
classOf[org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat[_, _]].getName),
159159
serde = Some(classOf[org.apache.hadoop.hive.serde2.`lazy`.LazySimpleSerDe].getName()),
160+
compressed = false,
160161
serdeProperties = Map.empty
161162
))
162163

0 commit comments

Comments
 (0)