org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector.PrimitiveCategory Java Examples
The following examples show how to use
org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector.PrimitiveCategory.
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: ST_Bin.java From spatial-framework-for-hadoop with Apache License 2.0 | 6 votes |
@Override public ObjectInspector initialize(ObjectInspector[] OIs) throws UDFArgumentException { if (OIs.length != 2) { throw new UDFArgumentException("Function takes exactly 2 arguments"); } if (OIs[0].getCategory() != Category.PRIMITIVE) { throw new UDFArgumentException("Argument 0 must be a number - got: " + OIs[0].getCategory()); } oiBinSize = (PrimitiveObjectInspector)OIs[0]; if (!EnumSet.of(PrimitiveCategory.DECIMAL,PrimitiveCategory.DOUBLE,PrimitiveCategory.INT,PrimitiveCategory.LONG,PrimitiveCategory.SHORT, PrimitiveCategory.FLOAT).contains(oiBinSize.getPrimitiveCategory())) { throw new UDFArgumentException("Argument 0 must be a number - got: " + oiBinSize.getPrimitiveCategory()); } geomHelper = HiveGeometryOIHelper.create(OIs[1], 1); binSizeIsConstant = ObjectInspectorUtils.isConstantObjectInspector(OIs[0]); return PrimitiveObjectInspectorFactory.javaLongObjectInspector; }
Example #2
Source File: MDSMapObjectInspector.java From multiple-dimension-spread with Apache License 2.0 | 6 votes |
public MDSMapObjectInspector( final MapTypeInfo typeInfo ){ TypeInfo keyTypeInfo = typeInfo.getMapKeyTypeInfo(); if( keyTypeInfo.getCategory() == ObjectInspector.Category.PRIMITIVE && ( (PrimitiveTypeInfo)keyTypeInfo ).getPrimitiveCategory() == PrimitiveCategory.STRING ){ keyObjectInspector = PrimitiveObjectInspectorFactory.javaStringObjectInspector; } else{ throw new RuntimeException( "Map key type is string only." ); } valueObjectInspector = MDSObjectInspectorFactory.craeteObjectInspectorFromTypeInfo( typeInfo.getMapValueTypeInfo() ); if( valueObjectInspector.getCategory() == ObjectInspector.Category.PRIMITIVE ){ getField = new PrimitiveGetField( (PrimitiveObjectInspector)valueObjectInspector ); } else if( valueObjectInspector.getCategory() == ObjectInspector.Category.UNION ){ getField = new UnionGetField( (UnionTypeInfo)( typeInfo.getMapValueTypeInfo() ) ); } else{ getField = new NestedGetField(); } }
Example #3
Source File: UnionDoubleSummaryWithModeSketchUDAFTest.java From incubator-datasketches-hive with Apache License 2.0 | 6 votes |
static void checkIntermediateResultInspector(ObjectInspector resultInspector) { Assert.assertNotNull(resultInspector); Assert.assertEquals(resultInspector.getCategory(), ObjectInspector.Category.STRUCT); StructObjectInspector structResultInspector = (StructObjectInspector) resultInspector; List<?> fields = structResultInspector.getAllStructFieldRefs(); Assert.assertEquals(fields.size(), 3); ObjectInspector inspector1 = ((StructField) fields.get(0)).getFieldObjectInspector(); Assert.assertEquals(inspector1.getCategory(), ObjectInspector.Category.PRIMITIVE); PrimitiveObjectInspector primitiveInspector1 = (PrimitiveObjectInspector) inspector1; Assert.assertEquals(primitiveInspector1.getPrimitiveCategory(), PrimitiveCategory.INT); ObjectInspector inspector2 = ((StructField) fields.get(1)).getFieldObjectInspector(); Assert.assertEquals(inspector2.getCategory(), ObjectInspector.Category.PRIMITIVE); PrimitiveObjectInspector primitiveInspector2 = (PrimitiveObjectInspector) inspector2; Assert.assertEquals(primitiveInspector2.getPrimitiveCategory(), PrimitiveCategory.STRING); ObjectInspector inspector3 = ((StructField) fields.get(2)).getFieldObjectInspector(); Assert.assertEquals(inspector3.getCategory(), ObjectInspector.Category.PRIMITIVE); PrimitiveObjectInspector primitiveInspector3 = (PrimitiveObjectInspector) inspector3; Assert.assertEquals(primitiveInspector3.getPrimitiveCategory(), PrimitiveCategory.BINARY); }
Example #4
Source File: DataToDoubleSummaryWithModeSketchUDAFTest.java From incubator-datasketches-hive with Apache License 2.0 | 6 votes |
static void checkIntermediateResultInspector(ObjectInspector resultInspector) { Assert.assertNotNull(resultInspector); Assert.assertEquals(resultInspector.getCategory(), ObjectInspector.Category.STRUCT); StructObjectInspector structResultInspector = (StructObjectInspector) resultInspector; List<?> fields = structResultInspector.getAllStructFieldRefs(); Assert.assertEquals(fields.size(), 3); ObjectInspector inspector1 = ((StructField) fields.get(0)).getFieldObjectInspector(); Assert.assertEquals(inspector1.getCategory(), ObjectInspector.Category.PRIMITIVE); PrimitiveObjectInspector primitiveInspector1 = (PrimitiveObjectInspector) inspector1; Assert.assertEquals(primitiveInspector1.getPrimitiveCategory(), PrimitiveCategory.INT); ObjectInspector inspector2 = ((StructField) fields.get(1)).getFieldObjectInspector(); Assert.assertEquals(inspector2.getCategory(), ObjectInspector.Category.PRIMITIVE); PrimitiveObjectInspector primitiveInspector2 = (PrimitiveObjectInspector) inspector2; Assert.assertEquals(primitiveInspector2.getPrimitiveCategory(), PrimitiveCategory.STRING); ObjectInspector inspector3 = ((StructField) fields.get(2)).getFieldObjectInspector(); Assert.assertEquals(inspector3.getCategory(), ObjectInspector.Category.PRIMITIVE); PrimitiveObjectInspector primitiveInspector3 = (PrimitiveObjectInspector) inspector3; Assert.assertEquals(primitiveInspector3.getPrimitiveCategory(), PrimitiveCategory.BINARY); }
Example #5
Source File: HiveWriteUtils.java From presto with Apache License 2.0 | 6 votes |
private static boolean isWritableType(TypeInfo typeInfo) { switch (typeInfo.getCategory()) { case PRIMITIVE: PrimitiveCategory primitiveCategory = ((PrimitiveTypeInfo) typeInfo).getPrimitiveCategory(); return isWritablePrimitiveType(primitiveCategory); case MAP: MapTypeInfo mapTypeInfo = (MapTypeInfo) typeInfo; return isWritableType(mapTypeInfo.getMapKeyTypeInfo()) && isWritableType(mapTypeInfo.getMapValueTypeInfo()); case LIST: ListTypeInfo listTypeInfo = (ListTypeInfo) typeInfo; return isWritableType(listTypeInfo.getListElementTypeInfo()); case STRUCT: StructTypeInfo structTypeInfo = (StructTypeInfo) typeInfo; return structTypeInfo.getAllStructFieldTypeInfos().stream().allMatch(HiveWriteUtils::isWritableType); } return false; }
Example #6
Source File: GetFrequentItemsFromStringsSketchUDTFTest.java From incubator-datasketches-hive with Apache License 2.0 | 6 votes |
private static void checkResultInspector(ObjectInspector resultInspector) { Assert.assertNotNull(resultInspector); Assert.assertEquals(resultInspector.getCategory(), ObjectInspector.Category.STRUCT); List<? extends StructField> fields = ((StructObjectInspector) resultInspector).getAllStructFieldRefs(); Assert.assertEquals(fields.size(), 4); Assert.assertEquals(fields.get(0).getFieldObjectInspector().getCategory(), ObjectInspector.Category.PRIMITIVE); Assert.assertEquals( ((PrimitiveObjectInspector) fields.get(0).getFieldObjectInspector()).getPrimitiveCategory(), PrimitiveObjectInspector.PrimitiveCategory.STRING ); Assert.assertEquals(fields.get(1).getFieldObjectInspector().getCategory(), ObjectInspector.Category.PRIMITIVE); Assert.assertEquals( ((PrimitiveObjectInspector) fields.get(1).getFieldObjectInspector()).getPrimitiveCategory(), PrimitiveObjectInspector.PrimitiveCategory.LONG ); Assert.assertEquals(fields.get(2).getFieldObjectInspector().getCategory(), ObjectInspector.Category.PRIMITIVE); Assert.assertEquals( ((PrimitiveObjectInspector) fields.get(2).getFieldObjectInspector()).getPrimitiveCategory(), PrimitiveObjectInspector.PrimitiveCategory.LONG ); Assert.assertEquals(fields.get(3).getFieldObjectInspector().getCategory(), ObjectInspector.Category.PRIMITIVE); Assert.assertEquals( ((PrimitiveObjectInspector) fields.get(3).getFieldObjectInspector()).getPrimitiveCategory(), PrimitiveObjectInspector.PrimitiveCategory.LONG ); }
Example #7
Source File: DataToSketchUDAFTest.java From incubator-datasketches-hive with Apache License 2.0 | 6 votes |
static void checkIntermediateResultInspector(ObjectInspector resultInspector) { Assert.assertNotNull(resultInspector); Assert.assertEquals(resultInspector.getCategory(), ObjectInspector.Category.STRUCT); StructObjectInspector structResultInspector = (StructObjectInspector) resultInspector; List<?> fields = structResultInspector.getAllStructFieldRefs(); Assert.assertEquals(fields.size(), 3); ObjectInspector inspector1 = ((StructField) fields.get(0)).getFieldObjectInspector(); Assert.assertEquals(inspector1.getCategory(), ObjectInspector.Category.PRIMITIVE); PrimitiveObjectInspector primitiveInspector1 = (PrimitiveObjectInspector) inspector1; Assert.assertEquals(primitiveInspector1.getPrimitiveCategory(), PrimitiveCategory.INT); ObjectInspector inspector2 = ((StructField) fields.get(1)).getFieldObjectInspector(); Assert.assertEquals(inspector2.getCategory(), ObjectInspector.Category.PRIMITIVE); PrimitiveObjectInspector primitiveInspector2 = (PrimitiveObjectInspector) inspector2; Assert.assertEquals(primitiveInspector2.getPrimitiveCategory(), PrimitiveCategory.LONG); ObjectInspector inspector3 = ((StructField) fields.get(2)).getFieldObjectInspector(); Assert.assertEquals(inspector3.getCategory(), ObjectInspector.Category.PRIMITIVE); PrimitiveObjectInspector primitiveInspector3 = (PrimitiveObjectInspector) inspector3; Assert.assertEquals(primitiveInspector3.getPrimitiveCategory(), PrimitiveCategory.BINARY); }
Example #8
Source File: HiveWriteUtils.java From presto with Apache License 2.0 | 6 votes |
private static boolean isWritablePrimitiveType(PrimitiveCategory primitiveCategory) { switch (primitiveCategory) { case BOOLEAN: case LONG: case INT: case SHORT: case BYTE: case FLOAT: case DOUBLE: case STRING: case DATE: case TIMESTAMP: case BINARY: case DECIMAL: case VARCHAR: case CHAR: return true; } return false; }
Example #9
Source File: DataToSketchUDAFTest.java From incubator-datasketches-hive with Apache License 2.0 | 6 votes |
static void checkIntermediateResultInspector(ObjectInspector resultInspector) { Assert.assertNotNull(resultInspector); Assert.assertEquals(resultInspector.getCategory(), ObjectInspector.Category.STRUCT); StructObjectInspector structResultInspector = (StructObjectInspector) resultInspector; List<?> fields = structResultInspector.getAllStructFieldRefs(); Assert.assertEquals(fields.size(), 3); ObjectInspector inspector1 = ((StructField) fields.get(0)).getFieldObjectInspector(); Assert.assertEquals(inspector1.getCategory(), ObjectInspector.Category.PRIMITIVE); PrimitiveObjectInspector primitiveInspector1 = (PrimitiveObjectInspector) inspector1; Assert.assertEquals(primitiveInspector1.getPrimitiveCategory(), PrimitiveCategory.INT); ObjectInspector inspector2 = ((StructField) fields.get(1)).getFieldObjectInspector(); Assert.assertEquals(inspector2.getCategory(), ObjectInspector.Category.PRIMITIVE); PrimitiveObjectInspector primitiveInspector2 = (PrimitiveObjectInspector) inspector2; Assert.assertEquals(primitiveInspector2.getPrimitiveCategory(), PrimitiveCategory.STRING); ObjectInspector inspector3 = ((StructField) fields.get(2)).getFieldObjectInspector(); Assert.assertEquals(inspector3.getCategory(), ObjectInspector.Category.PRIMITIVE); PrimitiveObjectInspector primitiveInspector3 = (PrimitiveObjectInspector) inspector3; Assert.assertEquals(primitiveInspector3.getPrimitiveCategory(), PrimitiveCategory.BINARY); }
Example #10
Source File: DataToArrayOfDoublesSketchUDAFTest.java From incubator-datasketches-hive with Apache License 2.0 | 6 votes |
static void checkIntermediateResultInspector(ObjectInspector resultInspector) { Assert.assertNotNull(resultInspector); Assert.assertEquals(resultInspector.getCategory(), ObjectInspector.Category.STRUCT); StructObjectInspector structResultInspector = (StructObjectInspector) resultInspector; List<?> fields = structResultInspector.getAllStructFieldRefs(); Assert.assertEquals(fields.size(), 3); ObjectInspector inspector1 = ((StructField) fields.get(0)).getFieldObjectInspector(); Assert.assertEquals(inspector1.getCategory(), ObjectInspector.Category.PRIMITIVE); PrimitiveObjectInspector primitiveInspector1 = (PrimitiveObjectInspector) inspector1; Assert.assertEquals(primitiveInspector1.getPrimitiveCategory(), PrimitiveCategory.INT); ObjectInspector inspector2 = ((StructField) fields.get(1)).getFieldObjectInspector(); Assert.assertEquals(inspector2.getCategory(), ObjectInspector.Category.PRIMITIVE); PrimitiveObjectInspector primitiveInspector2 = (PrimitiveObjectInspector) inspector2; Assert.assertEquals(primitiveInspector2.getPrimitiveCategory(), PrimitiveCategory.INT); ObjectInspector inspector3 = ((StructField) fields.get(2)).getFieldObjectInspector(); Assert.assertEquals(inspector3.getCategory(), ObjectInspector.Category.PRIMITIVE); PrimitiveObjectInspector primitiveInspector3 = (PrimitiveObjectInspector) inspector3; Assert.assertEquals(primitiveInspector3.getPrimitiveCategory(), PrimitiveCategory.BINARY); }
Example #11
Source File: DataToSketchUDAFTest.java From incubator-datasketches-hive with Apache License 2.0 | 6 votes |
static void checkIntermediateResultInspector(ObjectInspector resultInspector) { Assert.assertNotNull(resultInspector); Assert.assertEquals(resultInspector.getCategory(), ObjectInspector.Category.STRUCT); StructObjectInspector structResultInspector = (StructObjectInspector) resultInspector; List<?> fields = structResultInspector.getAllStructFieldRefs(); Assert.assertEquals(fields.size(), 3); ObjectInspector inspector1 = ((StructField) fields.get(0)).getFieldObjectInspector(); Assert.assertEquals(inspector1.getCategory(), ObjectInspector.Category.PRIMITIVE); PrimitiveObjectInspector primitiveInspector1 = (PrimitiveObjectInspector) inspector1; Assert.assertEquals(primitiveInspector1.getPrimitiveCategory(), PrimitiveCategory.INT); ObjectInspector inspector2 = ((StructField) fields.get(1)).getFieldObjectInspector(); Assert.assertEquals(inspector2.getCategory(), ObjectInspector.Category.PRIMITIVE); PrimitiveObjectInspector primitiveInspector2 = (PrimitiveObjectInspector) inspector2; Assert.assertEquals(primitiveInspector2.getPrimitiveCategory(), PrimitiveCategory.LONG); ObjectInspector inspector3 = ((StructField) fields.get(2)).getFieldObjectInspector(); Assert.assertEquals(inspector3.getCategory(), ObjectInspector.Category.PRIMITIVE); PrimitiveObjectInspector primitiveInspector3 = (PrimitiveObjectInspector) inspector3; Assert.assertEquals(primitiveInspector3.getPrimitiveCategory(), PrimitiveCategory.BINARY); }
Example #12
Source File: IntersectSketchUDAFTest.java From incubator-datasketches-hive with Apache License 2.0 | 6 votes |
private static void checkIntermediateResultInspector(ObjectInspector resultInspector) { Assert.assertNotNull(resultInspector); Assert.assertEquals(resultInspector.getCategory(), ObjectInspector.Category.STRUCT); StructObjectInspector structResultInspector = (StructObjectInspector) resultInspector; List<?> fields = structResultInspector.getAllStructFieldRefs(); Assert.assertEquals(fields.size(), 2); ObjectInspector inspector1 = ((StructField) fields.get(0)).getFieldObjectInspector(); Assert.assertEquals(inspector1.getCategory(), ObjectInspector.Category.PRIMITIVE); PrimitiveObjectInspector primitiveInspector1 = (PrimitiveObjectInspector) inspector1; Assert.assertEquals(primitiveInspector1.getPrimitiveCategory(), PrimitiveCategory.LONG); ObjectInspector inspector2 = ((StructField) fields.get(1)).getFieldObjectInspector(); Assert.assertEquals(inspector2.getCategory(), ObjectInspector.Category.PRIMITIVE); PrimitiveObjectInspector primitiveInspector2 = (PrimitiveObjectInspector) inspector2; Assert.assertEquals(primitiveInspector2.getPrimitiveCategory(), PrimitiveCategory.BINARY); }
Example #13
Source File: UnionSketchUDAF.java From incubator-datasketches-hive with Apache License 2.0 | 6 votes |
/** * Perform argument count check and argument type checking, returns an * appropriate evaluator to perform based on input type (which should always * be BINARY sketch). Also check sketch size and seed params if they are passed in. * * @see org.apache.hadoop.hive.ql.udf.generic.AbstractGenericUDAFResolver * #getEvaluator(org.apache.hadoop.hive.ql.udf.generic.GenericUDAFParameterInfo) * * @param info The parameter info to validate * @return The GenericUDAFEvaluator to use to compute the function. */ @Override public GenericUDAFEvaluator getEvaluator(final GenericUDAFParameterInfo info) throws SemanticException { final ObjectInspector[] parameters = info.getParameterObjectInspectors(); if (parameters.length < 1) { throw new UDFArgumentException("Please specify at least 1 argument"); } if (parameters.length > 3) { throw new UDFArgumentTypeException(parameters.length - 1, "Please specify no more than 3 arguments"); } ObjectInspectorValidator.validateGivenPrimitiveCategory(parameters[0], 0, PrimitiveCategory.BINARY); if (parameters.length > 1) { ObjectInspectorValidator.validateIntegralParameter(parameters[1], 1); } if (parameters.length > 2) { ObjectInspectorValidator.validateIntegralParameter(parameters[2], 2); } return new UnionSketchUDAFEvaluator(); }
Example #14
Source File: HiveTypeConverter.java From metacat with Apache License 2.0 | 6 votes |
private static Type getPrimitiveType(final ObjectInspector fieldInspector) { final PrimitiveCategory primitiveCategory = ((PrimitiveObjectInspector) fieldInspector) .getPrimitiveCategory(); if (HiveTypeMapping.getHIVE_TO_CANONICAL().containsKey(primitiveCategory.name())) { return HiveTypeMapping.getHIVE_TO_CANONICAL().get(primitiveCategory.name()); } switch (primitiveCategory) { case DECIMAL: final DecimalTypeInfo decimalTypeInfo = (DecimalTypeInfo) ((PrimitiveObjectInspector) fieldInspector) .getTypeInfo(); return DecimalType.createDecimalType(decimalTypeInfo.precision(), decimalTypeInfo.getScale()); case CHAR: final int cLength = ((CharTypeInfo) ((PrimitiveObjectInspector) fieldInspector).getTypeInfo()).getLength(); return CharType.createCharType(cLength); case VARCHAR: final int vLength = ((VarcharTypeInfo) ((PrimitiveObjectInspector) fieldInspector) .getTypeInfo()).getLength(); return VarcharType.createVarcharType(vLength); default: return null; } }
Example #15
Source File: IntersectSketchUDAF.java From incubator-datasketches-hive with Apache License 2.0 | 6 votes |
@Override public GenericUDAFEvaluator getEvaluator(final GenericUDAFParameterInfo info) throws SemanticException { final ObjectInspector[] inspectors = info.getParameterObjectInspectors(); if (inspectors.length < 1) { throw new UDFArgumentException("Please specify at least 1 argument"); } if (inspectors.length > 2) { throw new UDFArgumentTypeException(inspectors.length - 1, "Please specify no more than 2 arguments"); } ObjectInspectorValidator.validateGivenPrimitiveCategory(inspectors[0], 0, PrimitiveCategory.BINARY); if (inspectors.length > 1) { ObjectInspectorValidator.validateIntegralParameter(inspectors[1], 1); } return new IntersectSketchUDAFEvaluator(); }
Example #16
Source File: DataToDoubleSummaryWithModeSketchUDAF.java From incubator-datasketches-hive with Apache License 2.0 | 6 votes |
@Override public ObjectInspector init(final Mode mode, final ObjectInspector[] inspectors) throws HiveException { final ObjectInspector resultInspector = super.init(mode, inspectors); if (mode == Mode.PARTIAL1 || mode == Mode.COMPLETE) { // input is original data if (inspectors.length > 4) { summaryModeInspector_ = (PrimitiveObjectInspector) inspectors[4]; } } if (mode == Mode.PARTIAL1 || mode == Mode.PARTIAL2) { // intermediate results need to include the nominal number of entries and the summary mode return ObjectInspectorFactory.getStandardStructObjectInspector( Arrays.asList(NOMINAL_NUM_ENTRIES_FIELD, SUMMARY_MODE_FIELD, SKETCH_FIELD), Arrays.asList( PrimitiveObjectInspectorFactory.getPrimitiveWritableObjectInspector(PrimitiveCategory.INT), PrimitiveObjectInspectorFactory.getPrimitiveWritableObjectInspector(PrimitiveCategory.STRING), PrimitiveObjectInspectorFactory.getPrimitiveWritableObjectInspector(PrimitiveCategory.BINARY) ) ); } return resultInspector; }
Example #17
Source File: UnionArrayOfDoublesSketchUDAF.java From incubator-datasketches-hive with Apache License 2.0 | 6 votes |
@Override public GenericUDAFEvaluator getEvaluator(final GenericUDAFParameterInfo info) throws SemanticException { final ObjectInspector[] inspectors = info.getParameterObjectInspectors(); if (inspectors.length < 1) { throw new UDFArgumentException("Expected at least 1 argument"); } if (inspectors.length > 3) { throw new UDFArgumentTypeException(inspectors.length - 1, "Expected no more than 3 arguments"); } ObjectInspectorValidator.validateGivenPrimitiveCategory(inspectors[0], 0, PrimitiveCategory.BINARY); // nominal number of entries if (inspectors.length > 1) { ObjectInspectorValidator.validateIntegralParameter(inspectors[1], 1); } // number of double values per key if (inspectors.length > 2) { ObjectInspectorValidator.validateIntegralParameter(inspectors[2], 2); } return new UnionArrayOfDoublesSketchEvaluator(); }
Example #18
Source File: UnionSketchUDAF.java From incubator-datasketches-hive with Apache License 2.0 | 6 votes |
@Override public GenericUDAFEvaluator getEvaluator(final GenericUDAFParameterInfo info) throws SemanticException { final ObjectInspector[] inspectors = info.getParameterObjectInspectors(); if (inspectors.length < 1) { throw new UDFArgumentException("Expected at least 1 argument"); } ObjectInspectorValidator.validateGivenPrimitiveCategory(inspectors[0], 0, PrimitiveCategory.BINARY); // nominal number of entries if (inspectors.length > 1) { ObjectInspectorValidator.validateIntegralParameter(inspectors[1], 1); } checkExtraArguments(inspectors); return createEvaluator(); }
Example #19
Source File: UnionDoubleSummaryWithModeSketchUDAF.java From incubator-datasketches-hive with Apache License 2.0 | 6 votes |
@Override public ObjectInspector init(final Mode mode, final ObjectInspector[] inspectors) throws HiveException { final ObjectInspector resultInspector = super.init(mode, inspectors); if ((mode == Mode.PARTIAL1) || (mode == Mode.COMPLETE)) { // input is original data if (inspectors.length > 2) { summaryModeInspector_ = (PrimitiveObjectInspector) inspectors[2]; } } if ((mode == Mode.PARTIAL1) || (mode == Mode.PARTIAL2)) { // intermediate results need to include the nominal number of entries and the summary mode return ObjectInspectorFactory.getStandardStructObjectInspector( Arrays.asList(NOMINAL_NUM_ENTRIES_FIELD, SUMMARY_MODE_FIELD, SKETCH_FIELD), Arrays.asList( PrimitiveObjectInspectorFactory.getPrimitiveWritableObjectInspector(PrimitiveCategory.INT), PrimitiveObjectInspectorFactory.getPrimitiveWritableObjectInspector(PrimitiveCategory.STRING), PrimitiveObjectInspectorFactory.getPrimitiveWritableObjectInspector(PrimitiveCategory.BINARY) ) ); } return resultInspector; }
Example #20
Source File: ItemsEvaluator.java From incubator-datasketches-hive with Apache License 2.0 | 6 votes |
@Override public ObjectInspector init(final Mode mode, final ObjectInspector[] parameters) throws HiveException { super.init(mode, parameters); inputObjectInspector = (PrimitiveObjectInspector) parameters[0]; // Parameters: // In PARTIAL1 and COMPLETE mode, the parameters are original data. // In PARTIAL2 and FINAL mode, the parameters are partial aggregations. if (mode == Mode.PARTIAL1 || mode == Mode.COMPLETE) { if (parameters.length > 1) { kObjectInspector = (PrimitiveObjectInspector) parameters[1]; } } return PrimitiveObjectInspectorFactory.getPrimitiveWritableObjectInspector(PrimitiveCategory.BINARY); }
Example #21
Source File: SketchEvaluator.java From incubator-datasketches-hive with Apache License 2.0 | 6 votes |
@Override public ObjectInspector init(final Mode mode, final ObjectInspector[] parameters) throws HiveException { super.init(mode, parameters); inputInspector_ = (PrimitiveObjectInspector) parameters[0]; // Parameters: // In PARTIAL1 and COMPLETE mode, the parameters are original data. // In PARTIAL2 and FINAL mode, the parameters are partial aggregations. if ((mode == Mode.PARTIAL1) || (mode == Mode.COMPLETE)) { if (parameters.length > 1) { kInspector_ = (PrimitiveObjectInspector) parameters[1]; } } return PrimitiveObjectInspectorFactory.getPrimitiveWritableObjectInspector(PrimitiveCategory.BINARY); }
Example #22
Source File: UnionSketchUDAF.java From incubator-datasketches-hive with Apache License 2.0 | 5 votes |
@Override public ObjectInspector init(final Mode mode, final ObjectInspector[] inspectors) throws HiveException { super.init(mode, inspectors); if ((mode == Mode.PARTIAL1) || (mode == Mode.COMPLETE)) { // input is original data sketchInspector_ = (PrimitiveObjectInspector) inspectors[0]; if (inspectors.length > 1) { nominalNumEntriesInspector_ = (PrimitiveObjectInspector) inspectors[1]; } } else { // input for PARTIAL2 and FINAL is the output from PARTIAL1 intermediateInspector_ = (StructObjectInspector) inspectors[0]; } if ((mode == Mode.PARTIAL1) || (mode == Mode.PARTIAL2)) { // intermediate results need to include the the nominal number of entries return ObjectInspectorFactory.getStandardStructObjectInspector( Arrays.asList(NOMINAL_NUM_ENTRIES_FIELD, SKETCH_FIELD), Arrays.asList( PrimitiveObjectInspectorFactory.getPrimitiveWritableObjectInspector(PrimitiveCategory.INT), PrimitiveObjectInspectorFactory.getPrimitiveWritableObjectInspector(PrimitiveCategory.BINARY) ) ); } // final results include just the sketch return PrimitiveObjectInspectorFactory.getPrimitiveWritableObjectInspector(PrimitiveCategory.BINARY); }
Example #23
Source File: ArrayOfDoublesSketchToValuesUDTFTest.java From incubator-datasketches-hive with Apache License 2.0 | 5 votes |
private static void checkResultInspector(ObjectInspector resultInspector) { Assert.assertNotNull(resultInspector); Assert.assertEquals(resultInspector.getCategory(), ObjectInspector.Category.STRUCT); List<? extends StructField> fields = ((StructObjectInspector) resultInspector).getAllStructFieldRefs(); Assert.assertEquals(fields.size(), 1); Assert.assertEquals(fields.get(0).getFieldObjectInspector().getCategory(), ObjectInspector.Category.LIST); Assert.assertEquals( ((PrimitiveObjectInspector) ((ListObjectInspector) fields.get(0).getFieldObjectInspector()).getListElementObjectInspector()).getPrimitiveCategory(), PrimitiveObjectInspector.PrimitiveCategory.DOUBLE ); }
Example #24
Source File: OrcTester.java From spliceengine with GNU Affero General Public License v3.0 | 5 votes |
private static boolean hasType(ObjectInspector objectInspector, PrimitiveCategory... types) { if (objectInspector instanceof PrimitiveObjectInspector) { PrimitiveObjectInspector primitiveInspector = (PrimitiveObjectInspector) objectInspector; PrimitiveCategory primitiveCategory = primitiveInspector.getPrimitiveCategory(); for (PrimitiveCategory type : types) { if (primitiveCategory == type) { return true; } } return false; } if (objectInspector instanceof ListObjectInspector) { ListObjectInspector listInspector = (ListObjectInspector) objectInspector; return hasType(listInspector.getListElementObjectInspector(), types); } if (objectInspector instanceof MapObjectInspector) { MapObjectInspector mapInspector = (MapObjectInspector) objectInspector; return hasType(mapInspector.getMapKeyObjectInspector(), types) || hasType(mapInspector.getMapValueObjectInspector(), types); } if (objectInspector instanceof StructObjectInspector) { for (org.apache.hadoop.hive.serde2.objectinspector.StructField field : ((StructObjectInspector) objectInspector).getAllStructFieldRefs()) { if (hasType(field.getFieldObjectInspector(), types)) { return true; } } return false; } throw new IllegalArgumentException("Unknown object inspector type " + objectInspector); }
Example #25
Source File: DataToSketchUDAF.java From incubator-datasketches-hive with Apache License 2.0 | 5 votes |
@Override public GenericUDAFEvaluator getEvaluator(final GenericUDAFParameterInfo info) throws SemanticException { final ObjectInspector[] inspectors = info.getParameterObjectInspectors(); if ((inspectors.length != 1) && (inspectors.length != 2)) { throw new UDFArgumentException("One or two arguments expected"); } ObjectInspectorValidator.validateGivenPrimitiveCategory(inspectors[0], 0, PrimitiveCategory.FLOAT); if (inspectors.length == 2) { ObjectInspectorValidator.validateGivenPrimitiveCategory(inspectors[1], 1, PrimitiveCategory.INT); } return new DataToSketchEvaluator(); }
Example #26
Source File: UnionDoubleSummaryWithModeSketchUDAF.java From incubator-datasketches-hive with Apache License 2.0 | 5 votes |
@Override protected void checkExtraArguments(final ObjectInspector[] inspectors) throws SemanticException { if (inspectors.length > 3) { throw new UDFArgumentException("Expected no more than 3 arguments"); } // summary mode if (inspectors.length > 2) { ObjectInspectorValidator.validateGivenPrimitiveCategory(inspectors[2], 2, PrimitiveCategory.STRING); } }
Example #27
Source File: DataToSketchUDAF.java From incubator-datasketches-hive with Apache License 2.0 | 5 votes |
@Override public GenericUDAFEvaluator getEvaluator(final GenericUDAFParameterInfo info) throws SemanticException { final ObjectInspector[] inspectors = info.getParameterObjectInspectors(); if (inspectors.length < 2) { throw new UDFArgumentException("Expected at least 2 arguments"); } ObjectInspectorValidator.validateCategoryPrimitive(inspectors[0], 0); // No validation of the value inspector since it can be anything. // Override this method to validate if needed. // nominal number of entries if (inspectors.length > 2) { ObjectInspectorValidator.validateIntegralParameter(inspectors[2], 2); } // sampling probability if (inspectors.length > 3) { ObjectInspectorValidator.validateCategoryPrimitive(inspectors[3], 3); final PrimitiveObjectInspector primitiveInspector = (PrimitiveObjectInspector) inspectors[3]; if ((primitiveInspector.getPrimitiveCategory() != PrimitiveCategory.FLOAT) && (primitiveInspector.getPrimitiveCategory() != PrimitiveCategory.DOUBLE)) { throw new UDFArgumentTypeException(3, "float or double value expected as parameter 4 but " + primitiveInspector.getPrimitiveCategory().name() + " was received"); } } checkExtraArguments(inspectors); return createEvaluator(); }
Example #28
Source File: DataToSketchUDAF.java From incubator-datasketches-hive with Apache License 2.0 | 5 votes |
@Override public ObjectInspector init(final Mode mode, final ObjectInspector[] inspectors) throws HiveException { super.init(mode, inspectors); mode_ = mode; if ((mode == Mode.PARTIAL1) || (mode == Mode.COMPLETE)) { // input is original data keyInspector_ = (PrimitiveObjectInspector) inspectors[0]; valueInspector_ = (PrimitiveObjectInspector) inspectors[1]; if (inspectors.length > 2) { nominalNumEntriesInspector_ = (PrimitiveObjectInspector) inspectors[2]; } if (inspectors.length > 3) { samplingProbabilityInspector_ = (PrimitiveObjectInspector) inspectors[3]; } } else { // input for PARTIAL2 and FINAL is the output from PARTIAL1 intermediateInspector_ = (StructObjectInspector) inspectors[0]; } if ((mode == Mode.PARTIAL1) || (mode == Mode.PARTIAL2)) { // intermediate results need to include the nominal number of entries return ObjectInspectorFactory.getStandardStructObjectInspector( Arrays.asList(NOMINAL_NUM_ENTRIES_FIELD, SKETCH_FIELD), Arrays.asList( PrimitiveObjectInspectorFactory.getPrimitiveWritableObjectInspector(PrimitiveCategory.INT), PrimitiveObjectInspectorFactory.getPrimitiveWritableObjectInspector(PrimitiveCategory.BINARY) ) ); } // final results include just the sketch return PrimitiveObjectInspectorFactory.getPrimitiveWritableObjectInspector(PrimitiveCategory.BINARY); }
Example #29
Source File: UnionArrayOfDoublesSketchUDAF.java From incubator-datasketches-hive with Apache License 2.0 | 5 votes |
@Override public ObjectInspector init(final Mode mode, final ObjectInspector[] inspectors) throws HiveException { super.init(mode, inspectors); if ((mode == Mode.PARTIAL1) || (mode == Mode.COMPLETE)) { // input is original data sketchInspector_ = (PrimitiveObjectInspector) inspectors[0]; if (inspectors.length > 1) { nominalNumEntriesInspector_ = (PrimitiveObjectInspector) inspectors[1]; } if (inspectors.length > 2) { numValuesInspector_ = (PrimitiveObjectInspector) inspectors[2]; } } else { // input for PARTIAL2 and FINAL is the output from PARTIAL1 intermediateInspector_ = (StructObjectInspector) inspectors[0]; } if ((mode == Mode.PARTIAL1) || (mode == Mode.PARTIAL2)) { // intermediate results need to include the the nominal number of entries and number of values return ObjectInspectorFactory.getStandardStructObjectInspector( Arrays.asList(NOMINAL_NUM_ENTRIES_FIELD, NUM_VALUES_FIELD, SKETCH_FIELD), Arrays.asList( PrimitiveObjectInspectorFactory.getPrimitiveWritableObjectInspector(PrimitiveCategory.INT), PrimitiveObjectInspectorFactory.getPrimitiveWritableObjectInspector(PrimitiveCategory.INT), PrimitiveObjectInspectorFactory.getPrimitiveWritableObjectInspector(PrimitiveCategory.BINARY) ) ); } // final results include just the sketch return PrimitiveObjectInspectorFactory.getPrimitiveWritableObjectInspector(PrimitiveCategory.BINARY); }
Example #30
Source File: DataToDoubleSummaryWithModeSketchUDAFTest.java From incubator-datasketches-hive with Apache License 2.0 | 5 votes |
static void checkFinalResultInspector(ObjectInspector resultInspector) { Assert.assertNotNull(resultInspector); Assert.assertEquals(resultInspector.getCategory(), ObjectInspector.Category.PRIMITIVE); Assert.assertEquals( ((PrimitiveObjectInspector) resultInspector).getPrimitiveCategory(), PrimitiveObjectInspector.PrimitiveCategory.BINARY ); }