Search in sources :

Example 6 with Schema

use of org.apache.hadoop.hive.metastore.api.Schema in project hive by apache.

the class TestCliDriverMethods method testThatCliDriverPrintsHeaderForCommandsWithSchema.

// 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);
}
Also used : PrintStream(java.io.PrintStream) Schema(org.apache.hadoop.hive.metastore.api.Schema) FieldSchema(org.apache.hadoop.hive.metastore.api.FieldSchema) FieldSchema(org.apache.hadoop.hive.metastore.api.FieldSchema) ArrayList(java.util.ArrayList) Matchers.anyString(org.mockito.Matchers.anyString)

Example 7 with Schema

use of org.apache.hadoop.hive.metastore.api.Schema in project hive by apache.

the class Driver method getSchema.

/**
   * Get a Schema with fields represented with native Hive types
   */
private static Schema getSchema(BaseSemanticAnalyzer sem, HiveConf conf) {
    Schema schema = null;
    // 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();
        // 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(conf));
            } 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;
}
Also used : Schema(org.apache.hadoop.hive.metastore.api.Schema) FieldSchema(org.apache.hadoop.hive.metastore.api.FieldSchema) FieldSchema(org.apache.hadoop.hive.metastore.api.FieldSchema) PrunedPartitionList(org.apache.hadoop.hive.ql.parse.PrunedPartitionList) ArrayList(java.util.ArrayList) ValidTxnList(org.apache.hadoop.hive.common.ValidTxnList) List(java.util.List) LinkedList(java.util.LinkedList) TableDesc(org.apache.hadoop.hive.ql.plan.TableDesc) LockException(org.apache.hadoop.hive.ql.lockmgr.LockException) IOException(java.io.IOException) HiveException(org.apache.hadoop.hive.ql.metadata.HiveException) AuthorizationException(org.apache.hadoop.hive.ql.metadata.AuthorizationException) FetchTask(org.apache.hadoop.hive.ql.exec.FetchTask)

Aggregations

Schema (org.apache.hadoop.hive.metastore.api.Schema)7 FieldSchema (org.apache.hadoop.hive.metastore.api.FieldSchema)6 IOException (java.io.IOException)3 PrintStream (java.io.PrintStream)2 ArrayList (java.util.ArrayList)2 LockException (org.apache.hadoop.hive.ql.lockmgr.LockException)2 AuthorizationException (org.apache.hadoop.hive.ql.metadata.AuthorizationException)2 HiveException (org.apache.hadoop.hive.ql.metadata.HiveException)2 TableSchema (org.apache.hive.service.cli.TableSchema)2 FileNotFoundException (java.io.FileNotFoundException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 ValidTxnList (org.apache.hadoop.hive.common.ValidTxnList)1 FetchTask (org.apache.hadoop.hive.ql.exec.FetchTask)1 PrunedPartitionList (org.apache.hadoop.hive.ql.parse.PrunedPartitionList)1 TableDesc (org.apache.hadoop.hive.ql.plan.TableDesc)1 CommandProcessorResponse (org.apache.hadoop.hive.ql.processors.CommandProcessorResponse)1 OperationLog (org.apache.hadoop.hive.ql.session.OperationLog)1 HiveSQLException (org.apache.hive.service.cli.HiveSQLException)1