@SuppressWarnings("unchecked") private static Class<? extends CellComparator> getComparatorClass(String comparatorClassName) throws IOException { Class<? extends CellComparator> comparatorKlass; // for BC if (comparatorClassName.equals(KeyValue.COMPARATOR.getLegacyKeyComparatorName()) || comparatorClassName.equals(KeyValue.COMPARATOR.getClass().getName()) || (comparatorClassName.equals("org.apache.hadoop.hbase.CellComparator"))) { comparatorKlass = CellComparatorImpl.class; } else if (comparatorClassName.equals(KeyValue.META_COMPARATOR.getLegacyKeyComparatorName()) || comparatorClassName.equals(KeyValue.META_COMPARATOR.getClass().getName()) || (comparatorClassName .equals("org.apache.hadoop.hbase.CellComparator$MetaCellComparator"))) { comparatorKlass = MetaCellComparator.class; } else if (comparatorClassName.equals("org.apache.hadoop.hbase.KeyValue$RawBytesComparator") || comparatorClassName.equals("org.apache.hadoop.hbase.util.Bytes$ByteArrayComparator")) { // When the comparator to be used is Bytes.BYTES_RAWCOMPARATOR, we just return null from here // Bytes.BYTES_RAWCOMPARATOR is not a CellComparator comparatorKlass = null; } else { // if the name wasn't one of the legacy names, maybe its a legit new kind of comparator. try { comparatorKlass = (Class<? extends CellComparator>) Class.forName(comparatorClassName); } catch (ClassNotFoundException e) { throw new IOException(e); } } return comparatorKlass; }
@Test public void testCreateComparator() throws IOException { FixedFileTrailer t = new FixedFileTrailer(version, HFileReaderImpl.PBUF_TRAILER_MINOR_VERSION); try { assertEquals(CellComparatorImpl.class, t.createComparator(KeyValue.COMPARATOR.getLegacyKeyComparatorName()).getClass()); assertEquals(CellComparatorImpl.class, t.createComparator(KeyValue.COMPARATOR.getClass().getName()).getClass()); assertEquals(CellComparatorImpl.class, t.createComparator(CellComparator.class.getName()).getClass()); assertEquals(CellComparatorImpl.MetaCellComparator.class, t.createComparator(KeyValue.META_COMPARATOR.getLegacyKeyComparatorName()).getClass()); assertEquals(CellComparatorImpl.MetaCellComparator.class, t.createComparator(KeyValue.META_COMPARATOR.getClass().getName()).getClass()); assertEquals(CellComparatorImpl.MetaCellComparator.class, t.createComparator( CellComparatorImpl.MetaCellComparator.META_COMPARATOR.getClass().getName()).getClass()); assertNull(t.createComparator(Bytes.BYTES_RAWCOMPARATOR.getClass().getName())); assertNull(t.createComparator("org.apache.hadoop.hbase.KeyValue$RawBytesComparator")); } catch (IOException e) { fail("Unexpected exception while testing FixedFileTrailer#createComparator()"); } // Test an invalid comparatorClassName expectedEx.expect(IOException.class); t.createComparator(""); }
@SuppressWarnings("unchecked") private static Class<? extends KVComparator> getComparatorClass( String comparatorClassName) throws IOException { try { // HFile V2 legacy comparator class names. if (comparatorClassName.equals(KeyValue.COMPARATOR.getLegacyKeyComparatorName())) { comparatorClassName = KeyValue.COMPARATOR.getClass().getName(); } else if (comparatorClassName.equals(KeyValue.META_COMPARATOR.getLegacyKeyComparatorName())) { comparatorClassName = KeyValue.META_COMPARATOR.getClass().getName(); } else if (comparatorClassName.equals(KeyValue.RAW_COMPARATOR.getLegacyKeyComparatorName())) { comparatorClassName = KeyValue.RAW_COMPARATOR.getClass().getName(); } // if the name wasn't one of the legacy names, maybe its a legit new kind of comparator. return (Class<? extends KVComparator>) Class.forName(comparatorClassName); } catch (ClassNotFoundException ex) { throw new IOException(ex); } }
@Test public void testCreateComparator() throws IOException { FixedFileTrailer t = new FixedFileTrailer(version, HFileReaderImpl.PBUF_TRAILER_MINOR_VERSION); try { assertEquals(CellComparatorImpl.class, t.createComparator(KeyValue.COMPARATOR.getLegacyKeyComparatorName()).getClass()); assertEquals(CellComparatorImpl.class, t.createComparator(KeyValue.COMPARATOR.getClass().getName()).getClass()); assertEquals(CellComparatorImpl.class, t.createComparator(CellComparator.class.getName()).getClass()); assertEquals(CellComparatorImpl.MetaCellComparator.class, t.createComparator(KeyValue.META_COMPARATOR.getLegacyKeyComparatorName()).getClass()); assertEquals(CellComparatorImpl.MetaCellComparator.class, t.createComparator(KeyValue.META_COMPARATOR.getClass().getName()).getClass()); assertEquals(CellComparatorImpl.MetaCellComparator.class, t.createComparator( CellComparatorImpl.MetaCellComparator.META_COMPARATOR.getClass().getName()).getClass()); assertNull(t.createComparator(Bytes.BYTES_RAWCOMPARATOR.getClass().getName())); assertNull(t.createComparator("org.apache.hadoop.hbase.KeyValue$RawBytesComparator")); } catch (IOException e) { fail("Unexpected exception while testing FixedFileTrailer#createComparator()"); } // Test an invalid comparatorClassName expectedEx.expect(IOException.class); t.createComparator(""); }
public void setComparatorClass(Class<? extends KVComparator> klass) { // Is the comparator instantiable? try { KVComparator comp = klass.newInstance(); // HFile V2 legacy comparator class names. if (KeyValue.COMPARATOR.getClass().equals(klass)) { comparatorClassName = KeyValue.COMPARATOR.getLegacyKeyComparatorName(); } else if (KeyValue.META_COMPARATOR.getClass().equals(klass)) { comparatorClassName = KeyValue.META_COMPARATOR.getLegacyKeyComparatorName(); } else if (KeyValue.RAW_COMPARATOR.getClass().equals(klass)) { comparatorClassName = KeyValue.RAW_COMPARATOR.getLegacyKeyComparatorName(); } else { // if the name wasn't one of the legacy names, maybe its a legit new kind of comparator. comparatorClassName = klass.getName(); } } catch (Exception e) { throw new RuntimeException("Comparator class " + klass.getName() + " is not instantiable", e); } }