예제 #1
0
  /** Tests partition operations */
  @Test
  public void testPartitionOps()
      throws MetaException, InvalidObjectException, NoSuchObjectException, InvalidInputException {
    Database db1 = new Database(DB1, "description", "locationurl", null);
    objectStore.createDatabase(db1);
    StorageDescriptor sd =
        new StorageDescriptor(
            null,
            "location",
            null,
            null,
            false,
            0,
            new SerDeInfo("SerDeName", "serializationLib", null),
            null,
            null,
            null);
    HashMap<String, String> tableParams = new HashMap<String, String>();
    tableParams.put("EXTERNAL", "false");
    FieldSchema partitionKey1 = new FieldSchema("Country", "String", "");
    FieldSchema partitionKey2 = new FieldSchema("State", "String", "");
    Table tbl1 =
        new Table(
            TABLE1,
            DB1,
            "owner",
            1,
            2,
            3,
            sd,
            Arrays.asList(partitionKey1, partitionKey2),
            tableParams,
            "viewOriginalText",
            "viewExpandedText",
            "MANAGED_TABLE");
    objectStore.createTable(tbl1);
    HashMap<String, String> partitionParams = new HashMap<String, String>();
    partitionParams.put("PARTITION_LEVEL_PRIVILEGE", "true");
    List<String> value1 = Arrays.asList("US", "CA");
    Partition part1 = new Partition(value1, DB1, TABLE1, 111, 111, sd, partitionParams);
    objectStore.addPartition(part1);
    List<String> value2 = Arrays.asList("US", "MA");
    Partition part2 = new Partition(value2, DB1, TABLE1, 222, 222, sd, partitionParams);
    objectStore.addPartition(part2);

    Deadline.startTimer("getPartition");
    List<Partition> partitions = objectStore.getPartitions(DB1, TABLE1, 10);
    Assert.assertEquals(2, partitions.size());
    Assert.assertEquals(111, partitions.get(0).getCreateTime());
    Assert.assertEquals(222, partitions.get(1).getCreateTime());

    objectStore.dropPartition(DB1, TABLE1, value1);
    partitions = objectStore.getPartitions(DB1, TABLE1, 10);
    Assert.assertEquals(1, partitions.size());
    Assert.assertEquals(222, partitions.get(0).getCreateTime());

    objectStore.dropPartition(DB1, TABLE1, value2);
    objectStore.dropTable(DB1, TABLE1);
    objectStore.dropDatabase(DB1);
  }
예제 #2
0
  /** Test table operations */
  @Test
  public void testTableOps()
      throws MetaException, InvalidObjectException, NoSuchObjectException, InvalidInputException {
    Database db1 = new Database(DB1, "description", "locationurl", null);
    objectStore.createDatabase(db1);
    StorageDescriptor sd =
        new StorageDescriptor(
            null,
            "location",
            null,
            null,
            false,
            0,
            new SerDeInfo("SerDeName", "serializationLib", null),
            null,
            null,
            null);
    HashMap<String, String> params = new HashMap<String, String>();
    params.put("EXTERNAL", "false");
    Table tbl1 =
        new Table(
            TABLE1,
            DB1,
            "owner",
            1,
            2,
            3,
            sd,
            null,
            params,
            "viewOriginalText",
            "viewExpandedText",
            "MANAGED_TABLE");
    objectStore.createTable(tbl1);

    List<String> tables = objectStore.getAllTables(DB1);
    Assert.assertEquals(1, tables.size());
    Assert.assertEquals(TABLE1, tables.get(0));

    Table newTbl1 =
        new Table(
            "new" + TABLE1,
            DB1,
            "owner",
            1,
            2,
            3,
            sd,
            null,
            params,
            "viewOriginalText",
            "viewExpandedText",
            "MANAGED_TABLE");
    objectStore.alterTable(DB1, TABLE1, newTbl1);
    tables = objectStore.getTables(DB1, "new*");
    Assert.assertEquals(1, tables.size());
    Assert.assertEquals("new" + TABLE1, tables.get(0));

    objectStore.dropTable(DB1, "new" + TABLE1);
    tables = objectStore.getAllTables(DB1);
    Assert.assertEquals(0, tables.size());

    objectStore.dropDatabase(DB1);
  }
 @Override
 public void createTable(Table tbl) throws InvalidObjectException, MetaException {
   objectStore.createTable(tbl);
 }