Package org.apache.hadoop.hive.ql.plan

Examples of org.apache.hadoop.hive.ql.plan.CreateTableDesc


        Vector<ColumnInfo> colInfos = inputRR.getColumnInfos();

        // CTAS case: the file output format and serde are defined by the create table command
        // rather than taking the default value
        List<FieldSchema> field_schemas = null;
        createTableDesc tblDesc = qb.getTableDesc();
        if ( tblDesc != null )
          field_schemas = new ArrayList<FieldSchema>();

        boolean first = true;
        for (ColumnInfo colInfo:colInfos) {
          String[] nm = inputRR.reverseLookup(colInfo.getInternalName());

          if ( nm[1] != null ) { // non-null column alias
            colInfo.setAlias(nm[1]);
          }

          if ( field_schemas != null ) {
            FieldSchema col = new FieldSchema();
            if ( nm[1] != null ) {
              col.setName(colInfo.getAlias());
            } else {
              col.setName(colInfo.getInternalName());
            }
            col.setType(colInfo.getType().getTypeName());
            field_schemas.add(col);
          }

          if (!first) {
            cols = cols.concat(",");
            colTypes = colTypes.concat(":");
          }

          first = false;
          cols = cols.concat(colInfo.getInternalName());

          // Replace VOID type with string when the output is a temp table or local files.
          // A VOID type can be generated under the query:
          //
          //     select NULL from tt;
          // or
          //     insert overwrite local directory "abc" select NULL from tt;
          //
          // where there is no column type to which the NULL value should be converted.
          //
          String tName = colInfo.getType().getTypeName();
          if ( tName.equals(Constants.VOID_TYPE_NAME) )
            colTypes = colTypes.concat(Constants.STRING_TYPE_NAME);
          else
            colTypes = colTypes.concat(tName);
        }

        // update the create table descriptor with the resulting schema.
        if ( tblDesc != null )
          tblDesc.setCols(field_schemas);

        if (!ctx.isMRTmpFileURI(destStr)) {
          this.idToTableNameMap.put( String.valueOf(this.destTableId), destStr);
          currentTableId = this.destTableId;
          this.destTableId ++;
View Full Code Here


      for (Task<? extends Serializable> rootTask: rootTasks)
        generateCountersTask(rootTask);

    if ( qb.isCTAS() ) {
      // generate a DDL task and make it a dependent task of the leaf
      createTableDesc crtTblDesc = qb.getTableDesc();

      validateCreateTable(crtTblDesc);

      // Clear the output for CTAS since we don't need the output from the mapredWork, the
      // DDLWork at the tail of the chain will have the output
View Full Code Here

        e.printStackTrace();
      }
    }

    // Handle different types of CREATE TABLE command
    createTableDesc crtTblDesc = null;
    switch ( command_type ) {

      case CREATE_TABLE: // REGULAR CREATE TABLE DDL
        crtTblDesc =
          new createTableDesc(tableName, isExt, cols, partCols, bucketCols,
                              sortCols, numBuckets,
                              fieldDelim, fieldEscape,
                              collItemDelim, mapKeyDelim, lineDelim,
                              comment, inputFormat, outputFormat, location, serde,
                              mapProp, ifNotExists);

        validateCreateTable(crtTblDesc);
        rootTasks.add(TaskFactory.get(new DDLWork(getInputs(), getOutputs(), crtTblDesc), conf));
        break;

      case CTLT: // create table like <tbl_name>
        createTableLikeDesc crtTblLikeDesc =
          new createTableLikeDesc(tableName, isExt, location, ifNotExists, likeTableName);
        rootTasks.add(TaskFactory.get(new DDLWork(getInputs(), getOutputs(), crtTblLikeDesc), conf));
        break;

      case CTAS: // create table as select

        // check for existence of table. Throw an exception if it exists.
        try {
          Table tab = this.db.getTable(MetaStoreUtils.DEFAULT_DATABASE_NAME, tableName,
                                       false); // do not throw exception if table does not exist

          if ( tab != null ) {
            throw new SemanticException(ErrorMsg.TABLE_ALREADY_EXISTS.getMsg(tableName));
          }
        } catch (HiveException e) { // may be unable to get meta data
          throw new SemanticException(e);
        }

        crtTblDesc =
          new createTableDesc(tableName, isExt, cols, partCols, bucketCols,
                              sortCols, numBuckets,
                              fieldDelim, fieldEscape,
                              collItemDelim, mapKeyDelim, lineDelim,
                              comment, inputFormat, outputFormat, location, serde,
                              mapProp, ifNotExists);
View Full Code Here

    // Create the db
    Hive db;
    try {
      db = Hive.get(conf);

      createTableDesc crtTbl = work.getCreateTblDesc();
      if (crtTbl != null) {
        return createTable(db, crtTbl);
      }

      createTableLikeDesc crtTblLike = work.getCreateTblLikeDesc();
View Full Code Here

          break;
        default: assert false;
      }
    }
    if (likeTableName == null) {
      createTableDesc crtTblDesc =
        new createTableDesc(tableName, isExt, cols, partCols, bucketCols,
                            sortCols, numBuckets,
                            fieldDelim, fieldEscape,
                            collItemDelim, mapKeyDelim, lineDelim,
                            comment, inputFormat, outputFormat, location, serde,
                            mapProp, ifNotExists);
View Full Code Here

          break;
        default: assert false;
      }
    }

    createTableDesc crtTblDesc =
      new createTableDesc(tableName, isExt, cols, partCols, bucketCols,
                          sortCols, numBuckets,
                          fieldDelim, collItemDelim, mapKeyDelim, lineDelim,
                          comment, isSequenceFile, location, serde, mapProp);

    validateCreateTable(crtTblDesc);
View Full Code Here

    FileSystem fs;
    try {
      db = Hive.get(conf);
      fs = FileSystem.get(conf);

      createTableDesc crtTbl = work.getCreateTblDesc();
      if (crtTbl != null) {

        // create the table
        Table tbl = new Table(crtTbl.getTableName());
        tbl.setFields(crtTbl.getCols());
        StorageDescriptor tblStorDesc = tbl.getTTable().getSd();
        if (crtTbl.getBucketCols() != null)
          tblStorDesc.setBucketCols(crtTbl.getBucketCols());
        if (crtTbl.getSortCols() != null)
          tbl.setSortCols(crtTbl.getSortCols());
        if (crtTbl.getPartCols() != null)
          tbl.setPartCols(crtTbl.getPartCols());
        if (crtTbl.getNumBuckets() != -1)
          tblStorDesc.setNumBuckets(crtTbl.getNumBuckets());

        if (crtTbl.getSerName() != null) {
          tbl.setSerializationLib(crtTbl.getSerName());
          if (crtTbl.getMapProp() != null) {
            Iterator<Map.Entry<String, String>> iter = crtTbl.getMapProp().entrySet().iterator();
            while (iter.hasNext()) {
              Map.Entry<String, String> m = (Map.Entry)iter.next();
              tbl.setSerdeParam(m.getKey(), m.getValue());
            }
          }
        }
        else
        {
          if (crtTbl.getFieldDelim() != null)
          {
            tbl.setSerdeParam(Constants.FIELD_DELIM, crtTbl.getFieldDelim());
            tbl.setSerdeParam(Constants.SERIALIZATION_FORMAT, crtTbl.getFieldDelim());
          }
       
          if (crtTbl.getCollItemDelim() != null)
            tbl.setSerdeParam(Constants.COLLECTION_DELIM, crtTbl.getCollItemDelim());
          if (crtTbl.getMapKeyDelim() != null)
            tbl.setSerdeParam(Constants.MAPKEY_DELIM, crtTbl.getMapKeyDelim());
          if (crtTbl.getLineDelim() != null)
            tbl.setSerdeParam(Constants.LINE_DELIM, crtTbl.getLineDelim());
        }
       
        /**
         * For now, if the user specifies either the map or the collections delimiter, we infer the
         * table to DynamicSerDe/TCTLSeparatedProtocol.
         * In the future, we should infer this for any delimiters specified, but this will break older
         * hive tables, so not for now.
         */
        if (crtTbl.getCollItemDelim() != null || crtTbl.getMapKeyDelim() != null) {
          tbl.setSerializationLib(org.apache.hadoop.hive.serde2.dynamic_type.DynamicSerDe.class.getName());
          tbl.setSerdeParam(org.apache.hadoop.hive.serde.Constants.SERIALIZATION_FORMAT, org.apache.hadoop.hive.serde2.thrift.TCTLSeparatedProtocol.class.getName());
        }


        if (crtTbl.getComment() != null)
          tbl.setProperty("comment", crtTbl.getComment());
        if (crtTbl.getLocation() != null)
          tblStorDesc.setLocation(crtTbl.getLocation());

        if (crtTbl.isSequenceFile()) {
          tbl.setInputFormatClass(SequenceFileInputFormat.class);
          tbl.setOutputFormatClass(SequenceFileOutputFormat.class);
        }
        else {
          tbl.setOutputFormatClass(IgnoreKeyTextOutputFormat.class);
          tbl.setInputFormatClass(TextInputFormat.class);
        }

        if (crtTbl.isExternal())
          tbl.setProperty("EXTERNAL", "TRUE");

        // If the sorted columns is a superset of bucketed columns, store this fact. It can be later used to
        // optimize some group-by queries. Note that, the order does not matter as long as it in the first
        // 'n' columns where 'n' is the length of the bucketed columns.
View Full Code Here

TOP

Related Classes of org.apache.hadoop.hive.ql.plan.CreateTableDesc

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.