diff --git itests/hive-unit/src/test/java/org/apache/hadoop/hive/metastore/TestHiveMetaStore.java itests/hive-unit/src/test/java/org/apache/hadoop/hive/metastore/TestHiveMetaStore.java index 6efb334..6f9e9c7 100644 --- itests/hive-unit/src/test/java/org/apache/hadoop/hive/metastore/TestHiveMetaStore.java +++ itests/hive-unit/src/test/java/org/apache/hadoop/hive/metastore/TestHiveMetaStore.java @@ -273,6 +273,24 @@ public static void partitionTester(HiveMetaStoreClient client, HiveConf hiveConf } assertTrue("Partitions are not same", part.equals(part_get)); + // check null cols schemas for a partition + List vals6 = makeVals("2016-02-22 00:00:00", "16"); + Partition part6 = makePartitionObject(dbName, tblName, vals6, tbl, "/part5"); + part6.getSd().setCols(null); + LOG.info("Creating partition will null field schema"); + client.add_partition(part6); + LOG.info("Listing all partitions for table " + dbName + "." + tblName); + final List partitions = client.listPartitions(dbName, tblName, (short) -1); + boolean foundPart = false; + for (Partition p : partitions) { + if (p.getValues().equals(vals6)) { + assertNull(p.getSd().getCols()); + LOG.info("Found partition " + p + " having null field schema"); + foundPart = true; + } + } + assertTrue(foundPart); + String partName = "ds=" + FileUtils.escapePathName("2008-07-01 14:13:12") + "/hr=14"; String part2Name = "ds=" + FileUtils.escapePathName("2008-07-01 14:13:12") + "/hr=15"; String part3Name = "ds=" + FileUtils.escapePathName("2008-07-02 14:13:12") + "/hr=15"; @@ -306,7 +324,7 @@ public static void partitionTester(HiveMetaStoreClient client, HiveConf hiveConf partialVals.clear(); partialVals.add(""); partialNames = client.listPartitionNames(dbName, tblName, partialVals, (short) -1); - assertTrue("Should have returned 4 partition names", partialNames.size() == 4); + assertTrue("Should have returned 5 partition names", partialNames.size() == 5); assertTrue("Not all part names returned", partialNames.containsAll(partNames)); // Test partition listing with a partial spec - hr is specified but ds is not diff --git metastore/src/java/org/apache/hadoop/hive/metastore/MetaStoreDirectSql.java metastore/src/java/org/apache/hadoop/hive/metastore/MetaStoreDirectSql.java index 071a4c4..eb0fec2 100644 --- metastore/src/java/org/apache/hadoop/hive/metastore/MetaStoreDirectSql.java +++ metastore/src/java/org/apache/hadoop/hive/metastore/MetaStoreDirectSql.java @@ -531,14 +531,14 @@ private boolean isViewTable(String dbName, String tblName) throws MetaException Long sdId = extractSqlLong(fields[1]); Long colId = extractSqlLong(fields[2]); Long serdeId = extractSqlLong(fields[3]); - // A partition must have either everything set, or nothing set if it's a view. - if (sdId == null || colId == null || serdeId == null) { + // A partition must have at least sdId and serdeId set, or nothing set if it's a view. + if (sdId == null || serdeId == null) { if (isView == null) { isView = isViewTable(dbName, tblName); } if ((sdId != null || colId != null || serdeId != null) || !isView) { - throw new MetaException("Unexpected null for one of the IDs, SD " + sdId + ", column " - + colId + ", serde " + serdeId + " for a " + (isView ? "" : "non-") + " view"); + throw new MetaException("Unexpected null for one of the IDs, SD " + sdId + + ", serde " + serdeId + " for a " + (isView ? "" : "non-") + " view"); } } @@ -554,7 +554,7 @@ private boolean isViewTable(String dbName, String tblName) throws MetaException partitions.put(partitionId, part); if (sdId == null) continue; // Probably a view. - assert colId != null && serdeId != null; + assert serdeId != null; // We assume each partition has an unique SD. StorageDescriptor sd = new StorageDescriptor(); @@ -579,14 +579,16 @@ private boolean isViewTable(String dbName, String tblName) throws MetaException sdSb.append(sdId).append(","); part.setSd(sd); - List cols = colss.get(colId); - // We expect that colId will be the same for all (or many) SDs. - if (cols == null) { - cols = new ArrayList(); - colss.put(colId, cols); - colsSb.append(colId).append(","); + if (colId != null) { + List cols = colss.get(colId); + // We expect that colId will be the same for all (or many) SDs. + if (cols == null) { + cols = new ArrayList(); + colss.put(colId, cols); + colsSb.append(colId).append(","); + } + sd.setCols(cols); } - sd.setCols(cols); // We assume each SD has an unique serde. SerDeInfo serde = new SerDeInfo(); @@ -628,8 +630,10 @@ public void apply(Partition t, Object[] fields) { assert serdeSb.length() == 0 && colsSb.length() == 0; return orderedResult; // No SDs, probably a view. } - String sdIds = trimCommaList(sdSb), serdeIds = trimCommaList(serdeSb), - colIds = trimCommaList(colsSb); + + String sdIds = trimCommaList(sdSb); + String serdeIds = trimCommaList(serdeSb); + String colIds = trimCommaList(colsSb); // Get all the stuff for SD. Don't do empty-list check - we expect partitions do have SDs. queryText = "select \"SD_ID\", \"PARAM_KEY\", \"PARAM_VALUE\" from \"SD_PARAMS\""