Package org.apache.hadoop.hive.ql.processors

Examples of org.apache.hadoop.hive.ql.processors.CommandProcessorResponse


        + "(key int, testqualifier1 string, testqualifier2 string) STORED BY " +
        "'org.apache.hadoop.hive.hbase.HBaseStorageHandler'" +
        " WITH SERDEPROPERTIES ('hbase.columns.mapping'=':key,testFamily:testQualifier1,testFamily:testQualifier2')" +
        " TBLPROPERTIES ('hbase.table.default.storage.type'='binary')";

    CommandProcessorResponse responseOne = driver.run(deleteQuery);
    assertEquals(0, responseOne.getResponseCode());


    CommandProcessorResponse responseTwo = driver.run(dbQuery);
    assertEquals(0, responseTwo.getResponseCode());


    CommandProcessorResponse responseThree = driver.run(tableQuery);

    HBaseAdmin hAdmin = new HBaseAdmin(getHbaseConf());
    boolean doesTableExist = hAdmin.tableExists(hbaseTableName);
    assertTrue(doesTableExist);
View Full Code Here



    String selectQuery = "SELECT * from "+databaseName.toLowerCase()+"."+tableName.toLowerCase();


    CommandProcessorResponse responseOne = driver.run(deleteQuery);
    assertEquals(0, responseOne.getResponseCode());


    CommandProcessorResponse responseTwo = driver.run(dbQuery);
    assertEquals(0, responseTwo.getResponseCode());


    CommandProcessorResponse responseThree = driver.run(tableQuery);

    HBaseAdmin hAdmin = new HBaseAdmin(getHbaseConf());
    boolean doesTableExist = hAdmin.tableExists(hbaseTableName);
    assertTrue(doesTableExist);


    createTestDataFile(POPTXT_FILE_NAME);

    PigServer server = new PigServer(ExecType.LOCAL,hcatConf.getAllProperties());
    server.registerQuery("A = load '"+POPTXT_FILE_NAME+"' using PigStorage() as (key:int, testqualifier1:float, testqualifier2:chararray);");
    server.registerQuery("B = filter A by (key > 2) AND (key < 8) ;");
    server.registerQuery("store B into '"+databaseName.toLowerCase()+"."+tableName.toLowerCase()+"' using  org.apache.hive.hcatalog.pig.HCatStorer();");
    server.registerQuery("C = load '"+databaseName.toLowerCase()+"."+tableName.toLowerCase()+"' using org.apache.hive.hcatalog.pig.HCatLoader();");
    // Schema should be same
    Schema dumpedBSchema = server.dumpSchema("C");

    List<FieldSchema> fields = dumpedBSchema.getFields();
    assertEquals(3, fields.size());

    assertEquals(DataType.INTEGER,fields.get(0).type);
    assertEquals("key",fields.get(0).alias.toLowerCase());

    assertEquals( DataType.FLOAT,fields.get(1).type);
    assertEquals("testQualifier1".toLowerCase(), fields.get(1).alias.toLowerCase());

    assertEquals( DataType.CHARARRAY,fields.get(2).type);
    assertEquals("testQualifier2".toLowerCase(), fields.get(2).alias.toLowerCase());

    //Query the hbase table and check the key is valid and only 5  are present
    Configuration conf = new Configuration(getHbaseConf());
    HTable table = new HTable(conf, hbaseTableName);
    Scan scan = new Scan();
    scan.addFamily(Bytes.toBytes("testFamily"));
    byte[] familyNameBytes = Bytes.toBytes("testFamily");
    ResultScanner scanner = table.getScanner(scan);
    int index=3;
    int count=0;
    for(Result result: scanner) {
      //key is correct
      assertEquals(index,Bytes.toInt(result.getRow()));
      //first column exists
      assertTrue(result.containsColumn(familyNameBytes,Bytes.toBytes("testQualifier1")));
      //value is correct
      assertEquals((index+f),Bytes.toFloat(result.getValue(familyNameBytes,Bytes.toBytes("testQualifier1"))),0);

      //second column exists
      assertTrue(result.containsColumn(familyNameBytes,Bytes.toBytes("testQualifier2")));
      //value is correct
      assertEquals(("textB-"+index).toString(),Bytes.toString(result.getValue(familyNameBytes,Bytes.toBytes("testQualifier2"))));
      index++;
      count++;
    }
    // 5 rows should be returned
    assertEquals(count,5);

    //Check if hive returns results correctly
    driver.run(selectQuery);
    ArrayList<String> result = new ArrayList<String>();
    driver.getResults(result);
    //Query using the hive command line
    assertEquals(5, result.size());
    Iterator<String> itr = result.iterator();
    for(int i = 3; i <= 7; i++) {
      String tokens[] = itr.next().split("\\s+");
      assertEquals(i,Integer.parseInt(tokens[0]));
      assertEquals(i+f,Float.parseFloat(tokens[1]),0);
      assertEquals(("textB-"+i).toString(),tokens[2]);
    }

    //delete the table from the database
    CommandProcessorResponse responseFour = driver.run(deleteQuery);
    assertEquals(0, responseFour.getResponseCode());

  }
View Full Code Here

  @Test
  public void testTableCreateDrop() throws Exception {
    Initialize();

    hcatDriver.run("drop table test_table");
    CommandProcessorResponse response = hcatDriver
        .run("create table test_table(key int, value string) STORED BY " +
                     "'org.apache.hcatalog.hbase.HBaseHCatStorageHandler'"
          + "TBLPROPERTIES ('hbase.columns.mapping'=':key,cf1:val')");

    assertEquals(0, response.getResponseCode());

    HBaseAdmin hAdmin = new HBaseAdmin(getHbaseConf());
    boolean doesTableExist = hAdmin.tableExists("test_table");

    assertTrue(doesTableExist);
View Full Code Here

  @Test
  public void testTableCreateDropDifferentCase() throws Exception {
    Initialize();

    hcatDriver.run("drop table test_Table");
    CommandProcessorResponse response = hcatDriver
        .run("create table test_Table(key int, value string) STORED BY " +
               "'org.apache.hcatalog.hbase.HBaseHCatStorageHandler'"
          + "TBLPROPERTIES ('hbase.columns.mapping'=':key,cf1:val')");

    assertEquals(0, response.getResponseCode());

    //HBase table gets created with lower case unless specified as a table property.
    HBaseAdmin hAdmin = new HBaseAdmin(getHbaseConf());
    boolean doesTableExist = hAdmin.tableExists("test_table");
View Full Code Here

  @Test
  public void testTableCreateDropCaseSensitive() throws Exception {
    Initialize();

    hcatDriver.run("drop table test_Table");
    CommandProcessorResponse response = hcatDriver
        .run("create table test_Table(key int, value string) STORED BY " +
               "'org.apache.hcatalog.hbase.HBaseHCatStorageHandler'"
          + "TBLPROPERTIES ('hbase.columns.mapping'=':key,cf1:val'," +
          " 'hbase.table.name'='CaseSensitiveTable')");

    assertEquals(0, response.getResponseCode());

    HBaseAdmin hAdmin = new HBaseAdmin(getHbaseConf());
    boolean doesTableExist = hAdmin.tableExists("CaseSensitiveTable");

    assertTrue(doesTableExist);
View Full Code Here

  @Test
  public void testTableDropNonExistent() throws Exception {
    Initialize();

    hcatDriver.run("drop table mytable");
    CommandProcessorResponse response = hcatDriver
        .run("create table mytable(key int, value string) STORED BY " +
           "'org.apache.hcatalog.hbase.HBaseHCatStorageHandler'"
          + "TBLPROPERTIES ('hbase.columns.mapping'=':key,cf1:val')");

    assertEquals(0, response.getResponseCode());

    HBaseAdmin hAdmin = new HBaseAdmin(getHbaseConf());
    boolean doesTableExist = hAdmin.tableExists("mytable");
    assertTrue(doesTableExist);

    //Now delete the table from hbase
    if (hAdmin.isTableEnabled("mytable")) {
      hAdmin.disableTable("mytable");
    }
    hAdmin.deleteTable("mytable");
    doesTableExist = hAdmin.tableExists("mytable");
    assertTrue(doesTableExist == false);

    CommandProcessorResponse responseTwo = hcatDriver.run("drop table mytable");
    assertTrue(responseTwo.getResponseCode() == 0);

  }
View Full Code Here

    hAdmin.createTable(tableDesc);
    boolean doesTableExist = hAdmin.tableExists(tableName);
    assertTrue(doesTableExist);

    hcatDriver.run("drop table mytabletwo");
    CommandProcessorResponse response = hcatDriver
        .run("create external table mytabletwo(key int, valueone string, valuetwo string) STORED BY " +
           "'org.apache.hcatalog.hbase.HBaseHCatStorageHandler'"
          + "TBLPROPERTIES ('hbase.columns.mapping'=':key,familyone:val,familytwo:val'," +
          "'hbase.table.name'='testTable')");

    assertEquals(0, response.getResponseCode());

  }
View Full Code Here

    String tableQuery = "CREATE TABLE " + databaseName + "." + tableName
      + "(key string, testqualifier1 string, testqualifier2 string) STORED BY " +
      "'org.apache.hadoop.hive.hbase.HBaseStorageHandler'"
      + " WITH SERDEPROPERTIES ('hbase.columns.mapping'=':key,testFamily:testQualifier1,testFamily:testQualifier2')" ;

    CommandProcessorResponse responseOne = hcatDriver.run(dbquery);
    assertEquals(0, responseOne.getResponseCode());
    CommandProcessorResponse responseTwo = hcatDriver.run(tableQuery);
    assertEquals(0, responseTwo.getResponseCode());

    HBaseAdmin hAdmin = new HBaseAdmin(getHbaseConf());
    boolean doesTableExist = hAdmin.tableExists(hbaseTableName);
    assertTrue(doesTableExist);

    populateHBaseTable(hbaseTableName, 5);
    Configuration conf = new Configuration(hcatConf);
    conf.set(HCatConstants.HCAT_KEY_HIVE_CONF,
      HCatUtil.serialize(getHiveConf().getAllProperties()));

    conf.set(HBaseSerDe.HBASE_TABLE_NAME,hbaseTableName);
    conf.set(TableInputFormat.INPUT_TABLE, hbaseTableName);
    // output settings
    Path outputDir = new Path(getTestDir(), "mapred/testHbaseTableMRRead");
    FileSystem fs = getFileSystem();
    if (fs.exists(outputDir)) {
      fs.delete(outputDir, true);
    }
    // create job
    Job job = new Job(conf, "hbase-mr-read-test");
    job.setJarByClass(this.getClass());
    job.setMapperClass(MapReadHTable.class);
    MapReadHTable.resetCounters();

    job.setInputFormatClass(HCatInputFormat.class);
    InputJobInfo inputJobInfo = InputJobInfo.create(databaseName, tableName,
                null);
    HCatInputFormat.setInput(job, inputJobInfo);
    job.setOutputFormatClass(TextOutputFormat.class);
    TextOutputFormat.setOutputPath(job, outputDir);
    job.setMapOutputKeyClass(BytesWritable.class);
    job.setMapOutputValueClass(Text.class);
    job.setOutputKeyClass(BytesWritable.class);
    job.setOutputValueClass(Text.class);
    job.setNumReduceTasks(0);
    assertTrue(job.waitForCompletion(true));
    // Note: These asserts only works in case of LocalJobRunner as they run in same jvm.
    // If using MiniMRCluster, the tests will have to be modified.
    assertFalse(MapReadHTable.error);
    assertEquals(MapReadHTable.count, 1);

    String dropTableQuery = "DROP TABLE " + hbaseTableName ;
    CommandProcessorResponse responseThree = hcatDriver.run(dropTableQuery);
    assertEquals(0, responseThree.getResponseCode());

    boolean isHbaseTableThere = hAdmin.tableExists(hbaseTableName);
    assertFalse(isHbaseTableThere);

    String dropDB = "DROP DATABASE " + databaseName;
    CommandProcessorResponse responseFour = hcatDriver.run(dropDB);
    assertEquals(0, responseFour.getResponseCode());
  }
View Full Code Here

      + "'org.apache.hadoop.hive.hbase.HBaseStorageHandler'"
      + " WITH  SERDEPROPERTIES ('hbase.columns.mapping'="
      + "':key,testFamily:testQualifier1,testFamily:testQualifier2')"
      + " TBLPROPERTIES ('hbase.table.name'='" + hbaseTableName+ "')" ;

    CommandProcessorResponse responseTwo = hcatDriver.run(tableQuery);
    assertEquals(0, responseTwo.getResponseCode());

    HBaseAdmin hAdmin = new HBaseAdmin(getHbaseConf());
    boolean doesTableExist = hAdmin.tableExists(hbaseTableName);
    assertTrue(doesTableExist);

    populateHBaseTable(hbaseTableName, 5);

    Configuration conf = new Configuration(hcatConf);
    conf.set(HCatConstants.HCAT_KEY_HIVE_CONF,
      HCatUtil.serialize(getHiveConf().getAllProperties()));

    // output settings
    Path outputDir = new Path(getTestDir(), "mapred/testHBaseTableProjectionReadMR");
    FileSystem fs = getFileSystem();
    if (fs.exists(outputDir)) {
      fs.delete(outputDir, true);
    }
    // create job
    Job job = new Job(conf, "hbase-column-projection");
    job.setJarByClass(this.getClass());
    job.setMapperClass(MapReadProjHTable.class);
    job.setInputFormatClass(HCatInputFormat.class);
    InputJobInfo inputJobInfo = InputJobInfo.create(
      MetaStoreUtils.DEFAULT_DATABASE_NAME, tableName, null);
    HCatInputFormat.setOutputSchema(job, getProjectionSchema());
    HCatInputFormat.setInput(job, inputJobInfo);
    job.setOutputFormatClass(TextOutputFormat.class);
    TextOutputFormat.setOutputPath(job, outputDir);
    job.setMapOutputKeyClass(BytesWritable.class);
    job.setMapOutputValueClass(Text.class);
    job.setOutputKeyClass(BytesWritable.class);
    job.setOutputValueClass(Text.class);
    job.setNumReduceTasks(0);
    assertTrue(job.waitForCompletion(true));
    assertFalse(MapReadProjHTable.error);
    assertEquals(MapReadProjHTable.count, 1);

    String dropTableQuery = "DROP TABLE " + tableName;
    CommandProcessorResponse responseThree = hcatDriver.run(dropTableQuery);
    assertEquals(0, responseThree.getResponseCode());

    boolean isHbaseTableThere = hAdmin.tableExists(hbaseTableName);
    assertFalse(isHbaseTableThere);
  }
View Full Code Here

    public static void execHiveDDL(String ddl) throws Exception {
        System.out.println("Executing ddl = " + ddl);

        Driver hiveDriver = new Driver();
        CommandProcessorResponse response = hiveDriver.run(ddl);

        System.out.println("response = " + response);
        System.out.println("response.getResponseCode() = " + response.getResponseCode());
        System.out.println("response.getErrorMessage() = " + response.getErrorMessage());
        System.out.println("response.getSQLState() = " + response.getSQLState());

        if (response.getResponseCode() > 0) {
            throw new Exception(response.getErrorMessage());
        }
    }
View Full Code Here

TOP

Related Classes of org.apache.hadoop.hive.ql.processors.CommandProcessorResponse

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.