Package org.apache.hadoop.hive.serde2.objectinspector

Examples of org.apache.hadoop.hive.serde2.objectinspector.StructObjectInspector


    return genConvertCol(dest, qb, tab, table_desc, input, posns, convert);
  }

  private ArrayList<ExprNodeDesc> genConvertCol(String dest, QB qb, Table tab, TableDesc table_desc, Operator input,
                                                List<Integer> posns, boolean convert) throws SemanticException {
    StructObjectInspector oi = null;
    try {
      Deserializer deserializer = table_desc.getDeserializerClass()
          .newInstance();
      deserializer.initialize(conf, table_desc.getProperties());
      oi = (StructObjectInspector) deserializer.getObjectInspector();
    } catch (Exception e) {
      throw new SemanticException(e);
    }

    List<? extends StructField> tableFields = oi.getAllStructFieldRefs();
    ArrayList<ColumnInfo> rowFields = opParseCtx.get(input).getRowResolver()
        .getColumnInfos();

    // Check column type
    int columnNumber = posns.size();
View Full Code Here


    }

    if (top == null) {
      rwsch = new RowResolver();
      try {
        StructObjectInspector rowObjectInspector = (StructObjectInspector) tab
            .getDeserializer().getObjectInspector();
        List<? extends StructField> fields = rowObjectInspector
            .getAllStructFieldRefs();
        for (int i = 0; i < fields.size(); i++) {
          rwsch.put(alias, fields.get(i).getFieldName(), new ColumnInfo(fields
              .get(i).getFieldName(), TypeInfoUtils
              .getTypeInfoFromObjectInspector(fields.get(i)
View Full Code Here

      InspectableObject io = new InspectableObject();
      for(int i=0; i<5; i++) {
        cdop.retrieve(io);
        System.out.println("[" + i + "] io.o=" + io.o);
        System.out.println("[" + i + "] io.oi=" + io.oi);
        StructObjectInspector soi = (StructObjectInspector)io.oi;
        assert(soi != null);
        StructField a = soi.getStructFieldRef("a");
        StructField b = soi.getStructFieldRef("b");
        assertEquals(""+(i+1), soi.getStructFieldData(io.o, a));
        assertEquals((i) + "1", soi.getStructFieldData(io.o, b));
      }

      System.out.println("Script Operator ok");

    } catch (Throwable e) {
View Full Code Here

    for(String key: partKeys) {
      partNames.add(key);
      partValues.add(partSpec.get(key));
      partObjectInspectors.add(ObjectInspectorFactory.getStandardPrimitiveObjectInspector(String.class));
    }
    StructObjectInspector partObjectInspector = ObjectInspectorFactory.getStandardStructObjectInspector(partNames, partObjectInspectors);
    rowObjectInspector = (StructObjectInspector)serde.getObjectInspector();
   
    rowWithPart[1] = partValues;
    rowObjectInspector = ObjectInspectorFactory.getUnionStructObjectInspector(Arrays.asList(new StructObjectInspector[]{
                                                                                              rowObjectInspector, partObjectInspector}));
View Full Code Here

    String [] names = tableName.split("\\.");
    String last_name = names[names.length-1];
    for(int i = 1; i < names.length; i++) {

      if (oi instanceof StructObjectInspector) {
        StructObjectInspector soi = (StructObjectInspector)oi;
        StructField sf = soi.getStructFieldRef(names[i]);
        if (sf == null) {
          throw new MetaException("Invalid Field " + names[i]);
        } else {
          oi = sf.getFieldObjectInspector();
        }
View Full Code Here

   * Generate the conversion SelectOperator that converts the columns into
   * the types that are expected by the table_desc.
   */
  Operator genConversionSelectOperator(String dest, QB qb,
      Operator input, tableDesc table_desc) throws SemanticException {
    StructObjectInspector oi = null;
    try {
      Deserializer deserializer = table_desc.getDeserializerClass().newInstance();
      deserializer.initialize(null, table_desc.getProperties());
      oi = (StructObjectInspector) deserializer.getObjectInspector();
    } catch (Exception e) {
      throw new SemanticException(e);
    }
   
    // Check column number
    List<? extends StructField> tableFields = oi.getAllStructFieldRefs();
    Vector<ColumnInfo> rowFields = opParseCtx.get(input).getRR().getColumnInfos();
    if (tableFields.size() != rowFields.size()) {
      String reason = "Table " + dest + " has " + tableFields.size() + " columns but query has "
          + rowFields.size() + " columns.";
      throw new SemanticException(ErrorMsg.TARGET_TABLE_COLUMN_MISMATCH.getMsg(
View Full Code Here

      top = dummySel;
  
    if (top == null) {   
      rwsch = new RowResolver();
      try {
        StructObjectInspector rowObjectInspector = (StructObjectInspector)tab.getDeserializer().getObjectInspector();
        List<? extends StructField> fields = rowObjectInspector.getAllStructFieldRefs();
        for (int i=0; i<fields.size(); i++) {
          rwsch.put(alias, fields.get(i).getFieldName(),
                    new ColumnInfo(fields.get(i).getFieldName(),
                                   TypeInfoUtils.getTypeInfoFromObjectInspector(fields.get(i).getFieldObjectInspector())));
        }
View Full Code Here

        for(int i =  1; i < names.length; i++) {
          if (!(oi instanceof StructObjectInspector)) {
            oi = s.getObjectInspector();
            break;
          }
          StructObjectInspector soi = (StructObjectInspector)oi;
          StructField sf = soi.getStructFieldRef(names[i]);
          if (sf == null) {
            // If invalid field, then return the schema of the table
            oi = s.getObjectInspector();
            break;
          } else {
View Full Code Here

              partNames.add(key);
              partValues.add(partSpec.get(key));
              partObjectInspectors.add(
                  ObjectInspectorFactory.getStandardPrimitiveObjectInspector(String.class));
            }
            StructObjectInspector partObjectInspector = ObjectInspectorFactory.getStandardStructObjectInspector(partNames, partObjectInspectors);
           
            rowWithPart = new Object[2];
            rowWithPart[1] = partValues;
            rowObjectInspector = ObjectInspectorFactory.getUnionStructObjectInspector(
                Arrays.asList(new StructObjectInspector[]{
View Full Code Here

    LinkedHashSet<Partition> true_parts = new LinkedHashSet<Partition>();
    LinkedHashSet<Partition> unkn_parts = new LinkedHashSet<Partition>();

    try {
      StructObjectInspector rowObjectInspector = (StructObjectInspector)this.tab.getDeserializer().getObjectInspector();
      Object[] rowWithPart = new Object[2];
      InspectableObject inspectableObject = new InspectableObject();
    
      ExprNodeEvaluator evaluator = null;
      if (this.prunerExpr != null)
        evaluator = ExprNodeEvaluatorFactory.get(this.prunerExpr);
      for(Partition part: Hive.get().getPartitions(this.tab)) {
        // Set all the variables here
        LinkedHashMap<String, String> partSpec = part.getSpec();

        // Create the row object
        ArrayList<String> partNames = new ArrayList<String>();
        ArrayList<String> partValues = new ArrayList<String>();
        ArrayList<ObjectInspector> partObjectInspectors = new ArrayList<ObjectInspector>();
        for(Map.Entry<String,String>entry : partSpec.entrySet()) {
          partNames.add(entry.getKey());
          partValues.add(entry.getValue());
          partObjectInspectors.add(ObjectInspectorFactory.getStandardPrimitiveObjectInspector(String.class));
        }
        StructObjectInspector partObjectInspector = ObjectInspectorFactory.getStandardStructObjectInspector(partNames, partObjectInspectors);
       
        rowWithPart[1] = partValues;
        ArrayList<StructObjectInspector> ois = new ArrayList<StructObjectInspector>(2);
        ois.add(rowObjectInspector);
        ois.add(partObjectInspector);
        StructObjectInspector rowWithPartObjectInspector = ObjectInspectorFactory.getUnionStructObjectInspector(ois);
       
        // evaluate the expression tree
        if (evaluator != null) {
          evaluator.evaluate(rowWithPart, rowWithPartObjectInspector, inspectableObject);
          LOG.trace("prune result for partition " + partSpec + ": " + inspectableObject.o);
View Full Code Here

TOP

Related Classes of org.apache.hadoop.hive.serde2.objectinspector.StructObjectInspector

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.