org.apache.hadoop.hive.serde2.objectinspector.ConstantObjectInspector Java Examples
The following examples show how to use
org.apache.hadoop.hive.serde2.objectinspector.ConstantObjectInspector.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TestHiveGenericUDF.java From flink with Apache License 2.0 | 6 votes |
@Override public ObjectInspector initialize(ObjectInspector[] arguments) throws UDFArgumentException { checkArgument(arguments.length == 2); // TEST for constant arguments checkArgument(arguments[1] instanceof ConstantObjectInspector); Object constant = ((ConstantObjectInspector) arguments[1]).getWritableConstantValue(); checkArgument(constant instanceof IntWritable); checkArgument(((IntWritable) constant).get() == 1); if (arguments[0] instanceof IntObjectInspector || arguments[0] instanceof StringObjectInspector) { return arguments[0]; } else { throw new RuntimeException("Not support argument: " + arguments[0]); } }
Example #2
Source File: HiveUtils.java From incubator-hivemall with Apache License 2.0 | 6 votes |
@Nullable public static String[] getConstStringArray(@Nonnull final ObjectInspector oi) throws UDFArgumentException { if (!ObjectInspectorUtils.isConstantObjectInspector(oi)) { throw new UDFArgumentException("argument must be a constant value: " + TypeInfoUtils.getTypeInfoFromObjectInspector(oi)); } ConstantObjectInspector constOI = (ConstantObjectInspector) oi; if (constOI.getCategory() != Category.LIST) { throw new UDFArgumentException( "argument must be an array: " + TypeInfoUtils.getTypeInfoFromObjectInspector(oi)); } final List<?> lst = (List<?>) constOI.getWritableConstantValue(); if (lst == null) { return null; } final int size = lst.size(); final String[] ary = new String[size]; for (int i = 0; i < size; i++) { Object o = lst.get(i); if (o != null) { ary[i] = o.toString(); } } return ary; }
Example #3
Source File: HiveGenericUDF.java From flink with Apache License 2.0 | 6 votes |
@Override public Object evalInternal(Object[] args) { for (int i = 0; i < args.length; i++) { ((DeferredObjectAdapter) deferredObjects[i]).set(args[i]); } try { Object result = returnInspector instanceof ConstantObjectInspector ? ((ConstantObjectInspector) returnInspector).getWritableConstantValue() : function.evaluate(deferredObjects); return HiveInspectors.toFlinkObject(returnInspector, result, hiveShim); } catch (HiveException e) { throw new FlinkHiveUDFException(e); } }
Example #4
Source File: TestHiveGenericUDF.java From flink with Apache License 2.0 | 6 votes |
@Override public ObjectInspector initialize(ObjectInspector[] arguments) throws UDFArgumentException { checkArgument(arguments.length == 2); // TEST for constant arguments checkArgument(arguments[1] instanceof ConstantObjectInspector); Object constant = ((ConstantObjectInspector) arguments[1]).getWritableConstantValue(); checkArgument(constant instanceof IntWritable); checkArgument(((IntWritable) constant).get() == 1); if (arguments[0] instanceof IntObjectInspector || arguments[0] instanceof StringObjectInspector) { return arguments[0]; } else { throw new RuntimeException("Not support argument: " + arguments[0]); } }
Example #5
Source File: HiveInspectors.java From flink with Apache License 2.0 | 5 votes |
private static ConstantObjectInspector getPrimitiveJavaConstantObjectInspector(PrimitiveTypeInfo typeInfo, Object value) { switch (typeInfo.getPrimitiveCategory()) { case BOOLEAN: return new JavaConstantBooleanObjectInspector((Boolean) value); case BYTE: return new JavaConstantByteObjectInspector((Byte) value); case SHORT: return new JavaConstantShortObjectInspector((Short) value); case INT: return new JavaConstantIntObjectInspector((Integer) value); case LONG: return new JavaConstantLongObjectInspector((Long) value); case FLOAT: return new JavaConstantFloatObjectInspector((Float) value); case DOUBLE: return new JavaConstantDoubleObjectInspector((Double) value); case STRING: return new JavaConstantStringObjectInspector((String) value); case CHAR: return new JavaConstantHiveCharObjectInspector((HiveChar) value); case VARCHAR: return new JavaConstantHiveVarcharObjectInspector((HiveVarchar) value); case DATE: return new JavaConstantDateObjectInspector((Date) value); case TIMESTAMP: return new JavaConstantTimestampObjectInspector((Timestamp) value); case DECIMAL: return new JavaConstantHiveDecimalObjectInspector((HiveDecimal) value); case BINARY: return new JavaConstantBinaryObjectInspector((byte[]) value); case UNKNOWN: case VOID: // If type is null, we use the Java Constant String to replace return new JavaConstantStringObjectInspector((String) value); default: throw new FlinkHiveUDFException( String.format("Cannot find ConstantObjectInspector for %s", typeInfo)); } }
Example #6
Source File: TestHiveUDTF.java From flink with Apache License 2.0 | 5 votes |
@Override public StructObjectInspector initialize(ObjectInspector[] argOIs) throws UDFArgumentException { checkArgument(argOIs.length == 2); // TEST for constant arguments checkArgument(argOIs[1] instanceof ConstantObjectInspector); Object constant = ((ConstantObjectInspector) argOIs[1]).getWritableConstantValue(); checkArgument(constant instanceof IntWritable); checkArgument(((IntWritable) constant).get() == 1); return ObjectInspectorFactory.getStandardStructObjectInspector( Collections.singletonList("col1"), Collections.singletonList(PrimitiveObjectInspectorFactory.javaStringObjectInspector)); }
Example #7
Source File: StdUdfWrapper.java From transport with BSD 2-Clause "Simplified" License | 5 votes |
protected boolean containsNullValuedNonNullableConstants() { for (int i = 0; i < _inputObjectInspectors.length; i++) { if (!_nullableArguments[i] && _inputObjectInspectors[i] instanceof ConstantObjectInspector && ((ConstantObjectInspector) _inputObjectInspectors[i]).getWritableConstantValue() == null) { return true; } } return false; }
Example #8
Source File: HiveUtils.java From incubator-hivemall with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") @Nullable public static <T extends Writable> T getConstValue(@Nonnull final ObjectInspector oi) throws UDFArgumentException { if (!ObjectInspectorUtils.isConstantObjectInspector(oi)) { throw new UDFArgumentException("argument must be a constant value: " + TypeInfoUtils.getTypeInfoFromObjectInspector(oi)); } ConstantObjectInspector constOI = (ConstantObjectInspector) oi; Object v = constOI.getWritableConstantValue(); return (T) v; }
Example #9
Source File: HiveUtils.java From incubator-hivemall with Apache License 2.0 | 5 votes |
@Nullable public static double[] getConstDoubleArray(@Nonnull final ObjectInspector oi) throws UDFArgumentException { if (!ObjectInspectorUtils.isConstantObjectInspector(oi)) { throw new UDFArgumentException("argument must be a constant value: " + TypeInfoUtils.getTypeInfoFromObjectInspector(oi)); } ConstantObjectInspector constOI = (ConstantObjectInspector) oi; if (constOI.getCategory() != Category.LIST) { throw new UDFArgumentException( "argument must be an array: " + TypeInfoUtils.getTypeInfoFromObjectInspector(oi)); } StandardConstantListObjectInspector listOI = (StandardConstantListObjectInspector) constOI; PrimitiveObjectInspector elemOI = HiveUtils.asDoubleCompatibleOI(listOI.getListElementObjectInspector()); final List<?> lst = listOI.getWritableConstantValue(); if (lst == null) { return null; } final int size = lst.size(); final double[] ary = new double[size]; for (int i = 0; i < size; i++) { Object o = lst.get(i); if (o == null) { ary[i] = Double.NaN; } else { ary[i] = PrimitiveObjectInspectorUtils.getDouble(o, elemOI); } } return ary; }
Example #10
Source File: HiveUtils.java From incubator-hivemall with Apache License 2.0 | 5 votes |
@Nonnull public static ConstantObjectInspector asConstantObjectInspector( @Nonnull final ObjectInspector oi) throws UDFArgumentException { if (!ObjectInspectorUtils.isConstantObjectInspector(oi)) { throw new UDFArgumentException("argument must be a constant value: " + TypeInfoUtils.getTypeInfoFromObjectInspector(oi)); } return (ConstantObjectInspector) oi; }
Example #11
Source File: TestHiveUDTF.java From flink with Apache License 2.0 | 5 votes |
@Override public StructObjectInspector initialize(ObjectInspector[] argOIs) throws UDFArgumentException { checkArgument(argOIs.length == 2); // TEST for constant arguments checkArgument(argOIs[1] instanceof ConstantObjectInspector); Object constant = ((ConstantObjectInspector) argOIs[1]).getWritableConstantValue(); checkArgument(constant instanceof IntWritable); checkArgument(((IntWritable) constant).get() == 1); return ObjectInspectorFactory.getStandardStructObjectInspector( Collections.singletonList("col1"), Collections.singletonList(PrimitiveObjectInspectorFactory.javaStringObjectInspector)); }
Example #12
Source File: StdUdfWrapper.java From transport with BSD 2-Clause "Simplified" License | 4 votes |
private StdData[] wrapConstants() { return Arrays.stream(_inputObjectInspectors) .map(oi -> (oi instanceof ConstantObjectInspector) ? HiveWrapper.createStdData( ((ConstantObjectInspector) oi).getWritableConstantValue(), oi, _stdFactory) : null) .toArray(StdData[]::new); }