• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java TimestampObjectInspector类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.apache.hadoop.hive.serde2.objectinspector.primitive.TimestampObjectInspector的典型用法代码示例。如果您正苦于以下问题:Java TimestampObjectInspector类的具体用法?Java TimestampObjectInspector怎么用?Java TimestampObjectInspector使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



TimestampObjectInspector类属于org.apache.hadoop.hive.serde2.objectinspector.primitive包,在下文中一共展示了TimestampObjectInspector类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: createPrimitive

import org.apache.hadoop.hive.serde2.objectinspector.primitive.TimestampObjectInspector; //导入依赖的package包/类
private static Writable createPrimitive(Object obj, PrimitiveObjectInspector inspector)
        throws SerDeException {
    if (obj == null) {
        return null;
    }
    switch (inspector.getPrimitiveCategory()) {
        case DOUBLE:
            return new DoubleWritable(((DoubleObjectInspector) inspector).get(obj));
        case FLOAT:
            return new FloatWritable(((FloatObjectInspector) inspector).get(obj));
        case INT:
            return new IntWritable(((IntObjectInspector) inspector).get(obj));
        case LONG:
            return new LongWritable(((LongObjectInspector) inspector).get(obj));
        case STRING:
            return new Text(((StringObjectInspector) inspector).getPrimitiveJavaObject(obj));
        case DATE:
            return ((DateObjectInspector) inspector).getPrimitiveWritableObject(obj);
        case TIMESTAMP:
            return ((TimestampObjectInspector) inspector).getPrimitiveWritableObject(obj);
        default:
            throw new SerDeException("Can't serialize primitive : " + inspector.getPrimitiveCategory());
    }
}
 
开发者ID:shunfei,项目名称:indexr,代码行数:25,代码来源:IndexRSerde.java


示例2: initialize

import org.apache.hadoop.hive.serde2.objectinspector.primitive.TimestampObjectInspector; //导入依赖的package包/类
@Override
public ObjectInspector initialize(ObjectInspector[] arguments) throws UDFArgumentException {
    dateOi = arguments[0];
    if (!(dateOi instanceof StringObjectInspector ||  dateOi instanceof TimestampObjectInspector)) {
        throw new IllegalArgumentException("Can only call this UDF on types 'string' and 'timestamp'. " +
                "Given " + dateOi.getTypeName());
    }

    hasSecondArg = arguments.length > 1;

    if (hasSecondArg) {
        ObjectInspector oi = arguments[1];
        if (oi instanceof WritableConstantStringObjectInspector) {
            constSecondArg = ((WritableConstantStringObjectInspector) oi).getWritableConstantValue().toString();
        } else if (oi instanceof StringObjectInspector) {
            formatOi = (StringObjectInspector) oi;
        } else {
            throw new IllegalArgumentException("Second argument must be of String type");
        }
    }
    return PrimitiveObjectInspectorFactory.javaLongObjectInspector;
}
 
开发者ID:lithiumtech,项目名称:yoda-time,代码行数:23,代码来源:ToEpoch.java


示例3: write

import org.apache.hadoop.hive.serde2.objectinspector.primitive.TimestampObjectInspector; //导入依赖的package包/类
@Override
void write(Object obj) throws IOException {
  // Raw data size is:
  //   the number of bytes needed to store the milliseconds since the epoch
  //   (8 since it's a long)
  //   +
  //   the number of bytes needed to store the nanos field (4 since it's an int)
  super.write(obj, RawDatasizeConst.TIMESTAMP_SIZE);
  if (obj != null) {
    Timestamp val =
        ((TimestampObjectInspector) inspector).
            getPrimitiveJavaObject(obj);
    seconds.write((val.getTime() / MILLIS_PER_SECOND) - BASE_TIMESTAMP);
    nanos.write(formatNanos(val.getNanos()));
  }
}
 
开发者ID:facebookarchive,项目名称:hive-dwrf,代码行数:17,代码来源:WriterImpl.java


示例4: setSafeValue

import org.apache.hadoop.hive.serde2.objectinspector.primitive.TimestampObjectInspector; //导入依赖的package包/类
@Override
public void setSafeValue(ObjectInspector oi, Object hiveFieldValue, ValueVector outputVV, int outputIndex) {
  final TimestampWritable value = ((TimestampObjectInspector)oi).getPrimitiveWritableObject(hiveFieldValue);
  long seconds = value.getSeconds();
  long nanos = value.getNanos();
  long millis = seconds * 1000 + nanos/1000/1000;
  ((NullableTimeStampMilliVector) outputVV).getMutator().setSafe(outputIndex, millis);
}
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:9,代码来源:HiveFieldConverter.java


示例5: getTimestamp

import org.apache.hadoop.hive.serde2.objectinspector.primitive.TimestampObjectInspector; //导入依赖的package包/类
private static Timestamp getTimestamp(Object object, TimestampObjectInspector inspector)
{
    // handle broken ObjectInspectors
    if (object instanceof TimestampWritable) {
        return ((TimestampWritable) object).getTimestamp();
    }
    return inspector.getPrimitiveJavaObject(object);
}
 
开发者ID:y-lan,项目名称:presto,代码行数:9,代码来源:SerDeUtils.java


示例6: evaluate

import org.apache.hadoop.hive.serde2.objectinspector.primitive.TimestampObjectInspector; //导入依赖的package包/类
@Override
public Object evaluate(DeferredObject[] arguments) throws HiveException {
    if (dateOi instanceof StringObjectInspector) {
        String dateStr = ((StringObjectInspector) dateOi).getPrimitiveJavaObject(arguments[0].get());
        DateTimeFormatter dtf;
        if (hasSecondArg) {
            if (constSecondArg == null) {
                dtf = DateTimeFormat.forPattern(formatOi.getPrimitiveJavaObject(arguments[1].get()));
            } else {
                dtf = DateTimeFormat.forPattern(constSecondArg);
            }
        } else {
            dtf = ISODateTimeFormat.dateTimeParser().withOffsetParsed();
        }
        return dtf.parseDateTime(dateStr).getMillis();
    } else if (dateOi instanceof TimestampObjectInspector) {
        Timestamp ts = ((TimestampObjectInspector) dateOi).getPrimitiveJavaObject(arguments[0].get());
        if (hasSecondArg) {
            DateTime dt;
            if (constSecondArg == null) {
                dt = new DateTime(ts.getTime(), DateTimeZone.forID(
                        formatOi.getPrimitiveJavaObject(arguments[1].get())));
            } else {
                dt = new DateTime(ts.getTime(), DateTimeZone.forID(constSecondArg));
            }
            return dt.getMillis();
        } else {
            return ts.getTime();
        }
    }

    return null;
}
 
开发者ID:lithiumtech,项目名称:yoda-time,代码行数:34,代码来源:ToEpoch.java


示例7: testOneArgTimestampInput

import org.apache.hadoop.hive.serde2.objectinspector.primitive.TimestampObjectInspector; //导入依赖的package包/类
@Test
public void testOneArgTimestampInput() throws HiveException {
    ToEpoch udf = new ToEpoch();

    TimestampObjectInspector soi = PrimitiveObjectInspectorFactory.javaTimestampObjectInspector;
    udf.initialize(new ObjectInspector[]{soi});

    Timestamp ts = new Timestamp(1397483853809L);

    long output = (Long) udf.evaluate(new GenericUDF.DeferredObject[]{new GenericUDF.DeferredJavaObject(ts)});
    Assert.assertEquals(1397483853809L, output);
}
 
开发者ID:lithiumtech,项目名称:yoda-time,代码行数:13,代码来源:ToEpochTest.java


示例8: TestCopyTimestamp

import org.apache.hadoop.hive.serde2.objectinspector.primitive.TimestampObjectInspector; //导入依赖的package包/类
/**
 * Tests that after copying a lazy timestamp object, calling materialize on the original and the
 * copy doesn't advance the tree reader twice
 * @throws Exception
 */
@Test
public void TestCopyTimestamp() throws Exception {
  ReaderWriterProfiler.setProfilerOptions(null);
  OrcLazyTimestamp lazyTimestamp = new OrcLazyTimestamp(new LazyTimestampTreeReader(0, 0) {
    int nextCalls = 0;

    @Override
    public Object next(Object previous) throws IOException {
      if (nextCalls == 0) {
        return new TimestampWritable(new Timestamp(1));
      }

      throw new IOException("next should only be called once");
    }

    @Override
    protected boolean seekToRow(long currentRow) throws IOException {
      return true;
    }
  });

  TimestampObjectInspector timestampOI = (TimestampObjectInspector)
      OrcLazyObjectInspectorUtils.createLazyObjectInspector(TypeInfoFactory.timestampTypeInfo);

  OrcLazyTimestamp lazyTimestamp2 = (OrcLazyTimestamp) timestampOI.copyObject(lazyTimestamp);

  Assert.assertEquals(new Timestamp(1), ((TimestampWritable) lazyTimestamp.materialize()).getTimestamp());
  Assert.assertEquals(new Timestamp(1), ((TimestampWritable) lazyTimestamp2.materialize()).getTimestamp());
}
 
开发者ID:facebookarchive,项目名称:hive-dwrf,代码行数:35,代码来源:TestObjectInspector.java


示例9: setSafeValue

import org.apache.hadoop.hive.serde2.objectinspector.primitive.TimestampObjectInspector; //导入依赖的package包/类
@Override
public void setSafeValue(ObjectInspector oi, Object hiveFieldValue, ValueVector outputVV, int outputIndex) {
  final java.sql.Timestamp value = ((TimestampObjectInspector)oi).getPrimitiveJavaObject(hiveFieldValue);
  final DateTime ts = new DateTime(value.getTime()).withZoneRetainFields(DateTimeZone.UTC);
  ((NullableTimeStampVector) outputVV).getMutator().setSafe(outputIndex, ts.getMillis());
}
 
开发者ID:skhalifa,项目名称:QDrill,代码行数:7,代码来源:HiveFieldConverter.java


示例10: evaluate

import org.apache.hadoop.hive.serde2.objectinspector.primitive.TimestampObjectInspector; //导入依赖的package包/类
@Override
public Object evaluate(DeferredObject[] arguments) throws HiveException {
  if (arguments[0] == null || arguments[0].get() == null) {
    return null;
  }

  Object input = arguments[0].get();
  switch(inputType) {
    case BOOLEAN:
      return ((BooleanObjectInspector)argumentOI).get(input) ? Boolean.TRUE : Boolean.FALSE;
    case BYTE:
      return new Byte(((ByteObjectInspector)argumentOI).get(input));
    case SHORT:
      return new Short(((ShortObjectInspector)argumentOI).get(input));
    case INT:
      return new Integer(((IntObjectInspector)argumentOI).get(input));
    case LONG:
      return new Long(((LongObjectInspector)argumentOI).get(input));
    case FLOAT:
      return new Float(((FloatObjectInspector)argumentOI).get(input));
    case DOUBLE:
      return new Double(((DoubleObjectInspector)argumentOI).get(input));
    case STRING:
      return PrimitiveObjectInspectorUtils.getString(input, (StringObjectInspector)argumentOI);
    case BINARY:
      return PrimitiveObjectInspectorUtils.getBinary(input, (BinaryObjectInspector) argumentOI).getBytes();
    case VARCHAR:
      return PrimitiveObjectInspectorUtils.getHiveVarchar(input, (HiveVarcharObjectInspector)argumentOI);
    case DATE:
      return PrimitiveObjectInspectorUtils.getDate(input, (DateObjectInspector) argumentOI);
    case TIMESTAMP:
      return PrimitiveObjectInspectorUtils.getTimestamp(input, (TimestampObjectInspector) argumentOI);
    case DECIMAL:
      // return type is a HiveVarchar
      HiveDecimal decimalValue =
          PrimitiveObjectInspectorUtils.getHiveDecimal(input, (HiveDecimalObjectInspector) argumentOI);
      return new HiveVarchar(decimalValue.toString(), HiveVarchar.MAX_VARCHAR_LENGTH);
  }

  throw new UnsupportedOperationException(String.format("Unexpected input type '%s' in Test UDF", inputType));
}
 
开发者ID:skhalifa,项目名称:QDrill,代码行数:42,代码来源:HiveTestUDFImpls.java


示例11: evaluate

import org.apache.hadoop.hive.serde2.objectinspector.primitive.TimestampObjectInspector; //导入依赖的package包/类
@Override
public Object evaluate(DeferredObject[] arguments) throws HiveException {
  if (arguments[0] == null || arguments[0].get() == null) {
    return null;
  }

  Object input = arguments[0].get();
  switch(inputType) {
    case BOOLEAN:
      return ((BooleanObjectInspector)argumentOI).get(input) ? Boolean.TRUE : Boolean.FALSE;
    case BYTE:
      return new Byte(((ByteObjectInspector)argumentOI).get(input));
    case SHORT:
      return new Short(((ShortObjectInspector)argumentOI).get(input));
    case INT:
      return new Integer(((IntObjectInspector)argumentOI).get(input));
    case LONG:
      return new Long(((LongObjectInspector)argumentOI).get(input));
    case FLOAT:
      return new Float(((FloatObjectInspector)argumentOI).get(input));
    case DOUBLE:
      return new Double(((DoubleObjectInspector)argumentOI).get(input));
    case STRING:
      return PrimitiveObjectInspectorUtils.getString(input, (StringObjectInspector)argumentOI);
    case BINARY:
      return PrimitiveObjectInspectorUtils.getBinary(input, (BinaryObjectInspector) argumentOI).getBytes();
    case VARCHAR:
      if (outputType == PrimitiveCategory.CHAR) {
        HiveVarchar hiveVarchar = PrimitiveObjectInspectorUtils.getHiveVarchar(input, (HiveVarcharObjectInspector) argumentOI);
        return new HiveChar(hiveVarchar.getValue(), HiveChar.MAX_CHAR_LENGTH);
      } else {
        return PrimitiveObjectInspectorUtils.getHiveVarchar(input, (HiveVarcharObjectInspector)argumentOI);
      }
    case CHAR:
      return PrimitiveObjectInspectorUtils.getHiveChar(input, (HiveCharObjectInspector) argumentOI);
    case DATE:
      return PrimitiveObjectInspectorUtils.getDate(input, (DateObjectInspector) argumentOI);
    case TIMESTAMP:
      return PrimitiveObjectInspectorUtils.getTimestamp(input, (TimestampObjectInspector) argumentOI);
    case DECIMAL:
      // return type is a HiveVarchar
      HiveDecimal decimalValue =
          PrimitiveObjectInspectorUtils.getHiveDecimal(input, (HiveDecimalObjectInspector) argumentOI);
      return new HiveVarchar(decimalValue.toString(), HiveVarchar.MAX_VARCHAR_LENGTH);
  }

  throw new UnsupportedOperationException(String.format("Unexpected input type '%s' in Test UDF", inputType));
}
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:49,代码来源:HiveTestUDFImpls.java


示例12: serializePrimitive

import org.apache.hadoop.hive.serde2.objectinspector.primitive.TimestampObjectInspector; //导入依赖的package包/类
private static void serializePrimitive(BlockBuilder builder, Object object, PrimitiveObjectInspector inspector)
{
    requireNonNull(builder, "parent builder is null");

    if (object == null) {
        builder.appendNull();
        return;
    }

    switch (inspector.getPrimitiveCategory()) {
        case BOOLEAN:
            BooleanType.BOOLEAN.writeBoolean(builder, ((BooleanObjectInspector) inspector).get(object));
            return;
        case BYTE:
            BigintType.BIGINT.writeLong(builder, ((ByteObjectInspector) inspector).get(object));
            return;
        case SHORT:
            BigintType.BIGINT.writeLong(builder, ((ShortObjectInspector) inspector).get(object));
            return;
        case INT:
            BigintType.BIGINT.writeLong(builder, ((IntObjectInspector) inspector).get(object));
            return;
        case LONG:
            BigintType.BIGINT.writeLong(builder, ((LongObjectInspector) inspector).get(object));
            return;
        case FLOAT:
            DoubleType.DOUBLE.writeDouble(builder, ((FloatObjectInspector) inspector).get(object));
            return;
        case DOUBLE:
            DoubleType.DOUBLE.writeDouble(builder, ((DoubleObjectInspector) inspector).get(object));
            return;
        case STRING:
            VarcharType.VARCHAR.writeSlice(builder, Slices.utf8Slice(((StringObjectInspector) inspector).getPrimitiveJavaObject(object)));
            return;
        case DATE:
            DateType.DATE.writeLong(builder, formatDateAsLong(object, (DateObjectInspector) inspector));
            return;
        case TIMESTAMP:
            TimestampType.TIMESTAMP.writeLong(builder, formatTimestampAsLong(object, (TimestampObjectInspector) inspector));
            return;
        case BINARY:
            VARBINARY.writeSlice(builder, Slices.wrappedBuffer(((BinaryObjectInspector) inspector).getPrimitiveJavaObject(object)));
            return;
    }
    throw new RuntimeException("Unknown primitive type: " + inspector.getPrimitiveCategory());
}
 
开发者ID:y-lan,项目名称:presto,代码行数:47,代码来源:SerDeUtils.java


示例13: formatTimestampAsLong

import org.apache.hadoop.hive.serde2.objectinspector.primitive.TimestampObjectInspector; //导入依赖的package包/类
private static long formatTimestampAsLong(Object object, TimestampObjectInspector inspector)
{
    Timestamp timestamp = getTimestamp(object, inspector);
    return timestamp.getTime();
}
 
开发者ID:y-lan,项目名称:presto,代码行数:6,代码来源:SerDeUtils.java



注:本文中的org.apache.hadoop.hive.serde2.objectinspector.primitive.TimestampObjectInspector类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java Activation类代码示例发布时间:2022-05-21
下一篇:
Java ViewUtils类代码示例发布时间:2022-05-21
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap