/** * Gets the InputJobInfo object by reading the Configuration and deserializing * the string. If InputJobInfo is not present in the configuration, throws an * exception since that means HCatInputFormat.setInput has not been called. * @param conf the Configuration object * @return the InputJobInfo object * @throws IOException the exception */ private static InputJobInfo getJobInfo(Configuration conf) throws IOException { InputJobInfo inputJobInfo = HCatUtil.getLastInputJobInfosFromConf(conf); if (inputJobInfo == null) { throw new IOException("job information not found in JobContext." + " HCatInputFormat.setInput() not called?"); } return inputJobInfo; }
/** * Return partitioning columns for this input, can only be called after setInput is called, * since that takes care of adding a populated InputJobInfo object to its list in this job conf. * @return partitioning columns of the table specified by the job. * @throws IOException */ public static HCatSchema getPartitionColumns(Configuration conf) throws IOException { InputJobInfo inputInfo = HCatUtil.getLastInputJobInfosFromConf(conf); Preconditions.checkNotNull(inputInfo, "inputJobInfo is null, setInput has not yet been called to save job into conf supplied."); return inputInfo.getTableInfo().getPartitionColumns(); }
/** * Return data columns for this input, can only be called after setInput is called, * since that takes care of adding a populated InputJobInfo object to its list in this job conf. * @return data columns of the table specified by the job. * @throws IOException */ public static HCatSchema getDataColumns(Configuration conf) throws IOException { InputJobInfo inputInfo = HCatUtil.getLastInputJobInfosFromConf(conf); Preconditions.checkNotNull(inputInfo, "inputJobInfo is null, setInput has not yet been called to save job into conf supplied."); return inputInfo.getTableInfo().getDataColumns(); } }
HCatInputFormat.setInput(job, dbName, tableName, getPartitionFilterString()); InputJobInfo inputJobInfo = HCatUtil.getLastInputJobInfosFromConf(job.getConfiguration());
HCatUtil.getLastInputJobInfosFromConf(taskContext.getConfiguration()).getTableInfo());
@Test public void testInputJobInfoInConf() throws Exception { Configuration conf = new Configuration(false); InputJobInfo inputJobInfo = HCatUtil.getLastInputJobInfosFromConf(conf); Assert.assertNull(inputJobInfo); List<InputJobInfo> inputJobInfos = HCatUtil.getInputJobInfosFromConf(conf); Assert.assertNull(inputJobInfos); InputJobInfo inputJobInfo0 = InputJobInfo.create("db", "table", "", new Properties()); InputJobInfo inputJobInfo1 = InputJobInfo.create("db", "table2", "", new Properties()); HCatUtil.putInputJobInfoToConf(inputJobInfo0, conf); HCatUtil.putInputJobInfoToConf(inputJobInfo1, conf); inputJobInfo = HCatUtil.getLastInputJobInfosFromConf(conf); inputJobInfos = HCatUtil.getInputJobInfosFromConf(conf); Assert.assertEquals(inputJobInfo1.getDatabaseName(), inputJobInfo.getDatabaseName()); Assert.assertEquals(inputJobInfo1.getTableName(), inputJobInfo.getTableName()); Assert.assertEquals(inputJobInfo0.getDatabaseName(), inputJobInfos.get(0).getDatabaseName()); Assert.assertEquals(inputJobInfo0.getTableName(), inputJobInfos.get(0).getTableName()); } }