`
tcxiang
  • 浏览: 89525 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

ObjectInspector

    博客分类:
  • hive
 
阅读更多

PrimitiveObjectInspectorFactory做了个工厂模式,避免hive过多的去new Object从而对GC造成负担。

 

public final class PrimitiveObjectInspectorFactory {

  public static final JavaBooleanObjectInspector javaBooleanObjectInspector =
      new JavaBooleanObjectInspector();
  public static final JavaByteObjectInspector javaByteObjectInspector =
      new JavaByteObjectInspector();
  public static final JavaShortObjectInspector javaShortObjectInspector =
      new JavaShortObjectInspector();
  public static final JavaIntObjectInspector javaIntObjectInspector =
      new JavaIntObjectInspector();
  public static final JavaLongObjectInspector javaLongObjectInspector =
      new JavaLongObjectInspector();
  public static final JavaFloatObjectInspector javaFloatObjectInspector =
      new JavaFloatObjectInspector();
  public static final JavaDoubleObjectInspector javaDoubleObjectInspector =
      new JavaDoubleObjectInspector();
  public static final JavaStringObjectInspector javaStringObjectInspector =
      new JavaStringObjectInspector();
  public static final JavaVoidObjectInspector javaVoidObjectInspector =
      new JavaVoidObjectInspector();

  public static final WritableBooleanObjectInspector writableBooleanObjectInspector =
      new WritableBooleanObjectInspector();
  public static final WritableByteObjectInspector writableByteObjectInspector =
      new WritableByteObjectInspector();
  public static final WritableShortObjectInspector writableShortObjectInspector =
      new WritableShortObjectInspector();
  public static final WritableIntObjectInspector writableIntObjectInspector =
      new WritableIntObjectInspector();
  public static final WritableLongObjectInspector writableLongObjectInspector =
      new WritableLongObjectInspector();
  public static final WritableFloatObjectInspector writableFloatObjectInspector =
      new WritableFloatObjectInspector();
  public static final WritableDoubleObjectInspector writableDoubleObjectInspector =
      new WritableDoubleObjectInspector();
  public static final WritableStringObjectInspector writableStringObjectInspector =
      new WritableStringObjectInspector();
  public static final WritableVoidObjectInspector writableVoidObjectInspector =
      new WritableVoidObjectInspector();

  private static HashMap<PrimitiveCategory, AbstractPrimitiveWritableObjectInspector> cachedPrimitiveWritableInspectorCache =
      new HashMap<PrimitiveCategory, AbstractPrimitiveWritableObjectInspector>();
  static {
    cachedPrimitiveWritableInspectorCache.put(PrimitiveCategory.BOOLEAN,
        writableBooleanObjectInspector);
    cachedPrimitiveWritableInspectorCache.put(PrimitiveCategory.BYTE,
        writableByteObjectInspector);
    cachedPrimitiveWritableInspectorCache.put(PrimitiveCategory.SHORT,
        writableShortObjectInspector);
    cachedPrimitiveWritableInspectorCache.put(PrimitiveCategory.INT,
        writableIntObjectInspector);
    cachedPrimitiveWritableInspectorCache.put(PrimitiveCategory.LONG,
        writableLongObjectInspector);
    cachedPrimitiveWritableInspectorCache.put(PrimitiveCategory.FLOAT,
        writableFloatObjectInspector);
    cachedPrimitiveWritableInspectorCache.put(PrimitiveCategory.DOUBLE,
        writableDoubleObjectInspector);
    cachedPrimitiveWritableInspectorCache.put(PrimitiveCategory.STRING,
        writableStringObjectInspector);
    cachedPrimitiveWritableInspectorCache.put(PrimitiveCategory.VOID,
        writableVoidObjectInspector);
  }

  private static HashMap<PrimitiveCategory, AbstractPrimitiveJavaObjectInspector> cachedPrimitiveJavaInspectorCache =
      new HashMap<PrimitiveCategory, AbstractPrimitiveJavaObjectInspector>();
  static {
    cachedPrimitiveJavaInspectorCache.put(PrimitiveCategory.BOOLEAN,
        javaBooleanObjectInspector);
    cachedPrimitiveJavaInspectorCache.put(PrimitiveCategory.BYTE,
        javaByteObjectInspector);
    cachedPrimitiveJavaInspectorCache.put(PrimitiveCategory.SHORT,
        javaShortObjectInspector);
    cachedPrimitiveJavaInspectorCache.put(PrimitiveCategory.INT,
        javaIntObjectInspector);
    cachedPrimitiveJavaInspectorCache.put(PrimitiveCategory.LONG,
        javaLongObjectInspector);
    cachedPrimitiveJavaInspectorCache.put(PrimitiveCategory.FLOAT,
        javaFloatObjectInspector);
    cachedPrimitiveJavaInspectorCache.put(PrimitiveCategory.DOUBLE,
        javaDoubleObjectInspector);
    cachedPrimitiveJavaInspectorCache.put(PrimitiveCategory.STRING,
        javaStringObjectInspector);
    cachedPrimitiveJavaInspectorCache.put(PrimitiveCategory.VOID,
        javaVoidObjectInspector);
  }

  /**
   * Returns the PrimitiveWritableObjectInspector for the PrimitiveCategory.
   * 
   * @param primitiveCategory
   */
  public static AbstractPrimitiveWritableObjectInspector getPrimitiveWritableObjectInspector(
      PrimitiveCategory primitiveCategory) {
    AbstractPrimitiveWritableObjectInspector result =
        cachedPrimitiveWritableInspectorCache.get(primitiveCategory);
    if (result == null) {
      throw new RuntimeException("Internal error: Cannot find ObjectInspector "
          + " for " + primitiveCategory);
    }
    return result;
  }

  /**
   * Returns the PrimitiveJavaObjectInspector for the PrimitiveCategory.
   * 
   * @param primitiveCategory
   */
  public static AbstractPrimitiveJavaObjectInspector getPrimitiveJavaObjectInspector(
      PrimitiveCategory primitiveCategory) {
    AbstractPrimitiveJavaObjectInspector result =
        cachedPrimitiveJavaInspectorCache.get(primitiveCategory);
    if (result == null) {
      throw new RuntimeException("Internal error: Cannot find ObjectInspector "
          + " for " + primitiveCategory);
    }
    return result;
  }

  /**
   * Returns an ObjectInspector for a primitive Class. The Class can be a Hive
   * Writable class, or a Java Primitive Class.
   * 
   * A runtimeException will be thrown if the class is not recognized as a
   * primitive type by Hive.
   */
  public static PrimitiveObjectInspector getPrimitiveObjectInspectorFromClass(
      Class<?> c) {
    if (Writable.class.isAssignableFrom(c)) {
      // It is a writable class
      PrimitiveTypeEntry te = PrimitiveObjectInspectorUtils
          .getTypeEntryFromPrimitiveWritableClass(c);
      if (te == null) {
        throw new RuntimeException("Internal error: Cannot recognize " + c);
      }
      return PrimitiveObjectInspectorFactory
          .getPrimitiveWritableObjectInspector(te.primitiveCategory);
    } else {
      // It is a Java class
      PrimitiveTypeEntry te = PrimitiveObjectInspectorUtils
          .getTypeEntryFromPrimitiveJavaClass(c);
      if (te == null) {
        throw new RuntimeException("Internal error: Cannot recognize " + c);
      }
      return PrimitiveObjectInspectorFactory
          .getPrimitiveJavaObjectInspector(te.primitiveCategory);
    }
  }

  private PrimitiveObjectInspectorFactory() {
    // prevent instantiation
  }
}

 

public class WritableDoubleObjectInspector extends
    AbstractPrimitiveWritableObjectInspector implements
    SettableDoubleObjectInspector {

  WritableDoubleObjectInspector() {
    super(PrimitiveObjectInspectorUtils.doubleTypeEntry);
  }

  @Override
  public double get(Object o) {
    return ((DoubleWritable) o).get();
  }

  @Override
  public Object copyObject(Object o) {
    return o == null ? null : new DoubleWritable(((DoubleWritable) o).get());
  }

  @Override
  public Object getPrimitiveJavaObject(Object o) {
    return o == null ? null : Double.valueOf(((DoubleWritable) o).get());
  }

  @Override
  public Object create(double value) {
    return new DoubleWritable(value);
  }

  @Override
  public Object set(Object o, double value) {
    ((DoubleWritable) o).set(value);
    return o;
  }

}

 

public static StandardStructObjectInspector getStandardStructObjectInspector(
      List<String> structFieldNames,
      List<ObjectInspector> structFieldObjectInspectors) {
    ArrayList<List<?>> signature = new ArrayList<List<?>>();
    signature.add(structFieldNames);
    signature.add(structFieldObjectInspectors);
    StandardStructObjectInspector result = cachedStandardStructObjectInspector
        .get(signature);
    if (result == null) {
      result = new StandardStructObjectInspector(structFieldNames,
          structFieldObjectInspectors);
      cachedStandardStructObjectInspector.put(signature, result);
    }
    return result;
  }

 

public static StandardListObjectInspector getStandardListObjectInspector(
      ObjectInspector listElementObjectInspector) {
    StandardListObjectInspector result = cachedStandardListObjectInspector
        .get(listElementObjectInspector);
    if (result == null) {
      result = new StandardListObjectInspector(listElementObjectInspector);
      cachedStandardListObjectInspector.put(listElementObjectInspector, result);
    }
    return result;
  }

 

分享到:
评论

相关推荐

    运行时Object Inspector

    "运行时Object Inspector"是Delphi编程环境中一个强大的工具,主要功能是在运行阶段查看和编辑对象的属性。这个工具特别适用于Delphi 5.x至2006版本,为开发者提供了一个直观的方式来调试和调整控件的设计属性。下面...

    Object Inspector.rar

    《Object Inspector在Delphi开发中的应用详解》 在Delphi编程环境中,Object Inspector(对象查看器)是一个不可或缺的工具,它为开发者提供了直观且强大的组件属性和事件管理能力。Object Inspector,简称为OI,是...

    OI.zip_costjcj_object inspector

    【标题】"OI.zip_costjcj_object inspector" 是一个针对Delphi编程环境的扩展工具,主要功能是"Object Inspector",适用于Delphi 7到XE版本。这个工具旨在提升开发者在设计和调试对象属性时的效率。 【描述】...

    Object Inspector

    "Object Inspector"是编程环境中一个重要的工具,主要用来查看和修改对象的属性和方法。在Delphi或类似IDE(集成开发环境)中,它通常与代码编辑器一起使用,为开发者提供直观的界面来探索和调整对象实例的特性。这...

    Componente-MiTec Object Inspector Demo.7z

    《MiTec Object Inspector组件在Delphi开发中的应用探索》 MiTec Object Inspector是一款针对Delphi编程环境的组件,其主要功能在于提供一个强大的对象查看和编辑工具,极大地提升了开发者在编写和调试代码时的效率...

    Object Inspector v1.51 for BCB2009

    "Object Inspector v1.51 for BCB2009" 是一个专为Borland C++ Builder 2009 (BCB2009) 设计的工具,其核心功能是对象检查器。对象检查器是集成开发环境(IDE)中的一个重要组件,它允许程序员在运行时查看和修改...

    Object Inspector-开源

    ObjectInspector是一组旨在匹配对象并通过扩展来测试Bean实现代码的类。 这些入口点旨在通过使用其他匹配器和工厂的注册来扩展。

    delphi7 制作的计算器

    IDE提供了图形化用户界面(GUI)设计工具,称为对象-inspector(Object Inspector)和Form Designer。在Form Designer中,你可以通过拖放控件(如按钮、文本框等)到表单上,然后用Object Inspector来设置它们的属性...

    Object.Inspector.v1.51.Full.Soource For D2010.rar

    《Object.Inspector.v1.51.Full.Source for D2010》是一款专为Delphi 2010开发的组件,它提供了一个类似.NET Framework中的PropertyGrid控件的功能,使得用户可以在运行时便捷地修改组件的属性。这个控件在设计时...

    控件属性编辑器for delphbi XE2

    《Delphi XE2下的控件属性编辑器——深入理解Object Inspector》 在Delphi编程环境中,Object Inspector(简称OI)是开发人员不可或缺的工具,它允许开发者直观地查看、修改和设置对象的属性和方法。对于Delphi XE2...

    DELPHI基础教程.pdf

    属性提供非常重要的好处,最明显的好处是属性在设计时能出现在 ObjectInspector 窗口中,这将简化编程工作,因为你只需读用户所赋的值,而不要处理构造对象的参数。 属性的种类 ------------ 属性可以是函数能返回...

    DELPHI基础教程.docx

    属性提供非常重要的好处,最明显的好处是属性在设计时能出现在 Object Inspector 窗口中,这将简化编程工作,因为你只需读用户所赋的值,而不要处理构造对象的参数。从部件使用者的观点看,属性象变量。用户可以给...

    MaxSpace v4.2 破解版

    It turns the IDE ToolBar and ObjectInspector into emerging state, giving you unbelievable freedom of program editing and form designing. When you don‘t need the IDE ToolBar or the ObjectInspector ...

    PythonStudio GUI窗体设计开发文档

    Object Inspector 允许用户查看和编辑组件的属性,并且可以查看和编辑组件的事件处理程序。用户可以使用 Object Inspector 来设计和开发 GUI 窗体。 PythonStudio GUI 窗体设计开发文档提供了 GUI 窗体设计的基础...

    Delphi教程软件项目管理案例教程(第2版)课后习题答案(详细版).pdf

    设置窗体属性:单击“Object Inspector”(对象观察器)项,在打开的对话框中选择“Properties”选项卡,在“Caption”文本框中输入窗体的新标题。 向窗体中添加组件:在工具盘搜索区域输入组件名称(如TButton),...

    FastReport.v4.15 for.Delphi.BCB.Full.Source企业版含ClientServer中文修正版支持D4-XE5

    + published "UseMAPI" property of TfrxExportMail object + published "PictureType" property to ODF export - fixed bug with expressions in RichEdit - fixed bug in multi-column reports - fixed exception ...

    获取最大分区UDTF函数.doc

    import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector; import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorFactory; import org.apache.hadoop.hive.serde2.objectinspector....

    获取规范货币类型UDF函数.doc

    public ObjectInspector initialize(ObjectInspector[] arguments) throws UDFArgumentException { inputOI = (StringObjectInspector) arguments[0]; return PrimitiveObjectInspectorFactory....

Global site tag (gtag.js) - Google Analytics