Exemplo n.º 1
0
  private boolean isClonedTable(String orignalTable, String newTable) throws Exception {
    assertTableExists(newTable);
    TableDesc origTableDesc = client.getTableDesc(orignalTable);
    TableDesc newTableDesc = client.getTableDesc(newTable);

    if (isClonedSchema(origTableDesc.getSchema(), newTableDesc.getSchema()) == false) {
      fail("Schema of input tables do not match");
      return false;
    }

    // Check partition information
    PartitionMethodDesc origPartMethod = origTableDesc.getPartitionMethod();
    PartitionMethodDesc newPartMethod = newTableDesc.getPartitionMethod();
    if (origPartMethod != null) {
      if (newPartMethod == null) {
        fail("New table does not have partition info");
        return false;
      }
      if (isClonedSchema(origPartMethod.getExpressionSchema(), newPartMethod.getExpressionSchema())
          == false) {
        fail("Partition columns of input tables do not match");
        return false;
      }

      if (origPartMethod.getPartitionType().equals(newPartMethod.getPartitionType()) == false) {
        fail("Partition type of input tables do not match");
        return false;
      }
    }

    // Check external flag
    if (origTableDesc.isExternal() != newTableDesc.isExternal()) {
      fail("External table flag on input tables not equal");
      return false;
    }

    if (origTableDesc.getMeta() != null) {
      TableMeta origMeta = origTableDesc.getMeta();
      TableMeta newMeta = newTableDesc.getMeta();
      if (origMeta.getDataFormat().equals(newMeta.getDataFormat()) == false) {
        fail("Store type of input tables not equal");
        return false;
      }

      KeyValueSet origOptions = origMeta.getPropertySet();
      KeyValueSet newOptions = newMeta.getPropertySet();
      if (origOptions.equals(newOptions) == false) {
        fail("Meta options of input tables not equal");
        return false;
      }
    }
    return true;
  }
Exemplo n.º 2
0
  @Test
  public void testColumnKeyValueMapping() throws Exception {
    KeyValueSet keyValueSet = new KeyValueSet();
    keyValueSet.set(HBaseStorageConstants.META_TABLE_KEY, "test");
    keyValueSet.set(HBaseStorageConstants.META_COLUMNS_KEY, ":key,col2:key:,col2:value:#b,col3:");

    Schema schema = new Schema();
    schema.addColumn("c1", Type.TEXT);
    schema.addColumn("c2", Type.TEXT);
    schema.addColumn("c3", Type.TEXT);
    schema.addColumn("c4", Type.TEXT);

    TableMeta tableMeta = new TableMeta("HBASE", keyValueSet);

    ColumnMapping columnMapping = new ColumnMapping(schema, tableMeta.getPropertySet());

    List<String> cfNames = columnMapping.getColumnFamilyNames();
    assertEquals(2, cfNames.size());
    assertEquals("col2", cfNames.get(0));
    assertEquals("col3", cfNames.get(1));

    for (int i = 0; i < columnMapping.getIsBinaryColumns().length; i++) {
      if (i == 2) {
        assertTrue(columnMapping.getIsBinaryColumns()[i]);
      } else {
        assertFalse(columnMapping.getIsBinaryColumns()[i]);
      }
    }

    for (int i = 0; i < columnMapping.getIsRowKeyMappings().length; i++) {
      if (i == 0) {
        assertTrue(columnMapping.getIsRowKeyMappings()[i]);
      } else {
        assertFalse(columnMapping.getIsRowKeyMappings()[i]);
      }
    }

    String[] expectedColumnNames = {null, null, null, null};
    for (int i = 0; i < schema.size(); i++) {
      String columnName =
          columnMapping.getMappingColumns()[i][1] == null
              ? null
              : new String(columnMapping.getMappingColumns()[i][1]);
      assertEquals(expectedColumnNames[i], columnName);
    }

    for (int i = 0; i < schema.size(); i++) {
      if (i == 1) {
        assertTrue(columnMapping.getIsColumnKeys()[i]);
      } else {
        assertFalse(columnMapping.getIsColumnKeys()[i]);
      }
    }

    for (int i = 0; i < schema.size(); i++) {
      if (i == 2) {
        assertTrue(columnMapping.getIsColumnValues()[i]);
      } else {
        assertFalse(columnMapping.getIsColumnValues()[i]);
      }
    }
  }