Search in sources :

Example 11 with GetPartitionsRequest

use of org.apache.hadoop.hive.metastore.api.GetPartitionsRequest in project hive by apache.

the class TestGetPartitionsUsingProjectionAndFilterSpecs method runWithInvalidFieldNames.

private void runWithInvalidFieldNames(List<String> values) throws TException {
    GetPartitionsRequest request = getGetPartitionsRequest();
    GetProjectionsSpec projectSpec = request.getProjectionSpec();
    projectSpec.setFieldList(values);
    client.getPartitionsWithSpecs(request);
}
Also used : GetProjectionsSpec(org.apache.hadoop.hive.metastore.api.GetProjectionsSpec) GetPartitionsRequest(org.apache.hadoop.hive.metastore.api.GetPartitionsRequest)

Example 12 with GetPartitionsRequest

use of org.apache.hadoop.hive.metastore.api.GetPartitionsRequest in project hive by apache.

the class TestGetPartitionsUsingProjectionAndFilterSpecs method getPartitionsWithVals.

private void getPartitionsWithVals(List<String> filters, int expectedPartitions) throws TException {
    // get partitions from "trusted" API
    List<Partition> partitions = client.listPartitions(dbName, tblName, filters, (short) -1);
    GetPartitionsRequest request = getGetPartitionsRequest();
    GetProjectionsSpec projectSpec = request.getProjectionSpec();
    projectSpec.setFieldList(Arrays.asList("sd.location"));
    request.getFilterSpec().setFilterMode(PartitionFilterMode.BY_VALUES);
    request.getFilterSpec().setFilters(filters);
    GetPartitionsResponse response = client.getPartitionsWithSpecs(request);
    Assert.assertNotNull(response);
    if (expectedPartitions > 0) {
        PartitionSpecWithSharedSD partitionSpecWithSharedSD = response.getPartitionSpec().get(0).getSharedSDPartitionSpec();
        Assert.assertNotNull(partitionSpecWithSharedSD);
        Assert.assertEquals("Invalid number of partitions returned", expectedPartitions, partitionSpecWithSharedSD.getPartitionsSize());
        verifyLocations(partitions, partitionSpecWithSharedSD.getSd(), partitionSpecWithSharedSD.getPartitions());
    } else {
        Assert.assertTrue("Partition spec should have been empty since filter doesn't match with any partitions", response.getPartitionSpec().isEmpty());
    }
}
Also used : GetProjectionsSpec(org.apache.hadoop.hive.metastore.api.GetProjectionsSpec) Partition(org.apache.hadoop.hive.metastore.api.Partition) GetPartitionsResponse(org.apache.hadoop.hive.metastore.api.GetPartitionsResponse) GetPartitionsRequest(org.apache.hadoop.hive.metastore.api.GetPartitionsRequest) PartitionSpecWithSharedSD(org.apache.hadoop.hive.metastore.api.PartitionSpecWithSharedSD)

Example 13 with GetPartitionsRequest

use of org.apache.hadoop.hive.metastore.api.GetPartitionsRequest in project hive by apache.

the class TestGetPartitionsUsingProjectionAndFilterSpecs method testNonStandardPartitions.

@Test
public void testNonStandardPartitions() throws TException {
    String testTblName = "test_non_standard";
    new TableBuilder().setTableName(testTblName).setDbName(dbName).addCol("ns_c1", "string", "comment 1").addCol("ns_c2", "int", "comment 2").addPartCol("part", "string").addPartCol("city", "string").addBucketCol("ns_c1").addSortCol("ns_c2", 1).addTableParam("tblparamKey", "Partitions of this table are not located within table directory").create(client, conf);
    Table table = client.getTable(dbName, testTblName);
    Assert.assertNotNull("Unable to create a test table ", table);
    List<Partition> partitions = new ArrayList<>();
    partitions.add(createPartition(Arrays.asList("p1", "SanFrancisco"), table));
    partitions.add(createPartition(Arrays.asList("p1", "PaloAlto"), table));
    partitions.add(createPartition(Arrays.asList("p2", "Seattle"), table));
    partitions.add(createPartition(Arrays.asList("p2", "Phoenix"), table));
    client.add_partitions(partitions);
    // change locations of two of the partitions outside table directory
    List<Partition> testPartitions = client.listPartitions(dbName, testTblName, (short) -1);
    Assert.assertEquals(4, testPartitions.size());
    Partition p1 = testPartitions.get(2);
    p1.getSd().setLocation("/tmp/some_other_location/part=p2/city=Seattle");
    Partition p2 = testPartitions.get(3);
    p2.getSd().setLocation("/tmp/some_other_location/part=p2/city=Phoenix");
    client.alter_partitions(dbName, testTblName, Arrays.asList(p1, p2));
    GetPartitionsRequest request = getGetPartitionsRequest();
    request.getProjectionSpec().setFieldList(Arrays.asList("values", "sd"));
    request.setDbName(dbName);
    request.setTblName(testTblName);
    GetPartitionsResponse response = client.getPartitionsWithSpecs(request);
    Assert.assertNotNull("Response should have returned partition specs", response.getPartitionSpec());
    Assert.assertEquals("We should have two partition specs", 2, response.getPartitionSpec().size());
    Assert.assertNotNull("One SharedSD spec is expected", response.getPartitionSpec().get(0).getSharedSDPartitionSpec());
    Assert.assertNotNull("One composing spec is expected", response.getPartitionSpec().get(1).getPartitionList());
    PartitionSpecWithSharedSD partitionSpecWithSharedSD = response.getPartitionSpec().get(0).getSharedSDPartitionSpec();
    Assert.assertNotNull("sd was requested but not returned", partitionSpecWithSharedSD.getSd());
    Assert.assertEquals("shared SD should have table location", table.getSd().getLocation(), partitionSpecWithSharedSD.getSd().getLocation());
    List<List<String>> expectedVals = new ArrayList<>(2);
    expectedVals.add(Arrays.asList("p1", "PaloAlto"));
    expectedVals.add(Arrays.asList("p1", "SanFrancisco"));
    for (int i = 0; i < partitionSpecWithSharedSD.getPartitions().size(); i++) {
        PartitionWithoutSD retPartition = partitionSpecWithSharedSD.getPartitions().get(i);
        Assert.assertEquals(2, retPartition.getValuesSize());
        validateList(expectedVals.get(i), retPartition.getValues());
        Assert.assertNull("parameters were not requested so should have been null", retPartition.getParameters());
    }
    PartitionListComposingSpec composingSpec = response.getPartitionSpec().get(1).getPartitionList();
    Assert.assertNotNull("composing spec should have returned 2 partitions", composingSpec.getPartitions());
    Assert.assertEquals("composing spec should have returned 2 partitions", 2, composingSpec.getPartitionsSize());
    expectedVals.clear();
    expectedVals.add(Arrays.asList("p2", "Phoenix"));
    expectedVals.add(Arrays.asList("p2", "Seattle"));
    for (int i = 0; i < composingSpec.getPartitions().size(); i++) {
        Partition partition = composingSpec.getPartitions().get(i);
        Assert.assertEquals(2, partition.getValuesSize());
        validateList(expectedVals.get(i), partition.getValues());
        Assert.assertNull("parameters were not requested so should have been null", partition.getParameters());
    }
}
Also used : Partition(org.apache.hadoop.hive.metastore.api.Partition) Table(org.apache.hadoop.hive.metastore.api.Table) ArrayList(java.util.ArrayList) PartitionListComposingSpec(org.apache.hadoop.hive.metastore.api.PartitionListComposingSpec) GetPartitionsResponse(org.apache.hadoop.hive.metastore.api.GetPartitionsResponse) TableBuilder(org.apache.hadoop.hive.metastore.client.builder.TableBuilder) GetPartitionsRequest(org.apache.hadoop.hive.metastore.api.GetPartitionsRequest) PartitionSpecWithSharedSD(org.apache.hadoop.hive.metastore.api.PartitionSpecWithSharedSD) PartitionWithoutSD(org.apache.hadoop.hive.metastore.api.PartitionWithoutSD) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test) MetastoreCheckinTest(org.apache.hadoop.hive.metastore.annotation.MetastoreCheckinTest)

Example 14 with GetPartitionsRequest

use of org.apache.hadoop.hive.metastore.api.GetPartitionsRequest in project hive by apache.

the class TestGetPartitionsUsingProjectionAndFilterSpecs method getPartitionsWithNames.

private void getPartitionsWithNames(List<String> names, int expectedPartitionCount) throws TException {
    GetPartitionsRequest request = getGetPartitionsRequest();
    GetProjectionsSpec projectSpec = request.getProjectionSpec();
    projectSpec.setFieldList(Arrays.asList("sd.location"));
    request.getFilterSpec().setFilterMode(PartitionFilterMode.BY_NAMES);
    request.getFilterSpec().setFilters(names);
    GetPartitionsResponse response = client.getPartitionsWithSpecs(request);
    Assert.assertNotNull(response);
    if (expectedPartitionCount > 0) {
        PartitionSpecWithSharedSD partitionSpecWithSharedSD = response.getPartitionSpec().get(0).getSharedSDPartitionSpec();
        Assert.assertNotNull(partitionSpecWithSharedSD);
        Assert.assertEquals("Invalid number of partitions returned", expectedPartitionCount, partitionSpecWithSharedSD.getPartitionsSize());
        List<Partition> origPartitions = client.getPartitionsByNames(dbName, tblName, names);
        verifyLocations(origPartitions, partitionSpecWithSharedSD.getSd(), partitionSpecWithSharedSD.getPartitions());
    } else {
        Assert.assertTrue("Partition spec should have been empty since filter doesn't match with any partitions", response.getPartitionSpec().isEmpty());
    }
}
Also used : GetProjectionsSpec(org.apache.hadoop.hive.metastore.api.GetProjectionsSpec) Partition(org.apache.hadoop.hive.metastore.api.Partition) GetPartitionsResponse(org.apache.hadoop.hive.metastore.api.GetPartitionsResponse) GetPartitionsRequest(org.apache.hadoop.hive.metastore.api.GetPartitionsRequest) PartitionSpecWithSharedSD(org.apache.hadoop.hive.metastore.api.PartitionSpecWithSharedSD)

Example 15 with GetPartitionsRequest

use of org.apache.hadoop.hive.metastore.api.GetPartitionsRequest in project hive by apache.

the class TestHiveMetaStore method testGetPartitionsWithSpec.

@Test
public void testGetPartitionsWithSpec() throws Throwable {
    // create a table with multiple partitions
    List<Partition> createdPartitions = setupProjectionTestTable();
    Table tbl = client.getTable("compdb", "comptbl");
    GetPartitionsRequest request = new GetPartitionsRequest();
    GetProjectionsSpec projectSpec = new GetProjectionsSpec();
    projectSpec.setFieldList(Arrays.asList("dbName", "tableName", "catName", "parameters", "lastAccessTime", "sd.location", "values", "createTime", "sd.serdeInfo.serializationLib", "sd.cols"));
    projectSpec.setExcludeParamKeyPattern("exclude%");
    GetPartitionsFilterSpec filter = new GetPartitionsFilterSpec();
    request.setDbName("compdb");
    request.setTblName("comptbl");
    request.setFilterSpec(filter);
    request.setProjectionSpec(projectSpec);
    GetPartitionsResponse response;
    try {
        response = client.getPartitionsWithSpecs(request);
    } catch (Exception ex) {
        ex.printStackTrace();
        LOG.error("Exception while retriveing partitions", ex);
        throw ex;
    }
    Assert.assertEquals(1, response.getPartitionSpecSize());
    PartitionSpecWithSharedSD partitionSpecWithSharedSD = response.getPartitionSpec().get(0).getSharedSDPartitionSpec();
    Assert.assertNotNull(partitionSpecWithSharedSD.getSd());
    StorageDescriptor sharedSD = partitionSpecWithSharedSD.getSd();
    Assert.assertEquals("Root location should be set to table location", tbl.getSd().getLocation(), sharedSD.getLocation());
    Assert.assertFalse("Fields which are not requested should not be set", sharedSD.isSetParameters());
    Assert.assertNotNull("serializationLib class was requested but was not found in the returned partition", sharedSD.getSerdeInfo().getSerializationLib());
    Assert.assertNotNull("db name was requested but was not found in the returned partition", response.getPartitionSpec().get(0).getDbName());
    Assert.assertNotNull("Table name was requested but was not found in the returned partition", response.getPartitionSpec().get(0).getTableName());
    Assert.assertTrue("sd.cols was requested but was not found in the returned response", partitionSpecWithSharedSD.getSd().isSetCols());
    List<FieldSchema> origSdCols = createdPartitions.get(0).getSd().getCols();
    Assert.assertEquals("Size of the requested sd.cols should be same", origSdCols.size(), partitionSpecWithSharedSD.getSd().getCols().size());
    for (int i = 0; i < origSdCols.size(); i++) {
        FieldSchema origFs = origSdCols.get(i);
        FieldSchema returnedFs = partitionSpecWithSharedSD.getSd().getCols().get(i);
        Assert.assertEquals("Field schemas returned different than expected", origFs, returnedFs);
    }
    /*Assert
        .assertNotNull("Catalog name was requested but was not found in the returned partition",
            response.getPartitionSpec().get(0).getCatName());*/
    List<PartitionWithoutSD> partitionWithoutSDS = partitionSpecWithSharedSD.getPartitions();
    Assert.assertEquals(createdPartitions.size(), partitionWithoutSDS.size());
    for (int i = 0; i < createdPartitions.size(); i++) {
        Partition origPartition = createdPartitions.get(i);
        PartitionWithoutSD returnedPartitionWithoutSD = partitionWithoutSDS.get(i);
        Assert.assertEquals(String.format("Location returned for Partition %d is not correct", i), origPartition.getSd().getLocation(), sharedSD.getLocation() + returnedPartitionWithoutSD.getRelativePath());
        Assert.assertTrue("createTime was request but is not set", returnedPartitionWithoutSD.isSetCreateTime());
        Assert.assertTrue("Partition parameters were requested but are not set", returnedPartitionWithoutSD.isSetParameters());
        // first partition has parameters set
        if (i == 0) {
            Assert.assertTrue("partition parameters not set", returnedPartitionWithoutSD.getParameters().containsKey("key1"));
            Assert.assertEquals("partition parameters does not contain included keys", "val1", returnedPartitionWithoutSD.getParameters().get("key1"));
            // excluded parameter should not be returned
            Assert.assertFalse("Excluded parameter key returned", returnedPartitionWithoutSD.getParameters().containsKey("excludeKey1"));
            Assert.assertFalse("Excluded parameter key returned", returnedPartitionWithoutSD.getParameters().containsKey("excludeKey2"));
        }
        List<String> returnedVals = returnedPartitionWithoutSD.getValues();
        List<String> actualVals = origPartition.getValues();
        for (int j = 0; j < actualVals.size(); j++) {
            Assert.assertEquals(actualVals.get(j), returnedVals.get(j));
        }
    }
}
Also used : GetProjectionsSpec(org.apache.hadoop.hive.metastore.api.GetProjectionsSpec) Partition(org.apache.hadoop.hive.metastore.api.Partition) SourceTable(org.apache.hadoop.hive.metastore.api.SourceTable) Table(org.apache.hadoop.hive.metastore.api.Table) FieldSchema(org.apache.hadoop.hive.metastore.api.FieldSchema) StorageDescriptor(org.apache.hadoop.hive.metastore.api.StorageDescriptor) GetPartitionsResponse(org.apache.hadoop.hive.metastore.api.GetPartitionsResponse) GetPartitionsRequest(org.apache.hadoop.hive.metastore.api.GetPartitionsRequest) PartitionSpecWithSharedSD(org.apache.hadoop.hive.metastore.api.PartitionSpecWithSharedSD) MetaException(org.apache.hadoop.hive.metastore.api.MetaException) InvalidOperationException(org.apache.hadoop.hive.metastore.api.InvalidOperationException) ConfigValSecurityException(org.apache.hadoop.hive.metastore.api.ConfigValSecurityException) SQLException(java.sql.SQLException) UnknownDBException(org.apache.hadoop.hive.metastore.api.UnknownDBException) TException(org.apache.thrift.TException) IOException(java.io.IOException) InvalidObjectException(org.apache.hadoop.hive.metastore.api.InvalidObjectException) NoSuchObjectException(org.apache.hadoop.hive.metastore.api.NoSuchObjectException) GetPartitionsFilterSpec(org.apache.hadoop.hive.metastore.api.GetPartitionsFilterSpec) PartitionWithoutSD(org.apache.hadoop.hive.metastore.api.PartitionWithoutSD) Test(org.junit.Test)

Aggregations

GetPartitionsRequest (org.apache.hadoop.hive.metastore.api.GetPartitionsRequest)19 GetProjectionsSpec (org.apache.hadoop.hive.metastore.api.GetProjectionsSpec)16 GetPartitionsResponse (org.apache.hadoop.hive.metastore.api.GetPartitionsResponse)15 PartitionSpecWithSharedSD (org.apache.hadoop.hive.metastore.api.PartitionSpecWithSharedSD)14 Test (org.junit.Test)12 MetastoreCheckinTest (org.apache.hadoop.hive.metastore.annotation.MetastoreCheckinTest)11 PartitionWithoutSD (org.apache.hadoop.hive.metastore.api.PartitionWithoutSD)9 StorageDescriptor (org.apache.hadoop.hive.metastore.api.StorageDescriptor)7 Partition (org.apache.hadoop.hive.metastore.api.Partition)6 PartitionListComposingSpec (org.apache.hadoop.hive.metastore.api.PartitionListComposingSpec)4 PartitionSpec (org.apache.hadoop.hive.metastore.api.PartitionSpec)4 FieldSchema (org.apache.hadoop.hive.metastore.api.FieldSchema)2 GetPartitionsFilterSpec (org.apache.hadoop.hive.metastore.api.GetPartitionsFilterSpec)2 Table (org.apache.hadoop.hive.metastore.api.Table)2 IOException (java.io.IOException)1 SQLException (java.sql.SQLException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 ConfigValSecurityException (org.apache.hadoop.hive.metastore.api.ConfigValSecurityException)1 InvalidObjectException (org.apache.hadoop.hive.metastore.api.InvalidObjectException)1