Package org.apache.hcatalog.data.schema

Examples of org.apache.hcatalog.data.schema.HCatSchema


      } catch(HCatException he) {
          // pass the message to the user - essentially something about the table
          // information passed to HCatOutputFormat was not right
          throw new PigException(he.getMessage(), PigHCatUtil.PIG_EXCEPTION_CODE, he);
      }
      HCatSchema hcatTblSchema = HCatOutputFormat.getTableSchema(job);
      try{
        doSchemaValidations(pigSchema, hcatTblSchema);
      } catch(HCatException he){
        throw new FrontendException(he.getMessage(), PigHCatUtil.PIG_EXCEPTION_CODE, he);
      }
View Full Code Here


  public static HCatSchema extractSchemaFromStorageDescriptor(StorageDescriptor sd) throws HCatException {
      if (sd == null){
          throw new HCatException("Cannot construct partition info from an empty storage descriptor.");
        }
        HCatSchema schema = new HCatSchema(HCatUtil.getHCatFieldSchemaList(sd.getCols()));
        return schema;
  }
View Full Code Here

  public static Table getTable(HiveMetaStoreClient client, String dbName, String tableName) throws Exception{
    return client.getTable(dbName,tableName);
  }

  public static HCatSchema getTableSchemaWithPtnCols(Table table) throws IOException{
      HCatSchema tableSchema = extractSchemaFromStorageDescriptor(table.getSd());

      if( table.getPartitionKeys().size() != 0 ) {

        // add partition keys to table schema
        // NOTE : this assumes that we do not ever have ptn keys as columns inside the table schema as well!
        for (FieldSchema fs : table.getPartitionKeys()){
            tableSchema.append(HCatSchemaUtils.getHCatFieldSchema(fs));
        }
      }
      return tableSchema;
    }
View Full Code Here

      List<HCatFieldSchema> partKeys = new ArrayList<HCatFieldSchema>();
      partKeys.add(HCatSchemaUtils.getHCatFieldSchema(new FieldSchema("emp_country",
          Constants.STRING_TYPE_NAME, "")));
      partKeys.add(HCatSchemaUtils.getHCatFieldSchema(new FieldSchema("emp_state",
          Constants.STRING_TYPE_NAME, "")));
      HCatSchema partitionSchema = new HCatSchema(partKeys);

      List<String> partitionVals = new ArrayList<String>();
      partitionVals.add("IN");
      partitionVals.add("TN");
View Full Code Here

        Constants.STRING_TYPE_NAME, "")));
    columns.add(HCatSchemaUtils.getHCatFieldSchema(new FieldSchema("emp_dob",
        Constants.STRING_TYPE_NAME, "")));
    columns.add(HCatSchemaUtils.getHCatFieldSchema(new FieldSchema("emp_sex",
        Constants.STRING_TYPE_NAME, "")));
    schema = new HCatSchema(columns);

    fs = new LocalFileSystem();
    fs.initialize(fs.getWorkingDirectory().toUri(), new Configuration());
    outputLocation = new Path(fs.getWorkingDirectory(), "tmp/exports");
    if (fs.exists(outputLocation)) {
View Full Code Here

        }
        List<Partition> partitions = tp.getValue();
        partInfoList = filterPartitions(partitionFilter, partitions, table.getPartitionKeys());
      } else {
        partInfoList = new ArrayList<PartInfo>(1);
        HCatSchema schema = new HCatSchema(HCatUtil.getHCatFieldSchemaList(table.getSd().getCols()));
        Map<String,String> parameters = table.getParameters();
        String inputStorageDriverClass = null;
        if (parameters.containsKey(HCatConstants.HCAT_ISD_CLASS)){
          inputStorageDriverClass = parameters.get(HCatConstants.HCAT_ISD_CLASS);
        }else{
View Full Code Here

      }
      if (pigSchema == null) {
        throw new FrontendException("Schema for data cannot be determined.",
            PigHCatUtil.PIG_EXCEPTION_CODE);
      }
      HCatSchema hcatTblSchema = new HCatSchema(new ArrayList<HCatFieldSchema>());
      try {
        doSchemaValidations(pigSchema, hcatTblSchema);
      } catch (HCatException he) {
        throw new FrontendException(he.getMessage(), PigHCatUtil.PIG_EXCEPTION_CODE, he);
      }

      List<HCatFieldSchema> hcatFields = new ArrayList<HCatFieldSchema>();
      List<String> partVals = new ArrayList<String>();
      for (String key : partitions.keySet()) {
        hcatFields.add(new HCatFieldSchema(key, HCatFieldSchema.Type.STRING, ""));
        partVals.add(partitions.get(key));
      }

      HCatSchema outputSchema = convertPigSchemaToHCatSchema(pigSchema,
          hcatTblSchema);
      LOG.debug("Pig Schema '" + pigSchema.toString() + "' was converted to HCatSchema '"
          + outputSchema);
      HCatEximOutputFormat.setOutput(job,
          dbname, tablename,
          outputLocation,
          new HCatSchema(hcatFields),
          partVals,
          outputSchema);
      p.setProperty(COMPUTED_OUTPUT_SCHEMA, ObjectSerializer.serialize(outputSchema));
      p.setProperty(HCatConstants.HCAT_KEY_OUTPUT_INFO,
          config.get(HCatConstants.HCAT_KEY_OUTPUT_INFO));
View Full Code Here

      // else - this means pig's optimizer never invoked the pushProjection
      // method - so we need all fields and hence we should not call the
      // setOutputSchema on HCatInputFormat
      if (HCatUtil.checkJobContextIfRunningFromBackend(job)){
        try {
          HCatSchema hcatTableSchema = (HCatSchema) props.get(HCatConstants.HCAT_TABLE_SCHEMA);
          outputSchema = hcatTableSchema;
        } catch (Exception e) {
          throw new IOException(e);
        }
      }
View Full Code Here

  @Override
  public ResourceSchema getSchema(String location, Job job) throws IOException {
    Table table = phutil.getTable(location,
        hcatServerUri!=null?hcatServerUri:PigHCatUtil.getHCatServerUri(job),
            PigHCatUtil.getHCatServerPrincipal(job));
    HCatSchema hcatTableSchema = HCatUtil.getTableSchemaWithPtnCols(table);
    try {
      PigHCatUtil.validateHCatTableSchemaFollowsPigRules(hcatTableSchema);
    } catch (IOException e){
      throw new PigException(
          "Table schema incompatible for reading through HCatLoader :" + e.getMessage()
          + ";[Table schema was "+ hcatTableSchema.toString() +"]"
          ,PigHCatUtil.PIG_EXCEPTION_CODE, e);
    }
    storeInUDFContext(signature, HCatConstants.HCAT_TABLE_SCHEMA, hcatTableSchema);
    outputSchema = hcatTableSchema;
    return PigHCatUtil.getResourceSchema(hcatTableSchema);
View Full Code Here

        // Find out if we need to throw away the tuple or not.
        if(type == DataType.BAG && removeTupleFromBag(tableSchema, fSchema)){
          List<HCatFieldSchema> arrFields = new ArrayList<HCatFieldSchema>(1);
          arrFields.add(getHCatFSFromPigFS(fSchema.schema.getField(0).schema.getField(0), tableSchema));
          hcatFSchema = new HCatFieldSchema(fSchema.alias, Type.ARRAY, new HCatSchema(arrFields), null);
      }
      else{
          hcatFSchema = getHCatFSFromPigFS(fSchema, tableSchema);
      }
      fieldSchemas.add(hcatFSchema);
      } catch (HCatException he){
          throw new FrontendException(he.getMessage(),PigHCatUtil.PIG_EXCEPTION_CODE,he);
      }
    }

    return new HCatSchema(fieldSchemas);
  }
View Full Code Here

TOP

Related Classes of org.apache.hcatalog.data.schema.HCatSchema

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.