Index: hbase-handler/src/java/org/apache/hadoop/hive/hbase/HBaseSerDe.java =================================================================== --- hbase-handler/src/java/org/apache/hadoop/hive/hbase/HBaseSerDe.java (revision 1360713) +++ hbase-handler/src/java/org/apache/hadoop/hive/hbase/HBaseSerDe.java (working copy) @@ -133,6 +133,26 @@ } /** + * Construct the default hbase.columns.mapping if it's not specified by the user + * @param columnsNameSpec column names separated by "," + * @return the default mapping, with :key being the first column and column family cf + */ + public static String constructDefaultColumnsMapping(String columnsNameSpec) { + String[] colNames = columnsNameSpec.split(","); + StringBuilder sb = new StringBuilder(); + for(int i = 0; i < colNames.length; i++) { + if (i == 0) { + sb.append(":key"); + } else { + sb.append(",cf:"); + sb.append(colNames[i]); + } + } + LOG.info("hbase.columns.mapping not specified, using default mapping [" + sb.toString() + "]"); + return sb.toString(); + } + + /** * Parses the HBase columns mapping specifier to identify the column families, qualifiers * and also caches the byte arrays corresponding to them. One of the Hive table * columns maps to the HBase row key, by default the first column. @@ -144,9 +164,8 @@ public static List parseColumnsMapping(String columnsMappingSpec) throws SerDeException { - if (columnsMappingSpec == null) { - throw new SerDeException("Error: hbase.columns.mapping missing for this HBase table."); - } + //should have handled null before calling this function + assert columnsMappingSpec != null; if (columnsMappingSpec.equals("") || columnsMappingSpec.equals(HBASE_KEY_COL)) { throw new SerDeException("Error: hbase.columns.mapping specifies only the HBase table" @@ -420,6 +439,10 @@ putTimestamp = Long.valueOf(tbl.getProperty(HBaseSerDe.HBASE_PUT_TIMESTAMP,"-1")); // Parse and initialize the HBase columns mapping + if (hbaseColumnsMapping == null) { + hbaseColumnsMapping = constructDefaultColumnsMapping(tbl.getProperty(Constants.LIST_COLUMNS)); + } + columnsMapping = parseColumnsMapping(hbaseColumnsMapping); // Build the type property string if not supplied Index: hbase-handler/src/java/org/apache/hadoop/hive/hbase/HBaseStorageHandler.java =================================================================== --- hbase-handler/src/java/org/apache/hadoop/hive/hbase/HBaseStorageHandler.java (revision 1360713) +++ hbase-handler/src/java/org/apache/hadoop/hive/hbase/HBaseStorageHandler.java (working copy) @@ -138,8 +138,13 @@ String tableName = getHBaseTableName(tbl); Map serdeParam = tbl.getSd().getSerdeInfo().getParameters(); String hbaseColumnsMapping = serdeParam.get(HBaseSerDe.HBASE_COLUMNS_MAPPING); + + if (hbaseColumnsMapping == null) { + String columnName = MetaStoreUtils.getColumnNamesFromFieldSchema(tbl.getSd().getCols()); + hbaseColumnsMapping = HBaseSerDe.constructDefaultColumnsMapping(columnName); + } + List columnsMapping = null; - columnsMapping = HBaseSerDe.parseColumnsMapping(hbaseColumnsMapping); HTableDescriptor tableDesc; @@ -268,15 +273,21 @@ configureTableJobProperties(tableDesc, jobProperties); } + @Override public void configureTableJobProperties( TableDesc tableDesc, Map jobProperties) { Properties tableProperties = tableDesc.getProperties(); - jobProperties.put( - HBaseSerDe.HBASE_COLUMNS_MAPPING, - tableProperties.getProperty(HBaseSerDe.HBASE_COLUMNS_MAPPING)); + String hbaseColumnsMapping = + tableProperties.getProperty(HBaseSerDe.HBASE_COLUMNS_MAPPING); + if (hbaseColumnsMapping == null) { + String columnName = tableProperties.getProperty(Constants.META_TABLE_COLUMNS); + hbaseColumnsMapping = HBaseSerDe.constructDefaultColumnsMapping(columnName); + } + jobProperties.put(HBaseSerDe.HBASE_COLUMNS_MAPPING, hbaseColumnsMapping); + jobProperties.put(HBaseSerDe.HBASE_TABLE_DEFAULT_STORAGE_TYPE, tableProperties.getProperty(HBaseSerDe.HBASE_TABLE_DEFAULT_STORAGE_TYPE,"string")); Index: hbase-handler/src/java/org/apache/hadoop/hive/hbase/HiveHBaseTableInputFormat.java =================================================================== --- hbase-handler/src/java/org/apache/hadoop/hive/hbase/HiveHBaseTableInputFormat.java (revision 1360713) +++ hbase-handler/src/java/org/apache/hadoop/hive/hbase/HiveHBaseTableInputFormat.java (working copy) @@ -94,6 +94,10 @@ List readColIDs = ColumnProjectionUtils.getReadColumnIDs(jobConf); List columnsMapping = null; + if (hbaseColumnsMapping == null){ + hbaseColumnsMapping = HBaseSerDe.constructDefaultColumnsMapping(jobConf.get(Constants.LIST_COLUMNS)); + } + try { columnsMapping = HBaseSerDe.parseColumnsMapping(hbaseColumnsMapping); } catch (SerDeException e) { @@ -423,10 +427,11 @@ String hbaseColumnsMapping = jobConf.get(HBaseSerDe.HBASE_COLUMNS_MAPPING); if (hbaseColumnsMapping == null) { - throw new IOException("hbase.columns.mapping required for HBase Table."); + hbaseColumnsMapping = HBaseSerDe.constructDefaultColumnsMapping(jobConf.get(Constants.LIST_COLUMNS)); } List columnsMapping = null; + try { columnsMapping = HBaseSerDe.parseColumnsMapping(hbaseColumnsMapping); } catch (SerDeException e) {