Search in sources :

Example 91 with CommandProcessorResponse

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

the class FolderPermissionBase method testLoadLocal.

@Test
public void testLoadLocal() throws Exception {
    //case 1 is non-partitioned table.
    String tableName = "loadlocal";
    CommandProcessorResponse ret = driver.run("CREATE TABLE " + tableName + " (key string, value string)");
    Assert.assertEquals(0, ret.getResponseCode());
    String tableLoc = warehouseDir + "/" + tableName;
    assertExistence(warehouseDir + "/" + tableName);
    //case1A: load data local into non-partitioned table.
    setPermission(warehouseDir + "/" + tableName);
    ret = driver.run("load data local inpath '" + dataFilePath + "' into table " + tableName);
    Assert.assertEquals(0, ret.getResponseCode());
    Assert.assertTrue(listStatus(tableLoc).size() > 0);
    for (String child : listStatus(tableLoc)) {
        verifyPermission(child);
    }
    //case1B: load data local into overwrite non-partitioned-table
    setPermission(warehouseDir + "/" + tableName, 1);
    for (String child : listStatus(tableLoc)) {
        setPermission(child, 1);
    }
    ret = driver.run("load data local inpath '" + dataFilePath + "' overwrite into table " + tableName);
    Assert.assertEquals(0, ret.getResponseCode());
    Assert.assertTrue(listStatus(tableLoc).size() > 0);
    for (String child : listStatus(tableLoc)) {
        verifyPermission(child, 1);
    }
    //case 2 is partitioned table.
    tableName = "loadlocalpartition";
    ret = driver.run("CREATE TABLE " + tableName + " (key string, value string) partitioned by (part1 int, part2 int)");
    Assert.assertEquals(0, ret.getResponseCode());
    tableLoc = warehouseDir + "/" + tableName;
    assertExistence(tableLoc);
    //case 2A: load data local into partitioned table.
    setPermission(tableLoc);
    ret = driver.run("LOAD DATA LOCAL INPATH '" + dataFilePath + "' INTO TABLE " + tableName + " PARTITION (part1='1',part2='1')");
    Assert.assertEquals(0, ret.getResponseCode());
    String partLoc = warehouseDir + "/" + tableName + "/part1=1/part2=1";
    Assert.assertTrue(listStatus(partLoc).size() > 0);
    for (String child : listStatus(partLoc)) {
        verifyPermission(child);
    }
    //case 2B: insert data overwrite into partitioned table. set testing table/partition folder hierarchy 1
    //local load overwrite just overwrite the existing partition content but not the permission
    setPermission(tableLoc, 1);
    setPermission(partLoc, 1);
    for (String child : listStatus(partLoc)) {
        setPermission(child, 1);
    }
    ret = driver.run("LOAD DATA LOCAL INPATH '" + dataFilePath + "' OVERWRITE INTO TABLE " + tableName + " PARTITION (part1='1',part2='1')");
    Assert.assertEquals(0, ret.getResponseCode());
    Assert.assertTrue(listStatus(tableLoc).size() > 0);
    for (String child : listStatus(partLoc)) {
        verifyPermission(child, 1);
    }
}
Also used : CommandProcessorResponse(org.apache.hadoop.hive.ql.processors.CommandProcessorResponse) Test(org.junit.Test)

Example 92 with CommandProcessorResponse

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

the class FolderPermissionBase method testCreateDb.

@Test
public void testCreateDb() throws Exception {
    //see if db inherits permission from warehouse directory.
    String testDb = "mydb";
    String tableName = "createtable";
    setPermission(warehouseDir.toString());
    verifyPermission(warehouseDir.toString());
    CommandProcessorResponse ret = driver.run("CREATE DATABASE " + testDb);
    Assert.assertEquals(0, ret.getResponseCode());
    assertExistence(warehouseDir + "/" + testDb + ".db");
    verifyPermission(warehouseDir + "/" + testDb + ".db");
    ret = driver.run("USE " + testDb);
    Assert.assertEquals(0, ret.getResponseCode());
    ret = driver.run("CREATE TABLE " + tableName + " (key string, value string)");
    Assert.assertEquals(0, ret.getResponseCode());
    verifyPermission(warehouseDir + "/" + testDb + ".db/" + tableName);
    ret = driver.run("insert into table " + tableName + " select key,value from default.mysrc");
    Assert.assertEquals(0, ret.getResponseCode());
    assertExistence(warehouseDir + "/" + testDb + ".db/" + tableName);
    verifyPermission(warehouseDir + "/" + testDb + ".db/" + tableName);
    Assert.assertTrue(listStatus(warehouseDir + "/" + testDb + ".db/" + tableName).size() > 0);
    for (String child : listStatus(warehouseDir + "/" + testDb + ".db/" + tableName)) {
        verifyPermission(child);
    }
    ret = driver.run("USE default");
    Assert.assertEquals(0, ret.getResponseCode());
    //cleanup after the test.
    fs.delete(warehouseDir, true);
    fs.mkdirs(warehouseDir);
    Assert.assertEquals(listStatus(warehouseDir.toString()).size(), 0);
    setupDataTable();
}
Also used : CommandProcessorResponse(org.apache.hadoop.hive.ql.processors.CommandProcessorResponse) Test(org.junit.Test)

Example 93 with CommandProcessorResponse

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

the class FolderPermissionBase method testLoad.

@Test
public void testLoad() throws Exception {
    String tableName = "load";
    String location = "/hdfsPath";
    fs.copyFromLocalFile(dataFilePath, new Path(location));
    //case 1: load data
    CommandProcessorResponse ret = driver.run("CREATE TABLE " + tableName + " (key string, value string)");
    Assert.assertEquals(0, ret.getResponseCode());
    String tableLoc = warehouseDir + "/" + tableName;
    assertExistence(warehouseDir + "/" + tableName);
    //case1A: load data into non-partitioned table.
    setPermission(warehouseDir + "/" + tableName);
    ret = driver.run("load data inpath '" + location + "' into table " + tableName);
    Assert.assertEquals(0, ret.getResponseCode());
    Assert.assertTrue(listStatus(tableLoc).size() > 0);
    for (String child : listStatus(tableLoc)) {
        verifyPermission(child);
    }
    //case1B: load data into overwrite non-partitioned-table
    setPermission(warehouseDir + "/" + tableName, 1);
    for (String child : listStatus(tableLoc)) {
        setPermission(child, 1);
    }
    fs.copyFromLocalFile(dataFilePath, new Path(location));
    ret = driver.run("load data inpath '" + location + "' overwrite into table " + tableName);
    Assert.assertEquals(0, ret.getResponseCode());
    Assert.assertTrue(listStatus(tableLoc).size() > 0);
    for (String child : listStatus(tableLoc)) {
        verifyPermission(child, 1);
    }
    //case 2 is partitioned table.
    tableName = "loadpartition";
    ret = driver.run("CREATE TABLE " + tableName + " (key string, value string) partitioned by (part1 int, part2 int)");
    Assert.assertEquals(0, ret.getResponseCode());
    tableLoc = warehouseDir + "/" + tableName;
    assertExistence(tableLoc);
    //case 2A: load data into partitioned table.
    setPermission(tableLoc);
    fs.copyFromLocalFile(dataFilePath, new Path(location));
    ret = driver.run("LOAD DATA INPATH '" + location + "' INTO TABLE " + tableName + " PARTITION (part1='1',part2='1')");
    Assert.assertEquals(0, ret.getResponseCode());
    String partLoc = warehouseDir + "/" + tableName + "/part1=1/part2=1";
    Assert.assertTrue(listStatus(partLoc).size() > 0);
    for (String child : listStatus(partLoc)) {
        verifyPermission(child);
    }
    //case 2B: insert data overwrite into partitioned table. set testing table/partition folder hierarchy 1
    //load overwrite just overwrite the existing partition content but not the permission
    setPermission(tableLoc, 1);
    setPermission(partLoc, 1);
    Assert.assertTrue(listStatus(partLoc).size() > 0);
    for (String child : listStatus(partLoc)) {
        setPermission(child, 1);
    }
    fs.copyFromLocalFile(dataFilePath, new Path(location));
    ret = driver.run("LOAD DATA INPATH '" + location + "' OVERWRITE INTO TABLE " + tableName + " PARTITION (part1='1',part2='1')");
    Assert.assertEquals(0, ret.getResponseCode());
    Assert.assertTrue(listStatus(tableLoc).size() > 0);
    for (String child : listStatus(partLoc)) {
        verifyPermission(child, 1);
    }
}
Also used : Path(org.apache.hadoop.fs.Path) CommandProcessorResponse(org.apache.hadoop.hive.ql.processors.CommandProcessorResponse) Test(org.junit.Test)

Example 94 with CommandProcessorResponse

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

the class TestHBaseMetastoreSql method database.

@Test
public void database() throws Exception {
    CommandProcessorResponse rsp = driver.run("create database db");
    Assert.assertEquals(0, rsp.getResponseCode());
    rsp = driver.run("set role admin");
    Assert.assertEquals(0, rsp.getResponseCode());
    // security doesn't let me change the properties
    rsp = driver.run("alter database db set dbproperties ('key' = 'value')");
    Assert.assertEquals(0, rsp.getResponseCode());
    rsp = driver.run("drop database db");
    Assert.assertEquals(0, rsp.getResponseCode());
}
Also used : CommandProcessorResponse(org.apache.hadoop.hive.ql.processors.CommandProcessorResponse) Test(org.junit.Test)

Example 95 with CommandProcessorResponse

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

the class TestHBaseMetastoreSql method grant.

@Test
public void grant() throws Exception {
    CommandProcessorResponse rsp = driver.run("set role admin");
    Assert.assertEquals(0, rsp.getResponseCode());
    rsp = driver.run("create role role3");
    Assert.assertEquals(0, rsp.getResponseCode());
    driver.run("create table granttbl (c int)");
    Assert.assertEquals(0, rsp.getResponseCode());
    driver.run("grant select on granttbl to " + System.getProperty("user.name"));
    Assert.assertEquals(0, rsp.getResponseCode());
    driver.run("grant select on granttbl to role3 with grant option");
    Assert.assertEquals(0, rsp.getResponseCode());
    driver.run("revoke select on granttbl from " + System.getProperty("user.name"));
    Assert.assertEquals(0, rsp.getResponseCode());
    driver.run("revoke grant option for select on granttbl from role3");
    Assert.assertEquals(0, rsp.getResponseCode());
}
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