Package org.apache.hadoop.hive.metastore.api

Examples of org.apache.hadoop.hive.metastore.api.Table$Isset


      typ1.getFields().add(new FieldSchema("name", Constants.STRING_TYPE_NAME, ""));
      typ1.getFields().add(new FieldSchema("income", Constants.INT_TYPE_NAME, ""));
      ret = client.createType(typ1);
      assertTrue("Unable to create type " + typeName, ret);
 
      Table tbl = new Table();
      tbl.setDbName(dbName);
      tbl.setTableName(tblName);
      StorageDescriptor sd = new StorageDescriptor();
      tbl.setSd(sd);
      sd.setCols(typ1.getFields());
      sd.setCompressed(false);
      sd.setNumBuckets(1);
      sd.setParameters(new HashMap<String, String>());
      sd.getParameters().put("test_param_1", "Use this for comments etc");
      sd.setBucketCols(new ArrayList<String>(2));
      sd.getBucketCols().add("name");
      sd.setSerdeInfo(new SerDeInfo());
      sd.getSerdeInfo().setName(tbl.getTableName());
      sd.getSerdeInfo().setParameters(new HashMap<String, String>());
      sd.getSerdeInfo().getParameters().put(org.apache.hadoop.hive.serde.Constants.SERIALIZATION_FORMAT, "9");
 
      tbl.setPartitionKeys(new ArrayList<FieldSchema>(2));
      tbl.getPartitionKeys().add(new FieldSchema("ds", org.apache.hadoop.hive.serde.Constants.DATE_TYPE_NAME, ""));
      tbl.getPartitionKeys().add(new FieldSchema("hr", org.apache.hadoop.hive.serde.Constants.INT_TYPE_NAME, ""));
 
      client.createTable(tbl);
 
      Table tbl2 = client.getTable(dbName, tblName);
      assertEquals(tbl2.getDbName(), dbName);
      assertEquals(tbl2.getTableName(), tblName);
      assertEquals(tbl2.getSd().getCols().size(), typ1.getFields().size());
      assertFalse(tbl2.getSd().isCompressed());
      assertEquals(tbl2.getSd().getNumBuckets(), 1);
 
      assertEquals("Use this for comments etc", tbl2.getSd().getParameters().get("test_param_1"));
      assertEquals("name", tbl2.getSd().getBucketCols().get(0));
 
      assertNotNull(tbl2.getPartitionKeys());
      assertEquals(2, tbl2.getPartitionKeys().size());
      assertEquals(Constants.DATE_TYPE_NAME, tbl2.getPartitionKeys().get(0).getType());
      assertEquals(Constants.INT_TYPE_NAME, tbl2.getPartitionKeys().get(1).getType());
      assertEquals("ds", tbl2.getPartitionKeys().get(0).getName());
      assertEquals("hr", tbl2.getPartitionKeys().get(1).getName());
    } catch (Exception e) {
      System.err.println(StringUtils.stringifyException(e));
      System.err.println("testComplexTable() failed.");
      throw e;
    } finally {
View Full Code Here


      public void drop_table(String dbname, String name, boolean deleteData) throws NoSuchObjectException, MetaException {
        this.incrementCounter("drop_table");
        logStartFunction("drop_table", dbname, name);
        boolean success = false;
        Path tblPath = null;
        Table tbl = null;
        try {
          getMS().openTransaction();
          // drop any partitions
          tbl = get_table(dbname, name);
          if (tbl == null) {
            throw new NoSuchObjectException(name + " doesn't exist");
          }
          if(tbl.getSd() == null  || tbl.getSd().getLocation() == null) {
            throw new MetaException("Table metadata is corrupted");
          }
          if(!getMS().dropTable(dbname, name)) {
            throw new MetaException("Unable to drop table");
          }
          success  = getMS().commitTransaction();
          tblPath = new Path(tbl.getSd().getLocation());
        } finally {
          if(!success) {
            getMS().rollbackTransaction();
          } else if(deleteData && (tblPath != null) && !isExternal(tbl)) {
            wh.deleteDir(tblPath, true);
View Full Code Here

      }

      public Table get_table(String dbname, String name) throws MetaException, NoSuchObjectException {
        this.incrementCounter("get_table");
        logStartFunction("get_table", dbname, name);
        Table t = getMS().getTable(dbname, name);
        if(t == null) {
          throw new NoSuchObjectException(dbname + "." + name + " table not found");
        }
        return t;
      }
View Full Code Here

          part = new Partition();
          part.setDbName(dbName);
          part.setTableName(tableName);
          part.setValues(part_vals);

          Table tbl = getMS().getTable(part.getDbName(), part.getTableName());
          if(tbl == null) {
            throw new InvalidObjectException("Unable to add partition because table or database do not exist");
          }

          part.setSd(tbl.getSd());
          Path partLocation = new Path(tbl.getSd().getLocation(), Warehouse.makePartName(tbl.getPartitionKeys(), part_vals));
          part.getSd().setLocation(partLocation.toString());

          Partition old_part = this.get_partition(part.getDbName(), part.getTableName(), part.getValues());
          if( old_part != null) {
            throw new AlreadyExistsException("Partition already exists:" + part);
View Full Code Here

          getMS().openTransaction();
          Partition old_part = this.get_partition(part.getDbName(), part.getTableName(), part.getValues());
          if( old_part != null) {
            throw new AlreadyExistsException("Partition already exists:" + part);
          }
          Table tbl = getMS().getTable(part.getDbName(), part.getTableName());
          if(tbl == null) {
            throw new InvalidObjectException("Unable to add partition because table or database do not exist");
          }
          // add partition
          success = getMS().addPartition(part);
View Full Code Here

        this.incrementCounter("drop_partition");
        logStartFunction("drop_partition", db_name, tbl_name);
        LOG.info("Partition values:" + part_vals);
        boolean success = false;
        Path partPath = null;
        Table tbl = null;
        try {
          getMS().openTransaction();
          Partition part = this.get_partition(db_name, tbl_name, part_vals);
          if(part == null) {
            throw new NoSuchObjectException("Partition doesn't exist. " + part_vals);
View Full Code Here

        this.incrementCounter("get_fields");
        logStartFunction("get_fields: db=" + db + "tbl=" + tableName);
        String [] names = tableName.split("\\.");
        String base_table_name = names[0];

        Table tbl;
        try {
          tbl = this.get_table(db, base_table_name);
        } catch (NoSuchObjectException e) {
          throw new UnknownTableException(e.getMessage());
        }
View Full Code Here

      client = new HiveMetaStoreClient(hiveConf);

      String dbName = "testdb";
      String tableName = "tablename";

      Table tbl = new Table();
      tbl.setTableName(tableName);
      tbl.setDbName(dbName);
      tbl.setParameters(new HashMap<String, String>());

      StorageDescriptor sd = new StorageDescriptor();
      sd.setSerdeInfo(new SerDeInfo());
      sd.getSerdeInfo().setName(tbl.getTableName());
      sd.getSerdeInfo().setSerializationLib(LazySimpleSerDe.class.getName());

      List<FieldSchema> fss = new ArrayList<FieldSchema>();
      fss.add(new FieldSchema("name", Constants.STRING_TYPE_NAME, ""));
      sd.setCols(fss);
      tbl.setSd(sd);

      tbl.setPartitionKeys(new ArrayList<FieldSchema>());
      tbl.getPartitionKeys().add(
          new FieldSchema(PART1_NAME, Constants.STRING_TYPE_NAME, ""));
      tbl.getPartitionKeys().add(
          new FieldSchema(PART2_NAME, Constants.STRING_TYPE_NAME, ""));

      client.dropTable(dbName, tableName);
      client.dropDatabase(dbName);

      client.createDatabase(dbName, "newloc");
      client.createTable(tbl);

      tbl = client.getTable(dbName, tableName);

      List<String> partValues = new ArrayList<String>();
      partValues.add("value1");
      partValues.add("value2");

      Map<String, String> part1 = new HashMap<String, String>();
      part1.put(PART1_NAME, "value1");
      part1.put(PART2_NAME, "value2");
     
      List<Map<String, String>> partitions = new ArrayList<Map<String, String>>();
      partitions.add(part1);
     
      // no partitions yet
      List<Partition> parts = client.listPartitions(dbName, tableName,
          (short) -1);
      assertTrue(parts.isEmpty());

      String partitionLocation = PART1_NAME + Path.SEPARATOR + PART2_NAME;
      // add the partitions
      for (Map<String,String> map : partitions) {
        AddPartitionDesc addPartition = new AddPartitionDesc(dbName,
            tableName, map, partitionLocation);
        Task<DDLWork> task = TaskFactory.get(new DDLWork(addPartition), hiveConf);
        task.initialize(hiveConf);
        assertEquals(0, task.execute());
      }

      // should have one
      parts = client.listPartitions(dbName, tableName, (short) -1);
      assertEquals(1, parts.size());
      Partition insertedPart = parts.get(0);
      assertEquals(tbl.getSd().getLocation() + Path.SEPARATOR + partitionLocation,
          insertedPart.getSd().getLocation());

      client.dropPartition(dbName, tableName, insertedPart.getValues());

      // add without location specified
View Full Code Here

    typ1.getFields().add(new FieldSchema("name", Constants.STRING_TYPE_NAME, ""));
    typ1.getFields().add(new FieldSchema("income", Constants.INT_TYPE_NAME, ""));
    ret = client.createType(typ1);
    assertTrue("Unable to create type " + typeName, ret);
 
    Table tbl = new Table();
    tbl.setDbName(dbName);
    tbl.setTableName(tblName);
    StorageDescriptor sd = new StorageDescriptor();
    tbl.setSd(sd);
    sd.setCols(typ1.getFields());
    sd.setCompressed(false);
    sd.setNumBuckets(1);
    sd.setParameters(new HashMap<String, String>());
    sd.getParameters().put("test_param_1", "Use this for comments etc");
    sd.setBucketCols(new ArrayList<String>(2));
    sd.getBucketCols().add("name");
    sd.setSerdeInfo(new SerDeInfo());
    sd.getSerdeInfo().setName(tbl.getTableName());
    sd.getSerdeInfo().setParameters(new HashMap<String, String>());
    sd.getSerdeInfo().getParameters().put(Constants.SERIALIZATION_FORMAT, "1");
    sd.setSortCols(new ArrayList<Order>());
 
    tbl.setPartitionKeys(new ArrayList<FieldSchema>(2));
    tbl.getPartitionKeys().add(new FieldSchema("ds", Constants.STRING_TYPE_NAME, ""));
    tbl.getPartitionKeys().add(new FieldSchema("hr", Constants.INT_TYPE_NAME, ""));
 
    client.createTable(tbl);
 
    Partition part = new Partition();
    part.setDbName(dbName);
    part.setTableName(tblName);
    part.setValues(vals);
    part.setParameters(new HashMap<String, String>());
    part.setSd(tbl.getSd());
    part.getSd().setSerdeInfo(tbl.getSd().getSerdeInfo());
    part.getSd().setLocation(tbl.getSd().getLocation() + "/part1");
 
    Partition retp = client.add_partition(part);
    assertNotNull("Unable to create partition " + part, retp);
 
    Partition part2 = client.getPartition(dbName, tblName, part.getValues());
    assertTrue("Partitions are not same",part.equals(part2));
 
    FileSystem fs = FileSystem.get(this.hiveConf);
    Path partPath = new Path(part2.getSd().getLocation());
   
    assertTrue(fs.exists(partPath));
    ret = client.dropPartition(dbName, tblName, part.getValues(), true);
    assertTrue(ret);
    assertFalse(fs.exists(partPath));
 
    // add the partition again so that drop table with a partition can be tested
    retp = client.add_partition(part);
    assertNotNull("Unable to create partition " + part, ret);
 
    client.dropTable(dbName, tblName);
 
    ret = client.dropType(typeName);
    assertTrue("Unable to drop type " + typeName, ret);

    //recreate table as external, drop partition and it should
    //still exist
    tbl.setParameters(new HashMap<String, String>());
    tbl.getParameters().put("EXTERNAL", "TRUE");
    client.createTable(tbl);
    retp = client.add_partition(part);
    assertTrue(fs.exists(partPath));
    client.dropPartition(dbName, tblName, part.getValues(), true);
    assertTrue(fs.exists(partPath));
View Full Code Here

    typ1.getFields().add(new FieldSchema("name", Constants.STRING_TYPE_NAME, ""));
    typ1.getFields().add(new FieldSchema("income", Constants.INT_TYPE_NAME, ""));
    ret = client.createType(typ1);
    assertTrue("Unable to create type " + typeName, ret);
   
    Table tbl = new Table();
    tbl.setDbName(dbName);
    tbl.setTableName(tblName);
    StorageDescriptor sd = new StorageDescriptor();
    tbl.setSd(sd);
    sd.setCols(typ1.getFields());
    sd.setCompressed(false);
    sd.setNumBuckets(1);
    sd.setParameters(new HashMap<String, String>());
    sd.getParameters().put("test_param_1", "Use this for comments etc");
    sd.setBucketCols(new ArrayList<String>(2));
    sd.getBucketCols().add("name");
    sd.setSerdeInfo(new SerDeInfo());
    sd.getSerdeInfo().setName(tbl.getTableName());
    sd.getSerdeInfo().setParameters(new HashMap<String, String>());
    sd.getSerdeInfo().getParameters().put(org.apache.hadoop.hive.serde.Constants.SERIALIZATION_FORMAT, "1");
   
    client.createTable(tbl);
   
    Table tbl2 = client.getTable(dbName, tblName);
    assertNotNull(tbl2);
    assertEquals(tbl2.getDbName(), dbName);
    assertEquals(tbl2.getTableName(), tblName);
    assertEquals(tbl2.getSd().getCols().size(), typ1.getFields().size());
    assertEquals(tbl2.getSd().isCompressed(), false);
    assertEquals(tbl2.getSd().getNumBuckets(), 1);
    assertEquals(tbl2.getSd().getLocation(), tbl.getSd().getLocation());
    assertNotNull(tbl2.getSd().getSerdeInfo());
    sd.getSerdeInfo().setParameters(new HashMap<String, String>());
    sd.getSerdeInfo().getParameters().put(org.apache.hadoop.hive.serde.Constants.SERIALIZATION_FORMAT, "1");
   
    tbl2.setTableName(tblName2);
    tbl2.setParameters(new HashMap<String, String>());
    tbl2.getParameters().put("EXTERNAL", "TRUE");
    tbl2.getSd().setLocation(tbl.getSd().getLocation() +"-2");
   
    client.createTable(tbl2);
 
    Table tbl3 = client.getTable(dbName, tblName2);
    assertNotNull(tbl3);
    assertEquals(tbl3.getDbName(), dbName);
    assertEquals(tbl3.getTableName(), tblName2);
    assertEquals(tbl3.getSd().getCols().size(), typ1.getFields().size());
    assertEquals(tbl3.getSd().isCompressed(), false);
    assertEquals(tbl3.getSd().getNumBuckets(), 1);
    assertEquals(tbl3.getSd().getLocation(), tbl2.getSd().getLocation());
   
 
    assertEquals("Use this for comments etc", tbl2.getSd().getParameters().get("test_param_1"));
    assertEquals("name", tbl2.getSd().getBucketCols().get(0));
    assertTrue("Partition key list is not empty"(tbl2.getPartitionKeys() == null) || (tbl2.getPartitionKeys().size() == 0));
View Full Code Here

TOP

Related Classes of org.apache.hadoop.hive.metastore.api.Table$Isset

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.