Search in sources :

Example 51 with PartitionBuilder

use of org.apache.hadoop.hive.metastore.client.builder.PartitionBuilder in project hive by apache.

the class TestMetaStoreServerUtils method testCompareWithSdSamePrefixDifferentCols.

/**
 * Two StorageDescriptorKey objects with the same base location
 * should be equal iff their columns are equal
 */
@Test
public void testCompareWithSdSamePrefixDifferentCols() throws MetaException {
    Partition p1 = new PartitionBuilder().setDbName("DB_NAME").setTableName(TABLE_NAME).setLocation("l1").addCol("a", "int").addValue("val1").build(null);
    Partition p2 = new PartitionBuilder().setDbName("DB_NAME").setTableName(TABLE_NAME).setLocation("l2").addCol("b", "int").addValue("val1").build(null);
    Partition p3 = new PartitionBuilder().setDbName("DB_NAME").setTableName(TABLE_NAME).setLocation("l2").addCol("a", "int").addValue("val1").build(null);
    assertThat(new MetaStoreServerUtils.StorageDescriptorKey("a", p1.getSd()), IsNot.not(new MetaStoreServerUtils.StorageDescriptorKey("a", p2.getSd())));
    assertThat(new MetaStoreServerUtils.StorageDescriptorKey("a", p1.getSd()), is(new MetaStoreServerUtils.StorageDescriptorKey("a", p3.getSd())));
}
Also used : Partition(org.apache.hadoop.hive.metastore.api.Partition) PartitionBuilder(org.apache.hadoop.hive.metastore.client.builder.PartitionBuilder) MetastoreUnitTest(org.apache.hadoop.hive.metastore.annotation.MetastoreUnitTest) Test(org.junit.Test)

Example 52 with PartitionBuilder

use of org.apache.hadoop.hive.metastore.client.builder.PartitionBuilder in project hive by apache.

the class TestMetaStoreServerUtils method testCompareWithSdSamePrefixDifferentLocation.

/**
 * Two StorageDescriptorKey objects with the same base location but different
 * SD location should be equal
 */
@Test
public void testCompareWithSdSamePrefixDifferentLocation() throws MetaException {
    Partition p1 = new PartitionBuilder().setDbName("DB_NAME").setTableName(TABLE_NAME).setLocation("l1").addCol("a", "int").addValue("val1").build(null);
    Partition p2 = new PartitionBuilder().setDbName("DB_NAME").setTableName(TABLE_NAME).setLocation("l2").addCol("a", "int").addValue("val1").build(null);
    assertThat(new MetaStoreServerUtils.StorageDescriptorKey("a", p1.getSd()), is(new MetaStoreServerUtils.StorageDescriptorKey("a", p2.getSd())));
}
Also used : Partition(org.apache.hadoop.hive.metastore.api.Partition) PartitionBuilder(org.apache.hadoop.hive.metastore.client.builder.PartitionBuilder) MetastoreUnitTest(org.apache.hadoop.hive.metastore.annotation.MetastoreUnitTest) Test(org.junit.Test)

Example 53 with PartitionBuilder

use of org.apache.hadoop.hive.metastore.client.builder.PartitionBuilder in project hive by apache.

the class TestMetaStoreServerUtils method testCompareWithSdSamePrefixDifferentInputFormat.

/**
 * Two StorageDescriptorKey objects with the same base location
 * should be equal iff their input formats are equal
 */
@Test
public void testCompareWithSdSamePrefixDifferentInputFormat() throws MetaException {
    Partition p1 = new PartitionBuilder().setDbName("DB_NAME").setTableName(TABLE_NAME).setLocation("l1").addCol("a", "int").addValue("val1").setInputFormat("foo").build(null);
    Partition p2 = new PartitionBuilder().setDbName("DB_NAME").setTableName(TABLE_NAME).setLocation("l2").addCol("a", "int").setInputFormat("bar").addValue("val1").build(null);
    Partition p3 = new PartitionBuilder().setDbName("DB_NAME").setTableName(TABLE_NAME).setLocation("l1").addCol("a", "int").addValue("val1").setInputFormat("foo").build(null);
    assertThat(new MetaStoreServerUtils.StorageDescriptorKey("a", p1.getSd()), IsNot.not(new MetaStoreServerUtils.StorageDescriptorKey("a", p2.getSd())));
    assertThat(new MetaStoreServerUtils.StorageDescriptorKey("a", p1.getSd()), is(new MetaStoreServerUtils.StorageDescriptorKey("a", p3.getSd())));
}
Also used : Partition(org.apache.hadoop.hive.metastore.api.Partition) PartitionBuilder(org.apache.hadoop.hive.metastore.client.builder.PartitionBuilder) MetastoreUnitTest(org.apache.hadoop.hive.metastore.annotation.MetastoreUnitTest) Test(org.junit.Test)

Example 54 with PartitionBuilder

use of org.apache.hadoop.hive.metastore.client.builder.PartitionBuilder in project hive by apache.

the class TestMetaStoreServerUtils method testGetPartitionspecsGroupedBySDOnePartitionInTable.

/**
 * Test getPartitionspecsGroupedByStorageDescriptor() for partitions with a single
 * partition which is located under table location.
 */
@Test
public void testGetPartitionspecsGroupedBySDOnePartitionInTable() throws MetaException {
    // Create database and table
    Table tbl = new TableBuilder().setDbName(DB_NAME).setTableName(TABLE_NAME).addCol("id", "int").setLocation("/foo").build(null);
    Partition p1 = new PartitionBuilder().setDbName("DB_NAME").setTableName(TABLE_NAME).setLocation("/foo/bar").addCol("a", "int").addValue("val1").setInputFormat("foo").build(null);
    List<PartitionSpec> result = MetaStoreServerUtils.getPartitionspecsGroupedByStorageDescriptor(tbl, Collections.singleton(p1));
    assertThat(result.size(), is(1));
    PartitionSpec ps = result.get(0);
    assertThat(ps.getRootPath(), is(tbl.getSd().getLocation()));
    List<PartitionWithoutSD> partitions = ps.getSharedSDPartitionSpec().getPartitions();
    assertThat(partitions.size(), is(1));
    PartitionWithoutSD partition = partitions.get(0);
    assertThat(partition.getRelativePath(), is("/bar"));
    assertThat(partition.getValues(), is(Collections.singletonList("val1")));
}
Also used : Partition(org.apache.hadoop.hive.metastore.api.Partition) Table(org.apache.hadoop.hive.metastore.api.Table) PartitionBuilder(org.apache.hadoop.hive.metastore.client.builder.PartitionBuilder) PartitionWithoutSD(org.apache.hadoop.hive.metastore.api.PartitionWithoutSD) TableBuilder(org.apache.hadoop.hive.metastore.client.builder.TableBuilder) PartitionSpec(org.apache.hadoop.hive.metastore.api.PartitionSpec) MetastoreUnitTest(org.apache.hadoop.hive.metastore.annotation.MetastoreUnitTest) Test(org.junit.Test)

Example 55 with PartitionBuilder

use of org.apache.hadoop.hive.metastore.client.builder.PartitionBuilder in project hive by apache.

the class TestMetaStoreServerUtils method testGetPartitionspecsGroupedBySDNullSD.

/**
 * Test getPartitionspecsGroupedByStorageDescriptor() for partitions with null SDs.
 */
@Test
public void testGetPartitionspecsGroupedBySDNullSD() throws MetaException {
    // Create database and table
    Table tbl = new TableBuilder().setDbName(DB_NAME).setTableName(TABLE_NAME).addCol("id", "int").setLocation("/foo").build(null);
    Partition p1 = new PartitionBuilder().setDbName("DB_NAME").setTableName(TABLE_NAME).addCol("a", "int").addValue("val1").setInputFormat("foo").build(null);
    // Set SD to null
    p1.unsetSd();
    assertThat(p1.getSd(), is((StorageDescriptor) null));
    List<PartitionSpec> result = MetaStoreServerUtils.getPartitionspecsGroupedByStorageDescriptor(tbl, Collections.singleton(p1));
    assertThat(result.size(), is(1));
    PartitionSpec ps = result.get(0);
    assertThat(ps.getRootPath(), is((String) null));
    List<PartitionWithoutSD> partitions = ps.getSharedSDPartitionSpec().getPartitions();
    assertThat(partitions.size(), is(1));
    PartitionWithoutSD partition = partitions.get(0);
    assertThat(partition.getRelativePath(), is((String) null));
    assertThat(partition.getValues(), is(Collections.singletonList("val1")));
}
Also used : Partition(org.apache.hadoop.hive.metastore.api.Partition) Table(org.apache.hadoop.hive.metastore.api.Table) PartitionBuilder(org.apache.hadoop.hive.metastore.client.builder.PartitionBuilder) PartitionWithoutSD(org.apache.hadoop.hive.metastore.api.PartitionWithoutSD) StorageDescriptor(org.apache.hadoop.hive.metastore.api.StorageDescriptor) TableBuilder(org.apache.hadoop.hive.metastore.client.builder.TableBuilder) PartitionSpec(org.apache.hadoop.hive.metastore.api.PartitionSpec) MetastoreUnitTest(org.apache.hadoop.hive.metastore.annotation.MetastoreUnitTest) Test(org.junit.Test)

Aggregations

PartitionBuilder (org.apache.hadoop.hive.metastore.client.builder.PartitionBuilder)75 Partition (org.apache.hadoop.hive.metastore.api.Partition)63 Test (org.junit.Test)47 Table (org.apache.hadoop.hive.metastore.api.Table)44 TableBuilder (org.apache.hadoop.hive.metastore.client.builder.TableBuilder)33 MetastoreCheckinTest (org.apache.hadoop.hive.metastore.annotation.MetastoreCheckinTest)28 DatabaseBuilder (org.apache.hadoop.hive.metastore.client.builder.DatabaseBuilder)27 Database (org.apache.hadoop.hive.metastore.api.Database)22 ArrayList (java.util.ArrayList)14 MetastoreUnitTest (org.apache.hadoop.hive.metastore.annotation.MetastoreUnitTest)10 CatalogBuilder (org.apache.hadoop.hive.metastore.client.builder.CatalogBuilder)10 EnvironmentContext (org.apache.hadoop.hive.metastore.api.EnvironmentContext)9 SQLCheckConstraint (org.apache.hadoop.hive.metastore.api.SQLCheckConstraint)7 SQLDefaultConstraint (org.apache.hadoop.hive.metastore.api.SQLDefaultConstraint)7 SQLNotNullConstraint (org.apache.hadoop.hive.metastore.api.SQLNotNullConstraint)7 SQLUniqueConstraint (org.apache.hadoop.hive.metastore.api.SQLUniqueConstraint)7 Catalog (org.apache.hadoop.hive.metastore.api.Catalog)6 HashMap (java.util.HashMap)5 FieldSchema (org.apache.hadoop.hive.metastore.api.FieldSchema)5 HashSet (java.util.HashSet)4