Search in sources :

Example 86 with CommandProcessorResponse

use of org.apache.hadoop.hive.ql.processors.CommandProcessorResponse in project hive by apache.

the class TestAcidOnTez method runStatementOnDriver.

private List<String> runStatementOnDriver(String stmt) throws Exception {
    CommandProcessorResponse cpr = d.run(stmt);
    if (cpr.getResponseCode() != 0) {
        throw new RuntimeException(stmt + " failed: " + cpr);
    }
    List<String> rs = new ArrayList<String>();
    d.getResults(rs);
    return rs;
}
Also used : CommandProcessorResponse(org.apache.hadoop.hive.ql.processors.CommandProcessorResponse) ArrayList(java.util.ArrayList)

Example 87 with CommandProcessorResponse

use of org.apache.hadoop.hive.ql.processors.CommandProcessorResponse in project hive by apache.

the class FolderPermissionBase method testInsertStaticSinglePartition.

@Test
public void testInsertStaticSinglePartition() throws Exception {
    String tableName = "singlestaticpart";
    CommandProcessorResponse ret = driver.run("CREATE TABLE " + tableName + " (key string, value string) partitioned by (part1 string)");
    Assert.assertEquals(0, ret.getResponseCode());
    assertExistence(warehouseDir + "/" + tableName);
    setPermission(warehouseDir + "/" + tableName);
    //insert into test
    ret = driver.run("insert into table " + tableName + " partition(part1='1') select key,value from mysrc where part1='1' and part2='1'");
    Assert.assertEquals(0, ret.getResponseCode());
    verifyPermission(warehouseDir + "/" + tableName);
    verifyPermission(warehouseDir + "/" + tableName + "/part1=1");
    Assert.assertTrue(listStatus(warehouseDir + "/" + tableName + "/part1=1").size() > 0);
    for (String child : listStatus(warehouseDir + "/" + tableName + "/part1=1")) {
        verifyPermission(child);
    }
    //insert overwrite test
    setPermission(warehouseDir + "/" + tableName, 1);
    setPermission(warehouseDir + "/" + tableName + "/part1=1", 1);
    ret = driver.run("insert overwrite table " + tableName + " partition(part1='1') select key,value from mysrc where part1='1' and part2='1'");
    Assert.assertEquals(0, ret.getResponseCode());
    verifyPermission(warehouseDir + "/" + tableName, 1);
    verifyPermission(warehouseDir + "/" + tableName + "/part1=1", 1);
    Assert.assertTrue(listStatus(warehouseDir + "/" + tableName + "/part1=1").size() > 0);
    for (String child : listStatus(warehouseDir + "/" + tableName + "/part1=1")) {
        verifyPermission(child, 1);
    }
}
Also used : CommandProcessorResponse(org.apache.hadoop.hive.ql.processors.CommandProcessorResponse) Test(org.junit.Test)

Example 88 with CommandProcessorResponse

use of org.apache.hadoop.hive.ql.processors.CommandProcessorResponse in project hive by apache.

the class FolderPermissionBase method testExim.

@Test
public void testExim() throws Exception {
    //export the table to external file.
    String myLocation = warehouseDir + "/exim";
    FileSystem fs = FileSystem.get(new URI(myLocation), conf);
    fs.mkdirs(new Path(myLocation));
    setPermission(myLocation);
    myLocation = myLocation + "/temp";
    CommandProcessorResponse ret = driver.run("export table mysrc to '" + myLocation + "'");
    Assert.assertEquals(0, ret.getResponseCode());
    //check if exported data has inherited the permissions.
    assertExistence(myLocation);
    verifyPermission(myLocation);
    assertExistence(myLocation + "/part1=1/part2=1");
    verifyPermission(myLocation + "/part1=1/part2=1");
    Assert.assertTrue(listStatus(myLocation + "/part1=1/part2=1").size() > 0);
    for (String child : listStatus(myLocation + "/part1=1/part2=1")) {
        verifyPermission(child);
    }
    assertExistence(myLocation + "/part1=2/part2=2");
    verifyPermission(myLocation + "/part1=2/part2=2");
    Assert.assertTrue(listStatus(myLocation + "/part1=2/part2=2").size() > 0);
    for (String child : listStatus(myLocation + "/part1=2/part2=2")) {
        verifyPermission(child);
    }
    //import the table back into another database
    String testDb = "eximdb";
    ret = driver.run("CREATE DATABASE " + testDb);
    Assert.assertEquals(0, ret.getResponseCode());
    //use another permission for this import location, to verify that it is really set (permIndex=2)
    assertExistence(warehouseDir + "/" + testDb + ".db");
    setPermission(warehouseDir + "/" + testDb + ".db", 1);
    ret = driver.run("USE " + testDb);
    Assert.assertEquals(0, ret.getResponseCode());
    ret = driver.run("import from '" + myLocation + "'");
    Assert.assertEquals(0, ret.getResponseCode());
    //check permissions of imported, from the exported table
    assertExistence(warehouseDir + "/" + testDb + ".db/mysrc");
    verifyPermission(warehouseDir + "/" + testDb + ".db/mysrc", 1);
    myLocation = warehouseDir + "/" + testDb + ".db/mysrc";
    assertExistence(myLocation);
    verifyPermission(myLocation, 1);
    assertExistence(myLocation + "/part1=1/part2=1");
    verifyPermission(myLocation + "/part1=1/part2=1", 1);
    Assert.assertTrue(listStatus(myLocation + "/part1=1/part2=1").size() > 0);
    for (String child : listStatus(myLocation + "/part1=1/part2=1")) {
        verifyPermission(child, 1);
    }
    assertExistence(myLocation + "/part1=2/part2=2");
    verifyPermission(myLocation + "/part1=2/part2=2", 1);
    Assert.assertTrue(listStatus(myLocation + "/part1=2/part2=2").size() > 0);
    for (String child : listStatus(myLocation + "/part1=2/part2=2")) {
        verifyPermission(child, 1);
    }
}
Also used : Path(org.apache.hadoop.fs.Path) FileSystem(org.apache.hadoop.fs.FileSystem) CommandProcessorResponse(org.apache.hadoop.hive.ql.processors.CommandProcessorResponse) URI(java.net.URI) Test(org.junit.Test)

Example 89 with CommandProcessorResponse

use of org.apache.hadoop.hive.ql.processors.CommandProcessorResponse in project hive by apache.

the class FolderPermissionBase method testInsertDualDynamicPartitions.

@Test
public void testInsertDualDynamicPartitions() throws Exception {
    String tableName = "dualdynamicpart";
    CommandProcessorResponse ret = driver.run("CREATE TABLE " + tableName + " (key string, value string) partitioned by (part1 string, part2 string)");
    Assert.assertEquals(0, ret.getResponseCode());
    assertExistence(warehouseDir + "/" + tableName);
    //Insert into test, with permission set 0.
    setPermission(warehouseDir + "/" + tableName, 0);
    ret = driver.run("insert into table " + tableName + " partition (part1,part2) select key,value,part1,part2 from mysrc");
    Assert.assertEquals(0, ret.getResponseCode());
    verifyDualPartitionTable(warehouseDir + "/" + tableName, 0);
    //Insert overwrite test, with permission set 1.  We need reset existing partitions to 1 since the permissions
    //should be inherited from existing partition
    setDualPartitionTable(warehouseDir + "/" + tableName, 1);
    ret = driver.run("insert overwrite table " + tableName + " partition (part1,part2) select key,value,part1,part2 from mysrc");
    Assert.assertEquals(0, ret.getResponseCode());
    verifyDualPartitionTable(warehouseDir + "/" + tableName, 1);
}
Also used : CommandProcessorResponse(org.apache.hadoop.hive.ql.processors.CommandProcessorResponse) Test(org.junit.Test)

Example 90 with CommandProcessorResponse

use of org.apache.hadoop.hive.ql.processors.CommandProcessorResponse in project hive by apache.

the class FolderPermissionBase method testPartition.

@Test
public void testPartition() throws Exception {
    String tableName = "alterpart";
    CommandProcessorResponse ret = driver.run("CREATE TABLE " + tableName + " (key string, value string) partitioned by (part1 int, part2 int, part3 int)");
    Assert.assertEquals(0, ret.getResponseCode());
    assertExistence(warehouseDir + "/" + tableName);
    setPermission(warehouseDir + "/" + tableName);
    ret = driver.run("insert into table " + tableName + " partition(part1='1',part2='1',part3='1') select key,value from mysrc");
    Assert.assertEquals(0, ret.getResponseCode());
    assertExistence(warehouseDir + "/" + tableName);
    setPermission(warehouseDir + "/" + tableName, 1);
    //alter partition
    ret = driver.run("alter table " + tableName + " partition (part1='1',part2='1',part3='1') rename to partition (part1='2',part2='2',part3='2')");
    Assert.assertEquals(0, ret.getResponseCode());
    verifyPermission(warehouseDir + "/" + tableName + "/part1=2", 1);
    verifyPermission(warehouseDir + "/" + tableName + "/part1=2/part2=2", 1);
    verifyPermission(warehouseDir + "/" + tableName + "/part1=2/part2=2/part3=2", 1);
    Assert.assertTrue(listStatus(warehouseDir + "/" + tableName + "/part1=2/part2=2/part3=2").size() > 0);
    for (String child : listStatus(warehouseDir + "/" + tableName + "/part1=2/part2=2/part3=2")) {
        verifyPermission(child, 1);
    }
    String tableName2 = "alterpart2";
    ret = driver.run("CREATE TABLE " + tableName2 + " (key string, value string) partitioned by (part1 int, part2 int, part3 int)");
    Assert.assertEquals(0, ret.getResponseCode());
    assertExistence(warehouseDir + "/" + tableName2);
    setPermission(warehouseDir + "/" + tableName2);
    ret = driver.run("alter table " + tableName2 + " exchange partition (part1='2',part2='2',part3='2') with table " + tableName);
    Assert.assertEquals(0, ret.getResponseCode());
    //alter exchange can not change base table's permission
    //alter exchange can only control final partition folder's permission
    verifyPermission(warehouseDir + "/" + tableName2 + "/part1=2", 0);
    verifyPermission(warehouseDir + "/" + tableName2 + "/part1=2/part2=2", 0);
    verifyPermission(warehouseDir + "/" + tableName2 + "/part1=2/part2=2/part3=2", 1);
}
Also used : CommandProcessorResponse(org.apache.hadoop.hive.ql.processors.CommandProcessorResponse) Test(org.junit.Test)

Aggregations

CommandProcessorResponse (org.apache.hadoop.hive.ql.processors.CommandProcessorResponse)145 Test (org.junit.Test)92 ShowLocksResponseElement (org.apache.hadoop.hive.metastore.api.ShowLocksResponseElement)24 HCatBaseTest (org.apache.hive.hcatalog.mapreduce.HCatBaseTest)19 IOException (java.io.IOException)18 ArrayList (java.util.ArrayList)17 AddDynamicPartitions (org.apache.hadoop.hive.metastore.api.AddDynamicPartitions)8 Database (org.apache.hadoop.hive.metastore.api.Database)8 HiveConf (org.apache.hadoop.hive.conf.HiveConf)7 Table (org.apache.hadoop.hive.metastore.api.Table)7 Path (org.apache.hadoop.fs.Path)6 HiveException (org.apache.hadoop.hive.ql.metadata.HiveException)6 PigServer (org.apache.pig.PigServer)5 FieldSchema (org.apache.hadoop.hive.metastore.api.FieldSchema)4 Driver (org.apache.hadoop.hive.ql.Driver)4 IDriver (org.apache.hadoop.hive.ql.IDriver)4 LockException (org.apache.hadoop.hive.ql.lockmgr.LockException)4 PerfLogger (org.apache.hadoop.hive.ql.log.PerfLogger)4 ParseException (org.apache.hadoop.hive.ql.parse.ParseException)4 HashMap (java.util.HashMap)3