Search in sources :

Example 26 with CommandProcessorResponse

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

the class FolderPermissionBase method testCtas.

@Test
public void testCtas() throws Exception {
    String testDb = "ctasdb";
    String tableName = "createtable";
    CommandProcessorResponse ret = driver.run("CREATE DATABASE " + testDb);
    Assert.assertEquals(0, ret.getResponseCode());
    assertExistence(warehouseDir + "/" + testDb + ".db");
    setPermission(warehouseDir + "/" + testDb + ".db");
    verifyPermission(warehouseDir + "/" + testDb + ".db");
    ret = driver.run("USE " + testDb);
    Assert.assertEquals(0, ret.getResponseCode());
    ret = driver.run("create table " + tableName + " as 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());
}
Also used : CommandProcessorResponse(org.apache.hadoop.hive.ql.processors.CommandProcessorResponse) Test(org.junit.Test)

Example 27 with CommandProcessorResponse

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

the class FolderPermissionBase method testInsertSingleDynamicPartition.

@Test
public void testInsertSingleDynamicPartition() throws Exception {
    String tableName = "singledynamicpart";
    CommandProcessorResponse ret = driver.run("CREATE TABLE " + tableName + " (key string, value string) partitioned by (part1 string)");
    Assert.assertEquals(0, ret.getResponseCode());
    String tableLoc = warehouseDir + "/" + tableName;
    assertExistence(tableLoc);
    //Insert into test, with permission set 0.
    setPermission(tableLoc, 0);
    ret = driver.run("insert into table " + tableName + " partition (part1) select key,value,part1 from mysrc");
    Assert.assertEquals(0, ret.getResponseCode());
    verifySinglePartition(tableLoc, 0);
    //Insert overwrite test, with permission set 1. We need reset existing partitions to 1 since the permissions
    //should be inherited from existing partition
    setSinglePartition(tableLoc, 1);
    ret = driver.run("insert overwrite table " + tableName + " partition (part1) select key,value,part1 from mysrc");
    Assert.assertEquals(0, ret.getResponseCode());
    verifySinglePartition(tableLoc, 1);
    //delete and re-insert using insert overwrite.  There's different code paths insert vs insert overwrite for new tables.
    ret = driver.run("DROP TABLE " + tableName);
    Assert.assertEquals(0, ret.getResponseCode());
    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);
    ret = driver.run("insert overwrite table " + tableName + " partition (part1) select key,value,part1 from mysrc");
    Assert.assertEquals(0, ret.getResponseCode());
    verifySinglePartition(tableLoc, 0);
}
Also used : CommandProcessorResponse(org.apache.hadoop.hive.ql.processors.CommandProcessorResponse) Test(org.junit.Test)

Example 28 with CommandProcessorResponse

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

the class FolderPermissionBase method setupDataTable.

private static void setupDataTable() throws Exception {
    CommandProcessorResponse ret = driver.run("DROP TABLE IF EXISTS mysrc");
    Assert.assertEquals(0, ret.getResponseCode());
    ret = driver.run("CREATE TABLE mysrc (key STRING, value STRING) PARTITIONED BY (part1 string, part2 string) STORED AS TEXTFILE");
    Assert.assertEquals(0, ret.getResponseCode());
    ret = driver.run("LOAD DATA LOCAL INPATH '" + dataFilePath + "' INTO TABLE mysrc PARTITION (part1='1',part2='1')");
    Assert.assertEquals(0, ret.getResponseCode());
    ret = driver.run("LOAD DATA LOCAL INPATH '" + dataFilePath + "' INTO TABLE mysrc PARTITION (part1='2',part2='2')");
    Assert.assertEquals(0, ret.getResponseCode());
}
Also used : CommandProcessorResponse(org.apache.hadoop.hive.ql.processors.CommandProcessorResponse)

Example 29 with CommandProcessorResponse

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

the class FolderPermissionBase method testCreateTable.

@Test
public void testCreateTable() throws Exception {
    String testDb = "mydb2";
    String tableName = "createtable";
    CommandProcessorResponse ret = driver.run("CREATE DATABASE " + testDb);
    Assert.assertEquals(0, ret.getResponseCode());
    assertExistence(warehouseDir + "/" + testDb + ".db");
    setPermission(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());
}
Also used : CommandProcessorResponse(org.apache.hadoop.hive.ql.processors.CommandProcessorResponse) Test(org.junit.Test)

Example 30 with CommandProcessorResponse

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

the class FolderPermissionBase method testInsertNonPartTable.

@Test
public void testInsertNonPartTable() throws Exception {
    //case 1 is non-partitioned table.
    String tableName = "nonpart";
    CommandProcessorResponse ret = driver.run("CREATE TABLE " + tableName + " (key string, value string)");
    Assert.assertEquals(0, ret.getResponseCode());
    String tableLoc = warehouseDir + "/" + tableName;
    assertExistence(warehouseDir + "/" + tableName);
    //case1A: insert into non-partitioned table.
    setPermission(warehouseDir + "/" + tableName);
    ret = driver.run("insert into table " + tableName + " select key,value from mysrc");
    Assert.assertEquals(0, ret.getResponseCode());
    verifyPermission(warehouseDir + "/" + tableName);
    Assert.assertTrue(listStatus(tableLoc).size() > 0);
    for (String child : listStatus(tableLoc)) {
        verifyPermission(child);
    }
    //case1B: insert overwrite non-partitioned-table
    setPermission(warehouseDir + "/" + tableName, 1);
    ret = driver.run("insert overwrite table " + tableName + " select key,value from mysrc");
    Assert.assertEquals(0, ret.getResponseCode());
    verifyPermission(warehouseDir + "/" + tableName, 1);
    Assert.assertTrue(listStatus(tableLoc).size() > 0);
    for (String child : listStatus(tableLoc)) {
        verifyPermission(child, 1);
    }
}
Also used : CommandProcessorResponse(org.apache.hadoop.hive.ql.processors.CommandProcessorResponse) Test(org.junit.Test)

Aggregations

CommandProcessorResponse (org.apache.hadoop.hive.ql.processors.CommandProcessorResponse)124 Test (org.junit.Test)85 ShowLocksResponseElement (org.apache.hadoop.hive.metastore.api.ShowLocksResponseElement)22 HCatBaseTest (org.apache.hive.hcatalog.mapreduce.HCatBaseTest)19 ArrayList (java.util.ArrayList)17 IOException (java.io.IOException)12 Driver (org.apache.hadoop.hive.ql.Driver)9 AddDynamicPartitions (org.apache.hadoop.hive.metastore.api.AddDynamicPartitions)8 Database (org.apache.hadoop.hive.metastore.api.Database)8 CommandNeedRetryException (org.apache.hadoop.hive.ql.CommandNeedRetryException)8 Table (org.apache.hadoop.hive.metastore.api.Table)7 Path (org.apache.hadoop.fs.Path)6 HiveConf (org.apache.hadoop.hive.conf.HiveConf)6 PigServer (org.apache.pig.PigServer)5 FieldSchema (org.apache.hadoop.hive.metastore.api.FieldSchema)4 Configuration (org.apache.hadoop.conf.Configuration)3 HBaseAdmin (org.apache.hadoop.hbase.client.HBaseAdmin)3 CliSessionState (org.apache.hadoop.hive.cli.CliSessionState)3 MetaException (org.apache.hadoop.hive.metastore.api.MetaException)3 FileNotFoundException (java.io.FileNotFoundException)2