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

Examples of org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorConverters.Converter


      // Create the converters
      conversionNeeded = false;
      converters = new Converter[parameterOIs.length];
      for (int i = 0; i < parameterOIs.length; i++) {
        Converter pc = ObjectInspectorConverters.getConverter(parameterOIs[i],
            methodParameterOIs[i]);
        converters[i] = pc;
        // Conversion is needed?
        conversionNeeded = conversionNeeded
            || (!(pc instanceof IdentityConverter));
View Full Code Here


    SerDe oSerDe = qDef.getOutput().getSerDe();
    Object[] output = new Object[cols.size()];

    WhereDef whDef = qDef.getWhere();
    boolean applyWhere = whDef != null;
    Converter whConverter = !applyWhere ? null
        : ObjectInspectorConverters
            .getConverter(
                whDef.getOI(),
                PrimitiveObjectInspectorFactory.javaBooleanObjectInspector);
    ExprNodeEvaluator whCondEval = !applyWhere ? null : whDef
        .getExprEvaluator();

    Writable value = null;
    PartitionIterator<Object> pItr = oPart.iterator();
    RuntimeUtils.connectLeadLagFunctionsToPartition(qDef, pItr);
    while (pItr.hasNext())
    {
      int colCnt = 0;
      ArrayList selectList = new ArrayList();
      Object oRow = pItr.next();

      if (applyWhere)
      {
        Object whCond = null;
        try
        {
          whCond = whCondEval.evaluate(oRow);
          whCond = whConverter.convert(whCond);
        }
        catch (HiveException he)
        {
          throw new WindowingException(he);
        }
View Full Code Here

    }
   
    queue.add(ObjectInspectorUtils.copyToStandardObject(value,argumentOIs[1],ObjectInspectorCopyOption.JAVA));
    prevHash=ObjectInspectorUtils.copyToStandardObject(hash, argumentOIs[0],ObjectInspectorCopyOption.JAVA);
    if (queue.size()==offset+1) {
      Converter converter = ObjectInspectorConverters.getConverter(valueStandardOI, resultOI);
      return converter.convert(queue.remove(0));
    }
    return defaultValue;
  }
View Full Code Here

      doubleResult.set(0);
    }

    prevHash=ObjectInspectorUtils.copyToStandardObject(hash,hashOI, ObjectInspectorCopyOption.JAVA);

    Converter converter = ObjectInspectorConverters.getConverter(valueOI, resultOI);
    if(resultOI.getTypeName()==Constants.DOUBLE_TYPE_NAME){
      DoubleWritable valueW = (DoubleWritable)converter.convert(value);
      doubleResult.set(doubleResult.get()+valueW.get());
      return doubleResult;
    }
    LongWritable valueW = (LongWritable)converter.convert(value);
    longResult.set(longResult.get()+valueW.get());
    return longResult;
  }
View Full Code Here

public class TestObjectInspectorConverters extends TestCase {

  public void testObjectInspectorConverters() throws Throwable {
    try {
      // Boolean
      Converter booleanConverter = ObjectInspectorConverters.getConverter(
          PrimitiveObjectInspectorFactory.javaIntObjectInspector,
          PrimitiveObjectInspectorFactory.writableBooleanObjectInspector);
      assertEquals("BooleanConverter", new BooleanWritable(false),
          booleanConverter.convert(Integer.valueOf(0)));
      assertEquals("BooleanConverter", new BooleanWritable(true),
          booleanConverter.convert(Integer.valueOf(1)));
      assertEquals("BooleanConverter", null, booleanConverter.convert(null));

      // Byte
      Converter byteConverter = ObjectInspectorConverters.getConverter(
          PrimitiveObjectInspectorFactory.javaIntObjectInspector,
          PrimitiveObjectInspectorFactory.writableByteObjectInspector);
      assertEquals("ByteConverter", new ByteWritable((byte) 0), byteConverter
          .convert(Integer.valueOf(0)));
      assertEquals("ByteConverter", new ByteWritable((byte) 1), byteConverter
          .convert(Integer.valueOf(1)));
      assertEquals("ByteConverter", null, byteConverter.convert(null));

      // Short
      Converter shortConverter = ObjectInspectorConverters.getConverter(
          PrimitiveObjectInspectorFactory.javaIntObjectInspector,
          PrimitiveObjectInspectorFactory.writableShortObjectInspector);
      assertEquals("ShortConverter", new ShortWritable((short) 0),
          shortConverter.convert(Integer.valueOf(0)));
      assertEquals("ShortConverter", new ShortWritable((short) 1),
          shortConverter.convert(Integer.valueOf(1)));
      assertEquals("ShortConverter", null, shortConverter.convert(null));

      // Int
      Converter intConverter = ObjectInspectorConverters.getConverter(
          PrimitiveObjectInspectorFactory.javaIntObjectInspector,
          PrimitiveObjectInspectorFactory.writableIntObjectInspector);
      assertEquals("IntConverter", new IntWritable(0), intConverter
          .convert(Integer.valueOf(0)));
      assertEquals("IntConverter", new IntWritable(1), intConverter
          .convert(Integer.valueOf(1)));
      assertEquals("IntConverter", null, intConverter.convert(null));

      // Long
      Converter longConverter = ObjectInspectorConverters.getConverter(
          PrimitiveObjectInspectorFactory.javaIntObjectInspector,
          PrimitiveObjectInspectorFactory.writableLongObjectInspector);
      assertEquals("LongConverter", new LongWritable(0), longConverter
          .convert(Integer.valueOf(0)));
      assertEquals("LongConverter", new LongWritable(1), longConverter
          .convert(Integer.valueOf(1)));
      assertEquals("LongConverter", null, longConverter.convert(null));

      // Float
      Converter floatConverter = ObjectInspectorConverters.getConverter(
          PrimitiveObjectInspectorFactory.javaIntObjectInspector,
          PrimitiveObjectInspectorFactory.writableFloatObjectInspector);
      assertEquals("LongConverter", new FloatWritable(0), floatConverter
          .convert(Integer.valueOf(0)));
      assertEquals("LongConverter", new FloatWritable(1), floatConverter
          .convert(Integer.valueOf(1)));
      assertEquals("LongConverter", null, floatConverter.convert(null));

      // Double
      Converter doubleConverter = ObjectInspectorConverters.getConverter(
          PrimitiveObjectInspectorFactory.javaIntObjectInspector,
          PrimitiveObjectInspectorFactory.writableDoubleObjectInspector);
      assertEquals("DoubleConverter", new DoubleWritable(0), doubleConverter
          .convert(Integer.valueOf(0)));
      assertEquals("DoubleConverter", new DoubleWritable(1), doubleConverter
          .convert(Integer.valueOf(1)));
      assertEquals("DoubleConverter", null, doubleConverter.convert(null));

      // Text
      Converter textConverter = ObjectInspectorConverters.getConverter(
          PrimitiveObjectInspectorFactory.javaIntObjectInspector,
          PrimitiveObjectInspectorFactory.writableStringObjectInspector);
      assertEquals("TextConverter", new Text("0"), textConverter
          .convert(Integer.valueOf(0)));
      assertEquals("TextConverter", new Text("1"), textConverter
          .convert(Integer.valueOf(1)));
      assertEquals("TextConverter", null, textConverter.convert(null));

      textConverter = ObjectInspectorConverters.getConverter(
          PrimitiveObjectInspectorFactory.writableBinaryObjectInspector,
          PrimitiveObjectInspectorFactory.writableStringObjectInspector);
      assertEquals("TextConverter", new Text("hive"), textConverter
          .convert(new BytesWritable(new byte[]
              {(byte)'h', (byte)'i',(byte)'v',(byte)'e'})));
      assertEquals("TextConverter", null, textConverter.convert(null));

      textConverter = ObjectInspectorConverters.getConverter(
          PrimitiveObjectInspectorFactory.writableStringObjectInspector,
          PrimitiveObjectInspectorFactory.writableStringObjectInspector);
      assertEquals("TextConverter", new Text("hive"), textConverter
    .convert(new Text("hive")));
      assertEquals("TextConverter", null, textConverter.convert(null));

      textConverter = ObjectInspectorConverters.getConverter(
          PrimitiveObjectInspectorFactory.javaStringObjectInspector,
          PrimitiveObjectInspectorFactory.writableStringObjectInspector);
      assertEquals("TextConverter", new Text("hive"), textConverter
    .convert(new String("hive")));
      assertEquals("TextConverter", null, textConverter.convert(null));

      textConverter = ObjectInspectorConverters.getConverter(
          PrimitiveObjectInspectorFactory.javaHiveDecimalObjectInspector,
          PrimitiveObjectInspectorFactory.writableStringObjectInspector);
      assertEquals("TextConverter", new Text("100.001"), textConverter
    .convert(HiveDecimal.create("100.001")));
      assertEquals("TextConverter", null, textConverter.convert(null));

      // Binary
      Converter baConverter = ObjectInspectorConverters.getConverter(
          PrimitiveObjectInspectorFactory.javaStringObjectInspector,
          PrimitiveObjectInspectorFactory.writableBinaryObjectInspector);
      assertEquals("BAConverter", new BytesWritable(new byte[]
          {(byte)'h', (byte)'i',(byte)'v',(byte)'e'}),
          baConverter.convert("hive"));
      assertEquals("BAConverter", null, baConverter.convert(null));

      baConverter = ObjectInspectorConverters.getConverter(
          PrimitiveObjectInspectorFactory.writableStringObjectInspector,
          PrimitiveObjectInspectorFactory.writableBinaryObjectInspector);
      assertEquals("BAConverter", new BytesWritable(new byte[]
          {(byte)'h', (byte)'i',(byte)'v',(byte)'e'}),
          baConverter.convert(new Text("hive")));
      assertEquals("BAConverter", null, baConverter.convert(null));
    } catch (Throwable e) {
      e.printStackTrace();
      throw e;
    }
View Full Code Here

        if (type == null) {
          throw new SemanticException("Column " + key + " not found");
        }
        // Create the corresponding hive expression to filter on partition columns.
        PrimitiveTypeInfo pti = TypeInfoFactory.getPrimitiveTypeInfo(type);
        Converter converter = ObjectInspectorConverters.getConverter(
          TypeInfoUtils.getStandardJavaObjectInspectorFromTypeInfo(TypeInfoFactory.stringTypeInfo),
          TypeInfoUtils.getStandardJavaObjectInspectorFromTypeInfo(pti));
        ExprNodeColumnDesc column = new ExprNodeColumnDesc(pti, key, null, true);
        ExprNodeGenericFuncDesc op = makeBinaryPredicate(
            operator, column, new ExprNodeConstantDesc(pti, converter.convert(val)));
        // If it's multi-expr filter (e.g. a='5', b='2012-01-02'), AND with previous exprs.
        expr = (expr == null) ? op : makeBinaryPredicate("and", expr, op);
        names.add(key);
      }
      if (expr == null) continue;
View Full Code Here

      throw new UDFArgumentTypeException(0,
        "Only primitive type arguments are accepted but "
        + arguments[i].getTypeName() + " is passed. as first arguments");
    }
    PrimitiveCategory inputType = ((PrimitiveObjectInspector) arguments[i]).getPrimitiveCategory();
    Converter converter;
    switch (inputType) {
    case STRING:
    case VARCHAR:
    case CHAR:
      converter = ObjectInspectorConverters.getConverter(
View Full Code Here

        if (converters == null) {
          converters = new HashMap<ObjectInspector, Converter>();
        }

        Converter converter = converters.get(oi);
        if (converter == null) {
          converter = ObjectInspectorConverters.getConverter(oi,
              returnObjectInspector);
          converters.put(oi, converter);
        }
        converted = converter.convert(o);
      }
      return converted;
    }
View Full Code Here

      // Create the converters
      conversionNeeded = false;
      converters = new Converter[parameterOIs.length];
      for (int i = 0; i < parameterOIs.length; i++) {
        Converter pc = ObjectInspectorConverters.getConverter(parameterOIs[i],
            methodParameterOIs[i]);
        converters[i] = pc;
        // Conversion is needed?
        conversionNeeded = conversionNeeded
            || (!(pc instanceof IdentityConverter));
View Full Code Here

    if (arguments[i].getCategory() != ObjectInspector.Category.PRIMITIVE) {
      throw new UDFArgumentTypeException(i + 1, "Only primitive type arguments are accepted but "
    + arguments[i].getTypeName() + " is passed. as  arguments");
    }
    PrimitiveCategory inputType = ((PrimitiveObjectInspector) arguments[i]).getPrimitiveCategory();
    Converter converter;
    switch (inputType) {
    case STRING:
    case CHAR:
    case VARCHAR:
      converter = ObjectInspectorConverters.getConverter((PrimitiveObjectInspector) arguments[i],
View Full Code Here

TOP

Related Classes of org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorConverters.Converter

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.