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

Examples of org.apache.hadoop.hive.metastore.api.Type


    client.dropDatabase(dbName);
    boolean ret = client.createDatabase(dbName, "strange_loc");
    assertTrue("Unable to create the databse " + dbName, ret);
 
    client.dropType(typeName);
    Type typ1 = new Type();
    typ1.setName(typeName);
    typ1.setFields(new ArrayList<FieldSchema>(2));
    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));
View Full Code Here


 
  public void testSimpleTypeApi() throws Exception {
    try {
    client.dropType(Constants.INT_TYPE_NAME);
   
    Type typ1 = new Type();
    typ1.setName(Constants.INT_TYPE_NAME);
    boolean ret = client.createType(typ1);
    assertTrue("Unable to create type", ret);
   
    Type typ1_2 = client.getType(Constants.INT_TYPE_NAME);
    assertNotNull(typ1_2);
    assertEquals(typ1.getName(), typ1_2.getName());
   
    ret = client.dropType(Constants.INT_TYPE_NAME);
    assertTrue("unable to drop type integer", ret);
   
    Type typ1_3 = null;
    typ1_3 = client.getType(Constants.INT_TYPE_NAME);
    assertNull("unable to drop type integer",typ1_3);
    } catch (Exception e) {
      System.err.println(StringUtils.stringifyException(e));
      System.err.println("testSimpleTypeApi() failed.");
View Full Code Here

  // TODO:pc need to enhance this with complex fields and getType_all function
  public void testComplexTypeApi() throws Exception {
    try {
    client.dropType("Person");
   
    Type typ1 = new Type();
    typ1.setName("Person");
    typ1.setFields(new ArrayList<FieldSchema>(2));
    typ1.getFields().add(new FieldSchema("name", Constants.STRING_TYPE_NAME, ""));
    typ1.getFields().add(new FieldSchema("income", Constants.INT_TYPE_NAME, ""));
    boolean ret = client.createType(typ1);
    assertTrue("Unable to create type", ret);
   
    Type typ1_2 = client.getType("Person");
    assertNotNull("type Person not found", typ1_2);
    assertEquals(typ1.getName(), typ1_2.getName());
    assertEquals(typ1.getFields().size(), typ1_2.getFields().size());
    assertEquals(typ1.getFields().get(0), typ1_2.getFields().get(0));
    assertEquals(typ1.getFields().get(1), typ1_2.getFields().get(1));
   
    client.dropType("Family");
   
    Type fam = new Type();
    fam.setName("Family");
    fam.setFields(new ArrayList<FieldSchema>(2));
    fam.getFields().add(new FieldSchema("name", Constants.STRING_TYPE_NAME, ""));
    fam.getFields().add(new FieldSchema("members", MetaStoreUtils.getListType(typ1.getName()), ""));
   
    ret = client.createType(fam);
    assertTrue("Unable to create type " + fam.getName(), ret);
   
    Type fam2 = client.getType("Family");
    assertNotNull("type Person not found", fam2);
    assertEquals(fam.getName(), fam2.getName());
    assertEquals(fam.getFields().size(), fam2.getFields().size());
    assertEquals(fam.getFields().get(0), fam2.getFields().get(0));
    assertEquals(fam.getFields().get(1), fam2.getFields().get(1));
   
    ret = client.dropType("Family");
    assertTrue("unable to drop type Family", ret);
   
    ret = client.dropType("Person");
    assertTrue("unable to drop type Person", ret);
   
    Type typ1_3 = null;
    typ1_3 = client.getType("Person");
    assertNull("unable to drop type Person",typ1_3);
    } catch (Exception e) {
      System.err.println(StringUtils.stringifyException(e));
      System.err.println("testComplexTypeApi() failed.");
View Full Code Here

    client.dropDatabase(dbName);
    boolean ret = client.createDatabase(dbName, "strange_loc");
    assertTrue("Unable to create the databse " + dbName, ret);
   
    client.dropType(typeName);
    Type typ1 = new Type();
    typ1.setName(typeName);
    typ1.setFields(new ArrayList<FieldSchema>(2));
    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");
    sd.getSerdeInfo().setSerializationLib(org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe.class.getName());
    tbl.setPartitionKeys(new ArrayList<FieldSchema>());
   
    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");
   
    List<FieldSchema> fieldSchemas = client.getFields(dbName, tblName);
    assertNotNull(fieldSchemas);
    assertEquals(fieldSchemas.size(), tbl.getSd().getCols().size());
    for (FieldSchema fs : tbl.getSd().getCols()) {
      assertTrue(fieldSchemas.contains(fs));
    }
   
    List<FieldSchema> fieldSchemasFull = client.getSchema(dbName, tblName);
    assertNotNull(fieldSchemasFull);
    assertEquals(fieldSchemasFull.size(), tbl.getSd().getCols().size()+tbl.getPartitionKeys().size());
    for (FieldSchema fs : tbl.getSd().getCols()) {
      assertTrue(fieldSchemasFull.contains(fs));
    }
    for (FieldSchema fs : tbl.getPartitionKeys()) {
      assertTrue(fieldSchemasFull.contains(fs));
    }
   
    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(tbl3.getParameters(), tbl2.getParameters());
   
View Full Code Here

      client.dropDatabase(dbName);
      boolean ret = client.createDatabase(dbName, "strange_loc");
      assertTrue("Unable to create the databse " + dbName, ret);
 
      client.dropType(typeName);
      Type typ1 = new Type();
      typ1.setName(typeName);
      typ1.setFields(new ArrayList<FieldSchema>(2));
      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");
      sd.getSerdeInfo().setSerializationLib(org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe.class.getName());
 
      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));
View Full Code Here

    if(mtype.getFields() != null) {
      for (MFieldSchema field : mtype.getFields()) {
        fields.add(new FieldSchema(field.getName(), field.getType(), field.getComment()));
      }
    }
    return new Type(mtype.getName(), mtype.getType1(), mtype.getType2(), fields);
  }
View Full Code Here

    }
    return success;
  }

  public Type getType(String typeName) {
    Type type = null;
    boolean commited = false;
    try {
      openTransaction();
      Query query = pm.newQuery(MType.class, "name == typeName");
      query.declareParameters("java.lang.String typeName");
View Full Code Here

    }
    return copy;
  }

  private Type deepCopy(Type type) {
    Type copy = null;
    if (type != null) {
      copy = new Type(type);
    }
    return copy;
  }
View Full Code Here

      Database db = new Database();
      db.setName(dbName);
      client.createDatabase(db);

      client.dropType(typeName);
      Type typ1 = new Type();
      typ1.setName(typeName);
      typ1.setFields(new ArrayList<FieldSchema>(2));
      typ1.getFields().add(
          new FieldSchema("name", Constants.STRING_TYPE_NAME, ""));
      typ1.getFields().add(
          new FieldSchema("income", Constants.INT_TYPE_NAME, ""));
      client.createType(typ1);

      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));
View Full Code Here

  public void testSimpleTypeApi() throws Exception {
    try {
      client.dropType(Constants.INT_TYPE_NAME);

      Type typ1 = new Type();
      typ1.setName(Constants.INT_TYPE_NAME);
      boolean ret = client.createType(typ1);
      assertTrue("Unable to create type", ret);

      Type typ1_2 = client.getType(Constants.INT_TYPE_NAME);
      assertNotNull(typ1_2);
      assertEquals(typ1.getName(), typ1_2.getName());

      ret = client.dropType(Constants.INT_TYPE_NAME);
      assertTrue("unable to drop type integer", ret);

      boolean exceptionThrown = false;
View Full Code Here

TOP

Related Classes of org.apache.hadoop.hive.metastore.api.Type

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.