Skip to content

Commit fd4a1c6

Browse files
guluo2016Apache9
authored andcommitted
HBASE-27848:Should fast-fail if unmatched column family exists when using ImportTsv (apache#5225)
Signed-off-by: Duo Zhang <[email protected]> (cherry picked from commit ce29f97)
1 parent 364cb37 commit fd4a1c6

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

hbase-mapreduce/src/main/java/org/apache/hadoop/hbase/mapreduce/ImportTsv.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
import org.apache.hadoop.hbase.client.Table;
4646
import org.apache.hadoop.hbase.client.TableDescriptor;
4747
import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
48+
import org.apache.hadoop.hbase.regionserver.NoSuchColumnFamilyException;
4849
import org.apache.hadoop.hbase.util.Bytes;
4950
import org.apache.hadoop.hbase.util.Pair;
5051
import org.apache.hadoop.io.Text;
@@ -553,6 +554,22 @@ protected static Job createSubmittableJob(Configuration conf, String[] args)
553554
LOG.error(errorMsg);
554555
throw new TableNotFoundException(errorMsg);
555556
}
557+
try (Table table = connection.getTable(tableName)) {
558+
ArrayList<String> unmatchedFamilies = new ArrayList<>();
559+
Set<String> cfSet = getColumnFamilies(columns);
560+
TableDescriptor tDesc = table.getDescriptor();
561+
for (String cf : cfSet) {
562+
if (!tDesc.hasColumnFamily(Bytes.toBytes(cf))) {
563+
unmatchedFamilies.add(cf);
564+
}
565+
}
566+
if (unmatchedFamilies.size() > 0) {
567+
String noSuchColumnFamiliesMsg =
568+
format("Column families: %s do not exist.", unmatchedFamilies);
569+
LOG.error(noSuchColumnFamiliesMsg);
570+
throw new NoSuchColumnFamilyException(noSuchColumnFamiliesMsg);
571+
}
572+
}
556573
if (mapperClass.equals(TsvImporterTextMapper.class)) {
557574
usage(TsvImporterTextMapper.class.toString()
558575
+ " should not be used for non bulkloading case. use "

hbase-mapreduce/src/test/java/org/apache/hadoop/hbase/mapreduce/TestImportTsv.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
import org.apache.hadoop.hbase.io.hfile.CacheConfig;
5252
import org.apache.hadoop.hbase.io.hfile.HFile;
5353
import org.apache.hadoop.hbase.io.hfile.HFileScanner;
54+
import org.apache.hadoop.hbase.regionserver.NoSuchColumnFamilyException;
5455
import org.apache.hadoop.hbase.testclassification.LargeTests;
5556
import org.apache.hadoop.hbase.testclassification.VerySlowMapReduceTests;
5657
import org.apache.hadoop.hbase.util.Bytes;
@@ -241,6 +242,27 @@ public int run(String[] args) throws Exception {
241242
}, args));
242243
}
243244

245+
@Test
246+
public void testMRNoMatchedColumnFamily() throws Exception {
247+
util.createTable(tn, FAMILY);
248+
249+
String[] args = new String[] {
250+
"-D" + ImportTsv.COLUMNS_CONF_KEY
251+
+ "=HBASE_ROW_KEY,FAM:A,FAM01_ERROR:A,FAM01_ERROR:B,FAM02_ERROR:C",
252+
tn.getNameAsString(), "/inputFile" };
253+
exception.expect(NoSuchColumnFamilyException.class);
254+
assertEquals("running test job configuration failed.", 0,
255+
ToolRunner.run(new Configuration(util.getConfiguration()), new ImportTsv() {
256+
@Override
257+
public int run(String[] args) throws Exception {
258+
createSubmittableJob(getConf(), args);
259+
return 0;
260+
}
261+
}, args));
262+
263+
util.deleteTable(tn);
264+
}
265+
244266
@Test
245267
public void testMRWithoutAnExistingTable() throws Exception {
246268
String[] args = new String[] { tn.getNameAsString(), "/inputFile" };

0 commit comments

Comments
 (0)