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

Examples of org.apache.hadoop.hive.serde2.objectinspector.StandardUnionObjectInspector.StandardUnion


      }
      return r;
    }
    case UNION: {
      UnionTypeInfo utype = (UnionTypeInfo) type;
      StandardUnion r = reuse == null ? new StandardUnion()
          : (StandardUnion) reuse;
      // Read the tag
      byte tag = buffer.read(invert);
      r.setTag(tag);
      r.setObject(deserialize(buffer, utype.getAllUnionObjectTypeInfos().get(tag),
          invert, null));
      return r;
    }
    default: {
      throw new RuntimeException("Unrecognized type: " + type.getCategory());
View Full Code Here


   * @param rowIndex the row index in the batch
   * @param index the cachedKeys index to write to
   */
  private void populateCachedDistinctKeys(
      VectorizedRowBatch vrg, int rowIndex, int index) throws HiveException {
    StandardUnion union;
    cachedKeys[index][numDistributionKeys] = union = new StandardUnion(
        (byte)index, new Object[distinctColIndices.get(index).size()]);
    Object[] distinctParameters = (Object[]) union.getObject();
    for (int distinctParamI = 0; distinctParamI < distinctParameters.length; distinctParamI++) {
      int distinctColIndex = distinctColIndices.get(index).get(distinctParamI);
      int batchColumn = keyEval[distinctColIndex].getOutputColumn();
      distinctParameters[distinctParamI] =
          keyWriters[distinctColIndex].writeValue(vrg.cols[batchColumn], rowIndex);
    }
    union.setTag((byte) index);
  }
View Full Code Here

  }

  @Override
  public Object evaluate(DeferredObject[] arguments) throws HiveException {
    byte tag = (byte)((IntObjectInspector)tagOI).get(arguments[0].get());
    return new StandardUnion(tag, arguments[tag + 1].get());
  }
View Full Code Here

   * Populate distinct keys part of cachedKeys for a particular row.
   * @param row the row
   * @param index the cachedKeys index to write to
   */
  private void populateCachedDistinctKeys(Object row, int index) throws HiveException {
    StandardUnion union;
    cachedKeys[index][numDistributionKeys] = union = new StandardUnion(
          (byte)index, new Object[distinctColIndices.get(index).size()]);
    Object[] distinctParameters = (Object[]) union.getObject();
    for (int distinctParamI = 0; distinctParamI < distinctParameters.length; distinctParamI++) {
      distinctParameters[distinctParamI] =
          keyEval[distinctColIndices.get(index).get(distinctParamI)].evaluate(row);
    }
    union.setTag((byte) index);
  }
View Full Code Here

      // null
      assertNull(uoi1.getField(null));
      assertEquals(-1, uoi1.getTag(null));

      // Union
      UnionObject union = new StandardUnion((byte) 0, 1);
      assertEquals(0, uoi1.getTag(union));
      assertEquals(1, uoi1.getField(union));
      assertEquals("{0:1}", SerDeUtils.getJSONString(union, uoi1));
      assertEquals(0, ObjectInspectorUtils.compare(union, uoi1,
          new StandardUnion((byte) 0, 1), uoi2));
      assertTrue(ObjectInspectorUtils.copyToStandardObject(
          union, uoi1).equals(1));

      union = new StandardUnion((byte) 1, "two");
      assertEquals(1, uoi1.getTag(union));
      assertEquals("two", uoi1.getField(union));
      assertEquals("{1:\"two\"}", SerDeUtils.getJSONString(union, uoi1));
      assertEquals(0, ObjectInspectorUtils.compare(union, uoi1,
          new StandardUnion((byte) 1, "two"), uoi2));
      assertTrue(ObjectInspectorUtils.copyToStandardObject(
          union, uoi1).equals("two"));

      union = new StandardUnion((byte) 2, true);
      assertEquals(2, uoi1.getTag(union));
      assertEquals(true, uoi1.getField(union));
      assertEquals("{2:true}", SerDeUtils.getJSONString(union, uoi1));
      assertEquals(0, ObjectInspectorUtils.compare(union, uoi1,
          new StandardUnion((byte) 2, true), uoi2));
      assertTrue(ObjectInspectorUtils.copyToStandardObject(
          union, uoi1).equals(true));

      ArrayList<Integer> iList = new ArrayList<Integer>();
      iList.add(4);
      iList.add(5);
      union = new StandardUnion((byte) 3, iList);
      assertEquals(3, uoi1.getTag(union));
      assertEquals(iList, uoi1.getField(union));
      assertEquals("{3:[4,5]}", SerDeUtils.getJSONString(union, uoi1));
      assertEquals(0, ObjectInspectorUtils.compare(union, uoi1,
          new StandardUnion((byte) 3, iList.clone()), uoi2));
      assertTrue(ObjectInspectorUtils.copyToStandardObject(
          union, uoi1).equals(iList));

      HashMap<Integer, String> map = new HashMap<Integer, String>();
      map.put(6, "six");
      map.put(7, "seven");
      map.put(8, "eight");
      union = new StandardUnion((byte) 4, map);
      assertEquals(4, uoi1.getTag(union));
      assertEquals(map, uoi1.getField(union));
      assertEquals("{4:{6:\"six\",7:\"seven\",8:\"eight\"}}",
          SerDeUtils.getJSONString(union, uoi1));
      Throwable th = null;
      try {
        ObjectInspectorUtils.compare(union, uoi1,
            new StandardUnion((byte) 4, map.clone()), uoi2);
      } catch (Throwable t) {
        th = t;
      }
      assertNotNull(th);
      assertEquals("Compare on map type not supported!", th.getMessage());
      assertTrue(ObjectInspectorUtils.copyToStandardObject(
          union, uoi1).equals(map));


      ArrayList<Object> struct = new ArrayList<Object>(2);
      struct.add(9.0);
      struct.add(10L);
      union = new StandardUnion((byte) 5, struct);
      assertEquals(5, uoi1.getTag(union));
      assertEquals(struct, uoi1.getField(union));
      assertEquals("{5:{\"mydouble\":9.0,\"mylong\":10}}",
          SerDeUtils.getJSONString(union, uoi1));
      assertEquals(0, ObjectInspectorUtils.compare(union, uoi1,
          new StandardUnion((byte) 5, struct.clone()), uoi2));
      assertTrue(ObjectInspectorUtils.copyToStandardObject(
          union, uoi1).equals(struct));

    } catch (Throwable e) {
      e.printStackTrace();
View Full Code Here

          for (int j = 0; j < distinctParameters.length; j++) {
            distinctParameters[j] =
              keyEval[distinctColIndices.get(i).get(j)].evaluate(row);
          }
          cachedKeys[i][numDistributionKeys] =
              new StandardUnion((byte)i, distinctParameters);
        }
      } else {
        // no distinct key
        System.arraycopy(distributionKeys, 0, cachedKeys[0], 0, numDistributionKeys);
      }
View Full Code Here

   * Populate distinct keys part of cachedKeys for a particular row.
   * @param row the row
   * @param index the cachedKeys index to write to
   */
  private void populateCachedDistinctKeys(Object row, int index) throws HiveException {
    StandardUnion union;
    cachedKeys[index][numDistributionKeys] = union = new StandardUnion(
          (byte)index, new Object[distinctColIndices.get(index).size()]);
    Object[] distinctParameters = (Object[]) union.getObject();
    for (int distinctParamI = 0; distinctParamI < distinctParameters.length; distinctParamI++) {
      distinctParameters[distinctParamI] =
          keyEval[distinctColIndices.get(index).get(distinctParamI)].evaluate(row);
    }
    union.setTag((byte) index);
  }
View Full Code Here

      throw new IllegalArgumentException(
          "Invalid objectinspector found. Expected LazyUnionObjectInspector, Found "
              + objectInspector.getClass());
    }

    StandardUnion standardUnion = (StandardUnion) obj;

    // Grab the tag and the field
    byte tag = standardUnion.getTag();
    Object field = standardUnion.getObject();

    ObjectInspector fieldOI =
        ((LazyUnionObjectInspector) objectInspector).getObjectInspectors().get(tag);

    // convert to lazy object
View Full Code Here

      }
      return r;
    }
    case UNION: {
      UnionTypeInfo utype = (UnionTypeInfo) type;
      StandardUnion r = reuse == null ? new StandardUnion()
          : (StandardUnion) reuse;
      // Read the tag
      byte tag = buffer.read(invert);
      r.setTag(tag);
      r.setObject(deserialize(buffer, utype.getAllUnionObjectTypeInfos().get(tag),
          invert, null));
      return r;
    }
    default: {
      throw new RuntimeException("Unrecognized type: " + type.getCategory());
View Full Code Here

          for (int j = 0; j < distinctParameters.length; j++) {
            distinctParameters[j] =
              keyEval[distinctColIndices.get(i).get(j)].evaluate(row);
          }
          cachedKeys[i][numDistributionKeys] =
              new StandardUnion((byte)i, distinctParameters);
        }
      } else {
        // no distinct key
        System.arraycopy(distributionKeys, 0, cachedKeys[0], 0, numDistributionKeys);
      }
View Full Code Here

TOP

Related Classes of org.apache.hadoop.hive.serde2.objectinspector.StandardUnionObjectInspector.StandardUnion

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.