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

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


      client.execute("load data local inpath '" + dataFilePath.toString() + "' into table " + tableName);
      client.execute("select count(1) as cnt from " + tableName);
      String row = client.fetchOne();
      assertEquals(row, "500");
     
      Schema hiveSchema = client.getSchema();
      List<FieldSchema> listFields = hiveSchema.getFieldSchemas();
      assertEquals(listFields.size(), 1);
      assertEquals(listFields.get(0).getName(), "cnt");
      assertEquals(listFields.get(0).getType(), "bigint");
     
      Schema thriftSchema = client.getThriftSchema();
      List<FieldSchema> listThriftFields = thriftSchema.getFieldSchemas();
      assertEquals(listThriftFields.size(), 1);
      assertEquals(listThriftFields.get(0).getName(), "cnt");
      assertEquals(listThriftFields.get(0).getType(), "i64");
     
      client.execute("drop table " + tableName);
View Full Code Here


    client.execute("load data local inpath '" + dataFilePath.toString() + "' into table " + tableName);
   
    // Command not part of HiveQL -  verify no results
    client.execute("SET hive.mapred.mode = nonstrict");
   
    Schema schema = client.getSchema();
    assertEquals(schema.getFieldSchemasSize(), 0);
    assertEquals(schema.getPropertiesSize(), 0);
   
    Schema thriftschema = client.getThriftSchema();
    assertEquals(thriftschema.getFieldSchemasSize(), 0);
    assertEquals(thriftschema.getPropertiesSize(), 0);
   
    assertEquals(client.fetchOne(), "");
    assertEquals(client.fetchN(10).size(), 0);
    assertEquals(client.fetchAll().size(), 0);
   
    // Execute Hive query and fetch
    client.execute("select * from " + tableName + " limit 10");
    String row = client.fetchOne();
   
    // Re-execute command not part of HiveQL - verify still no results
    client.execute("SET hive.mapred.mode = nonstrict");
   
    schema = client.getSchema();
    assertEquals(schema.getFieldSchemasSize(), 0);
    assertEquals(schema.getPropertiesSize(), 0);
   
    thriftschema = client.getThriftSchema();
    assertEquals(thriftschema.getFieldSchemasSize(), 0);
    assertEquals(thriftschema.getPropertiesSize(), 0);
   
    assertEquals(client.fetchOne(), "");
    assertEquals(client.fetchN(10).size(), 0);
    assertEquals(client.fetchAll().size(), 0);

View Full Code Here

 
  /**
   * Get a Schema with fields represented with native Hive types
   */
  public Schema getSchema() throws Exception {
    Schema schema;
    try {
      if (plan != null && plan.getPlan().getFetchTask() != null) {
        BaseSemanticAnalyzer sem = plan.getPlan();

        if (!sem.getFetchTaskInit()) {
          sem.setFetchTaskInit(true);
          sem.getFetchTask().initialize(conf);
        }
        FetchTask ft = (FetchTask) sem.getFetchTask();

        tableDesc td = ft.getTblDesc();
        // partitioned tables don't have tableDesc set on the FetchTask. Instead
        // they have a list of PartitionDesc objects, each with a table desc. Let's
        // try to fetch the desc for the first partition and use it's deserializer.
        if (td == null && ft.getWork() != null && ft.getWork().getPartDesc() != null) {
          if (ft.getWork().getPartDesc().size() > 0) {
            td = ft.getWork().getPartDesc().get(0).getTableDesc();
          }
        }

        if (td == null) {
          throw new Exception("No table description found for fetch task: " + ft);
        }
        String tableName = "result";
        List<FieldSchema> lst = MetaStoreUtils.getFieldsFromDeserializer(
            tableName, td.getDeserializer());
        schema = new Schema(lst, null);
      }
      else {
        schema = new Schema();
      }
    }
    catch (Exception e) {
      e.printStackTrace();
      throw e;
View Full Code Here

 
  /**
   * Get a Schema with fields represented with Thrift DDL types
   */
  public Schema getThriftSchema() throws Exception {
    Schema schema;   
    try {
      schema = this.getSchema();
      if (schema != null) {
      List<FieldSchema> lst = schema.getFieldSchemas();
      // Go over the schema and convert type to thrift type
      if (lst != null) {
        for (FieldSchema f : lst) {
          f.setType(MetaStoreUtils.typeToThriftType(f.getType()))
          }    
View Full Code Here

  /**
   * Instantiate the dynamic serde used to deserialize the result row
   */
  public void initDynamicSerde() throws SQLException {
    try {
      Schema fullSchema = client.getThriftSchema();
      List<FieldSchema> schema = fullSchema.getFieldSchemas();
      columnNames = new ArrayList<String>();
      columnTypes = new ArrayList<String>();
     
      String serDDL;

View Full Code Here

// code for the script-based testing
public class TestCliDriverMethods extends TestCase {

  // If the command has an associated schema, make sure it gets printed to use
  public void testThatCliDriverPrintsHeaderForCommandsWithSchema() throws CommandNeedRetryException {
    Schema mockSchema = mock(Schema.class);
    List<FieldSchema> fieldSchemas = new ArrayList<FieldSchema>();
    String fieldName = "FlightOfTheConchords";
    fieldSchemas.add(new FieldSchema(fieldName, "type", "comment"));

    when(mockSchema.getFieldSchemas()).thenReturn(fieldSchemas);

    PrintStream mockOut = headerPrintingTestDriver(mockSchema);
    // Should have printed out the header for the field schema
    verify(mockOut, times(1)).print(fieldName);
  }
View Full Code Here

    verify(mockOut, times(1)).print(fieldName);
  }

  // If the command has no schema, make sure nothing is printed
  public void testThatCliDriverPrintsNoHeaderForCommandsWithNoSchema() throws CommandNeedRetryException {
    Schema mockSchema = mock(Schema.class);
    when(mockSchema.getFieldSchemas()).thenReturn(null);

    PrintStream mockOut = headerPrintingTestDriver(mockSchema);
    // Should not have tried to print any thing.
    verify(mockOut, never()).print(anyString());
  }
View Full Code Here

    /**
     * Return the Hive schema of the query result.
     */
    public Schema getSchema() throws HiveServerException, TException {
      if (!isHiveQuery) {
        Schema schema = response.getSchema();
        if (schema == null) {
          // Return empty schema if the last command was not a Hive query
          return new Schema();
        }
        else {
          return schema;
        }
      }

      assert driver != null: "getSchema() is called on a Hive query and driver is NULL.";

      try {
        Schema schema = driver.getSchema();
        if (schema == null) {
          schema = new Schema();
        }
        LOG.info("Returning schema: " + schema);
        return schema;
      } catch (Exception e) {
        LOG.error(e.toString());
View Full Code Here

     * Return the Thrift schema of the query result.
     */
    public Schema getThriftSchema() throws HiveServerException, TException {
      if (!isHiveQuery) {
        // Return empty schema if the last command was not a Hive query
        return new Schema();
      }

      assert driver != null: "getThriftSchema() is called on a Hive query and driver is NULL.";

      try {
        Schema schema = driver.getThriftSchema();
        if (schema == null) {
          schema = new Schema();
        }
        LOG.info("Returning schema: " + schema);
        return schema;
      } catch (Exception e) {
        LOG.error(e.toString());
View Full Code Here

  /**
   * Get a Schema with fields represented with native Hive types
   */
  public static Schema getSchema(BaseSemanticAnalyzer sem, HiveConf conf) {
    Schema schema = null;

    // If we have a plan, prefer its logical result schema if it's
    // available; otherwise, try digging out a fetch task; failing that,
    // give up.
    if (sem == null) {
      // can't get any info without a plan
    } else if (sem.getResultSchema() != null) {
      List<FieldSchema> lst = sem.getResultSchema();
      schema = new Schema(lst, null);
    } else if (sem.getFetchTask() != null) {
      FetchTask ft = sem.getFetchTask();
      TableDesc td = ft.getTblDesc();
      // partitioned tables don't have tableDesc set on the FetchTask. Instead
      // they have a list of PartitionDesc objects, each with a table desc.
      // Let's
      // try to fetch the desc for the first partition and use it's
      // deserializer.
      if (td == null && ft.getWork() != null && ft.getWork().getPartDesc() != null) {
        if (ft.getWork().getPartDesc().size() > 0) {
          td = ft.getWork().getPartDesc().get(0).getTableDesc();
        }
      }

      if (td == null) {
        LOG.info("No returning schema.");
      } else {
        String tableName = "result";
        List<FieldSchema> lst = null;
        try {
          lst = MetaStoreUtils.getFieldsFromDeserializer(tableName, td.getDeserializer());
        } catch (Exception e) {
          LOG.warn("Error getting schema: "
              + org.apache.hadoop.util.StringUtils.stringifyException(e));
        }
        if (lst != null) {
          schema = new Schema(lst, null);
        }
      }
    }
    if (schema == null) {
      schema = new Schema();
    }
    LOG.info("Returning Hive schema: " + schema);
    return schema;
  }
View Full Code Here

TOP

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

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.