@Override
  public boolean isVersionCompatible(String hiveVersion, String dbVersion) {
    hiveVersion = getEquivalentVersion(hiveVersion);
    dbVersion = getEquivalentVersion(dbVersion);
    if (hiveVersion.equals(dbVersion)) {
      return true;
    }
    String[] hiveVerParts = hiveVersion.split("\\.");
    String[] dbVerParts = dbVersion.split("\\.");
    if (hiveVerParts.length != 3 || dbVerParts.length != 3) {
      // these are non standard version numbers. can't perform the
      // comparison on these, so assume that they are incompatible
      return false;
    }

    hiveVerParts = hiveVersion.split("\\.|-");
    dbVerParts = dbVersion.split("\\.|-");
    for (int i = 0; i < Math.min(hiveVerParts.length, dbVerParts.length); i++) {
      int compare = compareVersion(dbVerParts[i], hiveVerParts[i]);
      if (compare != 0) {
        return compare > 0;
      }
    }
    return hiveVerParts.length > dbVerParts.length;
  }
@Test
  public void testIsVersionCompatible() throws Exception {
    // first argument is hiveVersion, it is compatible if 2nd argument - dbVersion is
    // greater than or equal to it
    // check the compatible case
    IMetaStoreSchemaInfo metastoreSchemaInfo =
        MetaStoreSchemaInfoFactory.get(MetastoreConf.newMetastoreConf());
    Assert.assertTrue(metastoreSchemaInfo.isVersionCompatible("0.0.1", "0.0.1"));
    Assert.assertTrue(metastoreSchemaInfo.isVersionCompatible("0.0.1", "0.0.2"));
    Assert.assertTrue(metastoreSchemaInfo.isVersionCompatible("1.0.2", "2.0.1"));
    Assert.assertTrue(metastoreSchemaInfo.isVersionCompatible("0.0.9", "9.0.0"));

    Assert.assertTrue(metastoreSchemaInfo.isVersionCompatible("4.0.0-alpha-1", "4.0.0-alpha-2"));
    Assert.assertTrue(metastoreSchemaInfo.isVersionCompatible("4.0.0-alpha-1", "4.0.0-alpha"));
    Assert.assertTrue(metastoreSchemaInfo.isVersionCompatible("4.0.0-alpha-1", "4.0.0"));
    Assert.assertTrue(metastoreSchemaInfo.isVersionCompatible("4.0.0-alpha-1", "4.0.1"));
    Assert.assertTrue(metastoreSchemaInfo.isVersionCompatible("4.0.0-alpha-1", "4.0.0-beta"));

    // check equivalent versions, should be compatible
    Assert.assertTrue(metastoreSchemaInfo.isVersionCompatible("0.13.0", "0.13.1"));
    Assert.assertTrue(metastoreSchemaInfo.isVersionCompatible("0.13.1", "0.13.0"));

    // check incompatible versions
    Assert.assertFalse(metastoreSchemaInfo.isVersionCompatible("0.1.1", "0.1.0"));
    Assert.assertFalse(metastoreSchemaInfo.isVersionCompatible("4.0.1", "0.1.0"));
    Assert.assertFalse(metastoreSchemaInfo.isVersionCompatible("4.0.1", "4.0.0-alpha-1"));
    Assert.assertFalse(metastoreSchemaInfo.isVersionCompatible("4.0.0", "4.0.0-alpha-1"));
    Assert.assertFalse(metastoreSchemaInfo.isVersionCompatible("4.0.0-alpha-2", "4.0.0-alpha-1"));
    Assert.assertFalse(metastoreSchemaInfo.isVersionCompatible("4.0.0-alpha", "4.0.0-alpha-1"));
    Assert.assertFalse(metastoreSchemaInfo.isVersionCompatible("4.0.0-beta", "4.0.0-alpha-1"));
  }