@@ -52,23 +52,24 @@ class InMemoryCatalogedDDLSuite extends DDLSuite with SharedSQLContext with Befo
52
52
protected override def generateTable (
53
53
catalog : SessionCatalog ,
54
54
name : TableIdentifier ,
55
- isDataSource : Boolean = true ): CatalogTable = {
55
+ isDataSource : Boolean = true ,
56
+ partitionCols : Seq [String ] = Seq (" a" , " b" )): CatalogTable = {
56
57
val storage =
57
58
CatalogStorageFormat .empty.copy(locationUri = Some (catalog.defaultTablePath(name)))
58
59
val metadata = new MetadataBuilder ()
59
60
.putString(" key" , " value" )
60
61
.build()
62
+ val schema = new StructType ()
63
+ .add(" col1" , " int" , nullable = true , metadata = metadata)
64
+ .add(" col2" , " string" )
61
65
CatalogTable (
62
66
identifier = name,
63
67
tableType = CatalogTableType .EXTERNAL ,
64
68
storage = storage,
65
- schema = new StructType ()
66
- .add(" col1" , " int" , nullable = true , metadata = metadata)
67
- .add(" col2" , " string" )
68
- .add(" a" , " int" )
69
- .add(" b" , " int" ),
69
+ schema = schema.copy(
70
+ fields = schema.fields ++ partitionCols.map(StructField (_, IntegerType ))),
70
71
provider = Some (" parquet" ),
71
- partitionColumnNames = Seq ( " a " , " b " ) ,
72
+ partitionColumnNames = partitionCols ,
72
73
createTime = 0L ,
73
74
createVersion = org.apache.spark.SPARK_VERSION ,
74
75
tracksPartitionsInCatalog = true )
@@ -176,7 +177,8 @@ abstract class DDLSuite extends QueryTest with SQLTestUtils {
176
177
protected def generateTable (
177
178
catalog : SessionCatalog ,
178
179
name : TableIdentifier ,
179
- isDataSource : Boolean = true ): CatalogTable
180
+ isDataSource : Boolean = true ,
181
+ partitionCols : Seq [String ] = Seq (" a" , " b" )): CatalogTable
180
182
181
183
private val escapedIdentifier = " `(.+)`" .r
182
184
@@ -228,8 +230,10 @@ abstract class DDLSuite extends QueryTest with SQLTestUtils {
228
230
private def createTable (
229
231
catalog : SessionCatalog ,
230
232
name : TableIdentifier ,
231
- isDataSource : Boolean = true ): Unit = {
232
- catalog.createTable(generateTable(catalog, name, isDataSource), ignoreIfExists = false )
233
+ isDataSource : Boolean = true ,
234
+ partitionCols : Seq [String ] = Seq (" a" , " b" )): Unit = {
235
+ catalog.createTable(
236
+ generateTable(catalog, name, isDataSource, partitionCols), ignoreIfExists = false )
233
237
}
234
238
235
239
private def createTablePartition (
@@ -1131,7 +1135,7 @@ abstract class DDLSuite extends QueryTest with SQLTestUtils {
1131
1135
}
1132
1136
1133
1137
test(" alter table: recover partition (parallel)" ) {
1134
- withSQLConf(" spark.rdd.parallelListingThreshold" -> " 1 " ) {
1138
+ withSQLConf(" spark.rdd.parallelListingThreshold" -> " 0 " ) {
1135
1139
testRecoverPartitions()
1136
1140
}
1137
1141
}
@@ -1144,23 +1148,32 @@ abstract class DDLSuite extends QueryTest with SQLTestUtils {
1144
1148
}
1145
1149
1146
1150
val tableIdent = TableIdentifier (" tab1" )
1147
- createTable(catalog, tableIdent)
1148
- val part1 = Map (" a" -> " 1" , " b" -> " 5" )
1151
+ createTable(catalog, tableIdent, partitionCols = Seq ( " a " , " b " , " c " ) )
1152
+ val part1 = Map (" a" -> " 1" , " b" -> " 5" , " c " -> " 19 " )
1149
1153
createTablePartition(catalog, part1, tableIdent)
1150
1154
assert(catalog.listPartitions(tableIdent).map(_.spec).toSet == Set (part1))
1151
1155
1152
- val part2 = Map (" a" -> " 2" , " b" -> " 6" )
1156
+ val part2 = Map (" a" -> " 2" , " b" -> " 6" , " c " -> " 31 " )
1153
1157
val root = new Path (catalog.getTableMetadata(tableIdent).location)
1154
1158
val fs = root.getFileSystem(spark.sessionState.newHadoopConf())
1155
1159
// valid
1156
- fs.mkdirs(new Path (new Path (root, " a=1" ), " b=5" ))
1157
- fs.createNewFile(new Path (new Path (root, " a=1/b=5" ), " a.csv" )) // file
1158
- fs.createNewFile(new Path (new Path (root, " a=1/b=5" ), " _SUCCESS" )) // file
1159
- fs.mkdirs(new Path (new Path (root, " A=2" ), " B=6" ))
1160
- fs.createNewFile(new Path (new Path (root, " A=2/B=6" ), " b.csv" )) // file
1161
- fs.createNewFile(new Path (new Path (root, " A=2/B=6" ), " c.csv" )) // file
1162
- fs.createNewFile(new Path (new Path (root, " A=2/B=6" ), " .hiddenFile" )) // file
1163
- fs.mkdirs(new Path (new Path (root, " A=2/B=6" ), " _temporary" ))
1160
+ fs.mkdirs(new Path (new Path (new Path (root, " a=1" ), " b=5" ), " c=19" ))
1161
+ fs.createNewFile(new Path (new Path (root, " a=1/b=5/c=19" ), " a.csv" )) // file
1162
+ fs.createNewFile(new Path (new Path (root, " a=1/b=5/c=19" ), " _SUCCESS" )) // file
1163
+
1164
+ fs.mkdirs(new Path (new Path (new Path (root, " A=2" ), " B=6" ), " C=31" ))
1165
+ fs.createNewFile(new Path (new Path (root, " A=2/B=6/C=31" ), " b.csv" )) // file
1166
+ fs.createNewFile(new Path (new Path (root, " A=2/B=6/C=31" ), " c.csv" )) // file
1167
+ fs.createNewFile(new Path (new Path (root, " A=2/B=6/C=31" ), " .hiddenFile" )) // file
1168
+ fs.mkdirs(new Path (new Path (root, " A=2/B=6/C=31" ), " _temporary" ))
1169
+
1170
+ val parts = (10 to 100 ).map { a =>
1171
+ val part = Map (" a" -> a.toString, " b" -> " 5" , " c" -> " 42" )
1172
+ fs.mkdirs(new Path (new Path (new Path (root, s " a= $a" ), " b=5" ), " c=42" ))
1173
+ fs.createNewFile(new Path (new Path (root, s " a= $a/b=5/c=42 " ), " a.csv" )) // file
1174
+ createTablePartition(catalog, part, tableIdent)
1175
+ part
1176
+ }
1164
1177
1165
1178
// invalid
1166
1179
fs.mkdirs(new Path (new Path (root, " a" ), " b" )) // bad name
@@ -1174,7 +1187,7 @@ abstract class DDLSuite extends QueryTest with SQLTestUtils {
1174
1187
try {
1175
1188
sql(" ALTER TABLE tab1 RECOVER PARTITIONS" )
1176
1189
assert(catalog.listPartitions(tableIdent).map(_.spec).toSet ==
1177
- Set (part1, part2))
1190
+ Set (part1, part2) ++ parts )
1178
1191
if (! isUsingHiveMetastore) {
1179
1192
assert(catalog.getPartition(tableIdent, part1).parameters(" numFiles" ) == " 1" )
1180
1193
assert(catalog.getPartition(tableIdent, part2).parameters(" numFiles" ) == " 2" )
0 commit comments