org.apache.hadoop.hive.ql.parse.SemanticException Java Examples

The following examples show how to use org.apache.hadoop.hive.ql.parse.SemanticException. 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: FMPredictGenericUDAF.java    From incubator-hivemall with Apache License 2.0 6 votes vote down vote up
@Override
public Evaluator getEvaluator(TypeInfo[] typeInfo) throws SemanticException {
    if (typeInfo.length != 3) {
        throw new UDFArgumentLengthException(
            "Expected argument length is 3 but given argument length was " + typeInfo.length);
    }
    if (!HiveUtils.isNumberTypeInfo(typeInfo[0])) {
        throw new UDFArgumentTypeException(0,
            "Number type is expected for the first argument Wj: " + typeInfo[0].getTypeName());
    }
    if (typeInfo[1].getCategory() != Category.LIST) {
        throw new UDFArgumentTypeException(1,
            "List type is expected for the second argument Vjf: " + typeInfo[1].getTypeName());
    }
    ListTypeInfo typeInfo1 = (ListTypeInfo) typeInfo[1];
    if (!HiveUtils.isNumberTypeInfo(typeInfo1.getListElementTypeInfo())) {
        throw new UDFArgumentTypeException(1,
            "Number type is expected for the element type of list Vjf: "
                    + typeInfo1.getTypeName());
    }
    if (!HiveUtils.isNumberTypeInfo(typeInfo[2])) {
        throw new UDFArgumentTypeException(2,
            "Number type is expected for the third argument Xj: " + typeInfo[2].getTypeName());
    }
    return new Evaluator();
}
 
Example #2
Source File: NDCGUDAF.java    From incubator-hivemall with Apache License 2.0 6 votes vote down vote up
@Override
public GenericUDAFEvaluator getEvaluator(@Nonnull TypeInfo[] typeInfo)
        throws SemanticException {
    if (typeInfo.length != 2 && typeInfo.length != 3) {
        throw new UDFArgumentTypeException(typeInfo.length - 1,
            "_FUNC_ takes two or three arguments");
    }

    ListTypeInfo arg1type = HiveUtils.asListTypeInfo(typeInfo[0]);
    if (!HiveUtils.isPrimitiveTypeInfo(arg1type.getListElementTypeInfo())
            && !HiveUtils.isStructTypeInfo(arg1type.getListElementTypeInfo())) {
        throw new UDFArgumentTypeException(0,
            "The first argument `array rankItems` is invalid form: " + typeInfo[0]);
    }
    ListTypeInfo arg2type = HiveUtils.asListTypeInfo(typeInfo[1]);
    if (!HiveUtils.isPrimitiveTypeInfo(arg2type.getListElementTypeInfo())) {
        throw new UDFArgumentTypeException(1,
            "The second argument `array correctItems` is invalid form: " + typeInfo[1]);
    }

    return new Evaluator();
}
 
Example #3
Source File: UnionSketchUDAF.java    From incubator-datasketches-hive with Apache License 2.0 6 votes vote down vote up
@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 #4
Source File: UDAFCollectAction.java    From 163-bigdate-note with GNU General Public License v3.0 6 votes vote down vote up
@Override
    public GenericUDAFEvaluator getEvaluator(TypeInfo[] parameters) throws SemanticException {
        //判断参数个数
        if (parameters.length != 2) {
            throw new UDFArgumentTypeException(parameters.length - 1, "Two argument is excepted.");
        }

        ObjectInspector oi = TypeInfoUtils.getStandardJavaObjectInspectorFromTypeInfo(parameters[0]);
//        ObjectInspector oi1 = TypeInfoUtils.getStandardJavaObjectInspectorFromTypeInfo(parameters[1]);
        if (oi.getCategory() != ObjectInspector.Category.PRIMITIVE) {
            throw new UDFArgumentTypeException(0, "Argument must be PRIMITIVE, but"
                + oi.getCategory().name()
                + " was passed.");
        }

//        PrimitiveObjectInspector inputOI = (PrimitiveObjectInspector) oi;
//        if (inputOI.getPrimitiveCategory() != PrimitiveObjectInspector.PrimitiveCategory.STRING) {
//            throw new UDFArgumentTypeException(0, "Argument must be String, but"
//                    + inputOI.getPrimitiveCategory().name()
//                    + " was passed.");
//        }

        return new AllActionsOfThisPeople30MinBefore();
    }
 
Example #5
Source File: UnionSketchUDAF.java    From incubator-datasketches-hive with Apache License 2.0 6 votes vote down vote up
/**
 * 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 #6
Source File: RuleDataSourceServiceImpl.java    From Qualitis with Apache License 2.0 6 votes vote down vote up
@Override
@Transactional(rollbackFor = {RuntimeException.class, SemanticException.class, ParseException.class})
public List<RuleDataSource> checkAndSaveCustomRuleDataSource(String clusterName, Rule savedRule) throws SemanticException, ParseException {
    String midTableAction = savedRule.getTemplate().getMidTableAction();
    midTableAction = midTableAction.replace("${filter}", savedRule.getWhereContent());
    midTableAction = DateExprReplaceUtil.replaceDateExpr(midTableAction);
    HiveSqlParser hiveSqlParser = new HiveSqlParser();
    Map<String, List<String>> dbAndTables = hiveSqlParser.checkSelectSqlAndGetDbAndTable(midTableAction);

    List<RuleDataSource> ruleDataSources = new ArrayList<>();
    for (String db : dbAndTables.keySet()) {
        for (String table : dbAndTables.get(db)) {
            RuleDataSource ruleDataSource = new RuleDataSource();
            ruleDataSource.setClusterName(clusterName);
            ruleDataSource.setProjectId(savedRule.getProject().getId());
            ruleDataSource.setRule(savedRule);
            ruleDataSource.setTableName(table);
            ruleDataSource.setDbName(db);
            ruleDataSources.add(ruleDataSource);
            ruleDataSource.setColName(savedRule.getFunctionContent());
            LOGGER.info("Succeed to save rule_datasource. rule_datasource: {}", ruleDataSources);
        }
    }
    LOGGER.info("Succeed to save all rule datasource: {}");
    return ruleDatasourceDao.saveAllRuleDataSource(ruleDataSources);
}
 
Example #7
Source File: HitRateUDAF.java    From incubator-hivemall with Apache License 2.0 6 votes vote down vote up
@Override
public GenericUDAFEvaluator getEvaluator(@Nonnull TypeInfo[] typeInfo)
        throws SemanticException {
    if (typeInfo.length != 2 && typeInfo.length != 3) {
        throw new UDFArgumentTypeException(typeInfo.length - 1,
            "_FUNC_ takes two or three arguments");
    }

    ListTypeInfo arg1type = HiveUtils.asListTypeInfo(typeInfo[0]);
    if (!HiveUtils.isPrimitiveTypeInfo(arg1type.getListElementTypeInfo())) {
        throw new UDFArgumentTypeException(0,
            "The first argument `array rankItems` is invalid form: " + typeInfo[0]);
    }
    ListTypeInfo arg2type = HiveUtils.asListTypeInfo(typeInfo[1]);
    if (!HiveUtils.isPrimitiveTypeInfo(arg2type.getListElementTypeInfo())) {
        throw new UDFArgumentTypeException(1,
            "The second argument `array correctItems` is invalid form: " + typeInfo[1]);
    }

    return new HitRateUDAF.Evaluator();
}
 
Example #8
Source File: AUCUDAF.java    From incubator-hivemall with Apache License 2.0 6 votes vote down vote up
@Override
public GenericUDAFEvaluator getEvaluator(@Nonnull TypeInfo[] typeInfo)
        throws SemanticException {
    if (typeInfo.length != 2 && typeInfo.length != 3) {
        throw new UDFArgumentTypeException(typeInfo.length - 1,
            "_FUNC_ takes two or three arguments");
    }

    if (HiveUtils.isNumberTypeInfo(typeInfo[0]) && HiveUtils.isIntegerTypeInfo(typeInfo[1])) {
        return new ClassificationEvaluator();
    } else {
        ListTypeInfo arg1type = HiveUtils.asListTypeInfo(typeInfo[0]);
        if (!HiveUtils.isPrimitiveTypeInfo(arg1type.getListElementTypeInfo())) {
            throw new UDFArgumentTypeException(0,
                "The first argument `array rankItems` is invalid form: " + typeInfo[0]);
        }

        ListTypeInfo arg2type = HiveUtils.asListTypeInfo(typeInfo[1]);
        if (!HiveUtils.isPrimitiveTypeInfo(arg2type.getListElementTypeInfo())) {
            throw new UDFArgumentTypeException(1,
                "The second argument `array correctItems` is invalid form: " + typeInfo[1]);
        }

        return new RankingEvaluator();
    }
}
 
Example #9
Source File: DataToDoublesSketchUDAF.java    From incubator-datasketches-hive with Apache License 2.0 5 votes vote down vote up
@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.DOUBLE);
  if (inspectors.length == 2) {
    ObjectInspectorValidator.validateGivenPrimitiveCategory(inspectors[1], 1,
        PrimitiveCategory.INT);
  }
  return new DataToSketchEvaluator();
}
 
Example #10
Source File: PLSAPredictUDAF.java    From incubator-hivemall with Apache License 2.0 5 votes vote down vote up
@Override
public Evaluator getEvaluator(TypeInfo[] typeInfo) throws SemanticException {
    if (typeInfo.length != 4 && typeInfo.length != 5) {
        throw new UDFArgumentLengthException(
            "Expected argument length is 4 or 5 but given argument length was "
                    + typeInfo.length);
    }

    if (!HiveUtils.isStringTypeInfo(typeInfo[0])) {
        throw new UDFArgumentTypeException(0,
            "String type is expected for the first argument word: "
                    + typeInfo[0].getTypeName());
    }
    if (!HiveUtils.isNumberTypeInfo(typeInfo[1])) {
        throw new UDFArgumentTypeException(1,
            "Number type is expected for the second argument value: "
                    + typeInfo[1].getTypeName());
    }
    if (!HiveUtils.isIntegerTypeInfo(typeInfo[2])) {
        throw new UDFArgumentTypeException(2,
            "Integer type is expected for the third argument label: "
                    + typeInfo[2].getTypeName());
    }
    if (!HiveUtils.isNumberTypeInfo(typeInfo[3])) {
        throw new UDFArgumentTypeException(3,
            "Number type is expected for the forth argument prob: "
                    + typeInfo[3].getTypeName());
    }

    if (typeInfo.length == 5) {
        if (!HiveUtils.isStringTypeInfo(typeInfo[4])) {
            throw new UDFArgumentTypeException(4,
                "String type is expected for the fifth argument prob: "
                        + typeInfo[4].getTypeName());
        }
    }

    return new Evaluator();
}
 
Example #11
Source File: ApproxCountDistinctUDAF.java    From incubator-hivemall with Apache License 2.0 5 votes vote down vote up
@Override
public GenericUDAFEvaluator getEvaluator(@Nonnull TypeInfo[] typeInfo)
        throws SemanticException {
    if (typeInfo.length != 1 && typeInfo.length != 2) {
        throw new UDFArgumentTypeException(typeInfo.length - 1,
            "_FUNC_ takes one or two arguments");
    }
    if (typeInfo.length == 2 && !HiveUtils.isStringTypeInfo(typeInfo[1])) {
        throw new UDFArgumentTypeException(1,
            "The second argument type expected to be const string: " + typeInfo[1]);
    }

    return new HLLEvaluator();
}
 
Example #12
Source File: RuleBatchServiceImpl.java    From Qualitis with Apache License 2.0 5 votes vote down vote up
private void addCustomRule(Map<String, List<ExcelCustomRule>> customRulePartitionedByRuleName, Project project) throws UnExpectedRequestException, SemanticException, ParseException {
    // Construct request and add rule
    List<AddCustomRuleRequest> addRuleRequests = constructAddCustomRuleRequest(customRulePartitionedByRuleName, project);

    // Add rule
    LOGGER.info("Start to add all custom rules");
    for (AddCustomRuleRequest addCustomRuleRequest : addRuleRequests) {
        LOGGER.info("Start to add custom rule. request: {}", addCustomRuleRequest);
        customRuleService.addCustomRule(addCustomRuleRequest);
    }
    LOGGER.info("Succeed to add all custom rules");
}
 
Example #13
Source File: UnionSketchUDAF.java    From incubator-datasketches-hive with Apache License 2.0 5 votes vote down vote up
/**
 * 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 lgK and target HLL type parameters 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[] inspectors = info.getParameterObjectInspectors();

  if (inspectors.length < 1) {
    throw new UDFArgumentException("Please specify at least 1 argument");
  }

  if (inspectors.length > 3) {
    throw new UDFArgumentTypeException(inspectors.length - 1, "Please specify no more than 3 arguments");
  }

  ObjectInspectorValidator.validateGivenPrimitiveCategory(inspectors[0], 0, PrimitiveCategory.BINARY);

  // Validate second argument if present
  if (inspectors.length > 1) {
    ObjectInspectorValidator.validateIntegralParameter(inspectors[1], 1);
    if (!ObjectInspectorUtils.isConstantObjectInspector(inspectors[1])) {
      throw new UDFArgumentTypeException(1, "The second argument must be a constant");
    }
  }

  // Validate third argument if present
  if (inspectors.length > 2) {
    ObjectInspectorValidator.validateGivenPrimitiveCategory(inspectors[2], 2, PrimitiveCategory.STRING);
    if (!ObjectInspectorUtils.isConstantObjectInspector(inspectors[2])) {
      throw new UDFArgumentTypeException(2, "The third argument must be a constant");
    }
  }

  return new UnionSketchUDAFEvaluator();
}
 
Example #14
Source File: RuleBatchServiceImpl.java    From Qualitis with Apache License 2.0 5 votes vote down vote up
@Override
@Transactional(rollbackFor = {RuntimeException.class, UnExpectedRequestException.class})
public GeneralResponse<?> uploadRules(InputStream fileInputStream, FormDataContentDisposition fileDisposition, Long projectId) throws UnExpectedRequestException, IOException, MetaDataAcquireFailedException, SemanticException, ParseException {
    // Check Arguments
    if (fileInputStream == null || fileDisposition == null) {
        throw new UnExpectedRequestException("{&FILE_CAN_NOT_BE_NULL_OR_EMPTY}");
    }

    // Check suffix name of file
    String fileName = fileDisposition.getFileName();
    String suffixName = fileName.substring(fileName.lastIndexOf('.'));
    if (!suffixName.equals(SUPPORT_EXCEL_SUFFIX_NAME)) {
        throw new UnExpectedRequestException("{&DO_NOT_SUPPORT_SUFFIX_NAME}: [" + suffixName + "]. {&ONLY_SUPPORT} [" + SUPPORT_EXCEL_SUFFIX_NAME + "]");
    }
    Project projectInDb = projectDao.findById(projectId);
    if (projectInDb == null) {
        throw new UnExpectedRequestException("{&PROJECT_ID} {&DOES_NOT_EXIST}");
    }

    String username = HttpUtils.getUserName(httpServletRequest);
    if (username == null) {
        return new GeneralResponse<>("401", "{&PLEASE_LOGIN}", null);
    }

    ExcelRuleListener excelRuleListener = readExcel(fileInputStream);
    if (excelRuleListener.getCustomExcelContent().isEmpty() && excelRuleListener.getTemplateExcelContent().isEmpty()
            && excelRuleListener.getMultiTemplateExcelContent().isEmpty()) {
        throw new UnExpectedRequestException("{&FILE_CAN_NOT_BE_EMPTY_OR_FILE_CAN_NOT_BE_RECOGNIZED}");
    }
    getAndSaveRule(excelRuleListener.getTemplateExcelContent(), excelRuleListener.getCustomExcelContent(),
            excelRuleListener.getMultiTemplateExcelContent(), projectInDb, username);
    fileInputStream.close();
    return new GeneralResponse<>("200", "{&SUCCEED_TO_UPLOAD_FILE}", null);
}
 
Example #15
Source File: DataToSketchUDAFTest.java    From incubator-datasketches-hive with Apache License 2.0 5 votes vote down vote up
@Test(expectedExceptions = { UDFArgumentException.class })
public void initTooManyArguments() throws SemanticException {
  DataToSketchUDAF udf = new DataToSketchUDAF();
  GenericUDAFParameterInfo params = new SimpleGenericUDAFParameterInfo(new ObjectInspector[] {
    intInspector, intConstantInspector, floatConstantInspector, longConstantInspector, longConstantInspector
  }, false, false, false);
  udf.getEvaluator(params);
}
 
Example #16
Source File: DataToItemsSketchUDAF.java    From incubator-datasketches-hive with Apache License 2.0 5 votes vote down vote up
@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.validateCategoryPrimitive(inspectors[0], 0);
  if (inspectors.length == 2) {
    ObjectInspectorValidator.validateGivenPrimitiveCategory(inspectors[1], 1, PrimitiveCategory.INT);
  }
  return createEvaluator();
}
 
Example #17
Source File: LDAPredictUDAF.java    From incubator-hivemall with Apache License 2.0 5 votes vote down vote up
@Override
public Evaluator getEvaluator(TypeInfo[] typeInfo) throws SemanticException {
    if (typeInfo.length != 4 && typeInfo.length != 5) {
        throw new UDFArgumentLengthException(
            "Expected argument length is 4 or 5 but given argument length was "
                    + typeInfo.length);
    }

    if (!HiveUtils.isStringTypeInfo(typeInfo[0])) {
        throw new UDFArgumentTypeException(0,
            "String type is expected for the first argument word: "
                    + typeInfo[0].getTypeName());
    }
    if (!HiveUtils.isNumberTypeInfo(typeInfo[1])) {
        throw new UDFArgumentTypeException(1,
            "Number type is expected for the second argument value: "
                    + typeInfo[1].getTypeName());
    }
    if (!HiveUtils.isIntegerTypeInfo(typeInfo[2])) {
        throw new UDFArgumentTypeException(2,
            "Integer type is expected for the third argument label: "
                    + typeInfo[2].getTypeName());
    }
    if (!HiveUtils.isNumberTypeInfo(typeInfo[3])) {
        throw new UDFArgumentTypeException(3,
            "Number type is expected for the forth argument lambda: "
                    + typeInfo[3].getTypeName());
    }

    if (typeInfo.length == 5) {
        if (!HiveUtils.isStringTypeInfo(typeInfo[4])) {
            throw new UDFArgumentTypeException(4,
                "String type is expected for the fifth argument lambda: "
                        + typeInfo[4].getTypeName());
        }
    }

    return new Evaluator();
}
 
Example #18
Source File: FMeasureUDAF.java    From incubator-hivemall with Apache License 2.0 5 votes vote down vote up
@Override
public GenericUDAFEvaluator getEvaluator(@Nonnull TypeInfo[] typeInfo)
        throws SemanticException {
    if (typeInfo.length != 2 && typeInfo.length != 3) {
        throw new UDFArgumentTypeException(typeInfo.length - 1,
            "_FUNC_ takes two or three arguments");
    }

    boolean isArg1ListOrIntOrBoolean =
            HiveUtils.isListTypeInfo(typeInfo[0]) || HiveUtils.isIntegerTypeInfo(typeInfo[0])
                    || HiveUtils.isBooleanTypeInfo(typeInfo[0]);
    if (!isArg1ListOrIntOrBoolean) {
        throw new UDFArgumentTypeException(0,
            "The first argument `array/int/boolean actual` is invalid form: " + typeInfo[0]);
    }

    boolean isArg2ListOrIntOrBoolean =
            HiveUtils.isListTypeInfo(typeInfo[1]) || HiveUtils.isIntegerTypeInfo(typeInfo[1])
                    || HiveUtils.isBooleanTypeInfo(typeInfo[1]);
    if (!isArg2ListOrIntOrBoolean) {
        throw new UDFArgumentTypeException(1,
            "The second argument `array/int/boolean predicted` is invalid form: "
                    + typeInfo[1]);
    }

    if (!typeInfo[0].equals(typeInfo[1])) {
        throw new UDFArgumentTypeException(1,
            "The first argument `actual`'s type is " + typeInfo[0]
                    + ", but the second argument `predicted`'s type is not match: "
                    + typeInfo[1]);
    }

    return new Evaluator();
}
 
Example #19
Source File: UnionItemsSketchUDAF.java    From incubator-datasketches-hive with Apache License 2.0 5 votes vote down vote up
@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.BINARY);
  if (inspectors.length == 2) {
    ObjectInspectorValidator.validateGivenPrimitiveCategory(inspectors[1], 1, PrimitiveCategory.INT);
  }
 return createEvaluator();
}
 
Example #20
Source File: UnionSketchUDAFTest.java    From incubator-datasketches-hive with Apache License 2.0 5 votes vote down vote up
@Test(expectedExceptions = { UDFArgumentTypeException.class })
public void initIvalidCategoryArg2() throws SemanticException {
  UnionSketchUDAF udf = new UnionSketchUDAF();
  GenericUDAFParameterInfo params = new SimpleGenericUDAFParameterInfo(
      new ObjectInspector[] { binaryInspector, structInspector }, false, false, false);
  udf.getEvaluator(params);
}
 
Example #21
Source File: RandomForestEnsembleUDAF.java    From incubator-hivemall with Apache License 2.0 5 votes vote down vote up
@Override
public GenericUDAFEvaluator getEvaluator(@Nonnull final TypeInfo[] typeInfo)
        throws SemanticException {
    switch (typeInfo.length) {
        case 1: {
            if (!HiveUtils.isIntegerTypeInfo(typeInfo[0])) {
                throw new UDFArgumentTypeException(0, "Expected INT for yhat: " + typeInfo[0]);
            }
            return new RfEvaluatorV1();
        }
        case 3:
            if (!HiveUtils.isFloatingPointTypeInfo(typeInfo[2])) {
                throw new UDFArgumentTypeException(2,
                    "Expected DOUBLE or FLOAT for model_weight: " + typeInfo[2]);
            }
            /* fall through */
        case 2: {// typeInfo.length == 2 || typeInfo.length == 3
            if (!HiveUtils.isIntegerTypeInfo(typeInfo[0])) {
                throw new UDFArgumentTypeException(0, "Expected INT for yhat: " + typeInfo[0]);
            }
            if (!HiveUtils.isFloatingPointListTypeInfo(typeInfo[1])) {
                throw new UDFArgumentTypeException(1,
                    "ARRAY<double> is expected for a posteriori: " + typeInfo[1]);
            }
            return new RfEvaluatorV2();
        }
        default:
            throw new UDFArgumentLengthException(
                "Expected 1~3 arguments but got " + typeInfo.length);
    }
}
 
Example #22
Source File: ObjectInspectorValidator.java    From incubator-datasketches-hive with Apache License 2.0 5 votes vote down vote up
static void validateGivenPrimitiveCategory(final ObjectInspector inspector, final int index,
    final PrimitiveObjectInspector.PrimitiveCategory category) throws SemanticException
{
  validateCategoryPrimitive(inspector, index);
  final PrimitiveObjectInspector primitiveInspector = (PrimitiveObjectInspector) inspector;
  if (primitiveInspector.getPrimitiveCategory() != category) {
    throw new UDFArgumentTypeException(index, category.name() + " value expected as the argument "
        + (index + 1) + " but " + primitiveInspector.getPrimitiveCategory().name() + " was received");
  }
}
 
Example #23
Source File: UnionSketchUDAFTest.java    From incubator-datasketches-hive with Apache License 2.0 5 votes vote down vote up
@Test(expectedExceptions = { UDFArgumentTypeException.class })
public void initInvalidTypeArg2() throws SemanticException {
  UnionSketchUDAF udf = new UnionSketchUDAF();
  GenericUDAFParameterInfo params = new SimpleGenericUDAFParameterInfo(
      new ObjectInspector[] { binaryInspector, binaryInspector }, false, false, false);
  udf.getEvaluator(params);
}
 
Example #24
Source File: UnionSketchUDAFTest.java    From incubator-datasketches-hive with Apache License 2.0 5 votes vote down vote up
@Test(expectedExceptions = { UDFArgumentTypeException.class })
public void initInvalidTypeArg3() throws SemanticException {
  UnionSketchUDAF udf = new UnionSketchUDAF();
  GenericUDAFParameterInfo params = new SimpleGenericUDAFParameterInfo(
      new ObjectInspector[] { binaryInspector, intInspector, binaryInspector }, false, false, false);
  udf.getEvaluator(params);
}
 
Example #25
Source File: CollectAllUDAF.java    From incubator-hivemall with Apache License 2.0 5 votes vote down vote up
@Override
public GenericUDAFEvaluator getEvaluator(TypeInfo[] tis) throws SemanticException {
    if (tis.length != 1) {
        throw new UDFArgumentTypeException(tis.length - 1, "Exactly one argument is expected.");
    }
    return new CollectAllEvaluator();
}
 
Example #26
Source File: ArrayAvgGenericUDAF.java    From incubator-hivemall with Apache License 2.0 5 votes vote down vote up
@Override
public GenericUDAFEvaluator getEvaluator(TypeInfo[] typeInfo) throws SemanticException {
    if (typeInfo.length != 1) {
        throw new UDFArgumentTypeException(typeInfo.length - 1,
            "One argument is expected, taking an array as an argument");
    }
    if (!typeInfo[0].getCategory().equals(Category.LIST)) {
        throw new UDFArgumentTypeException(typeInfo.length - 1,
            "One argument is expected, taking an array as an argument");
    }
    return new Evaluator();
}
 
Example #27
Source File: MinByUDAF.java    From incubator-hivemall with Apache License 2.0 5 votes vote down vote up
@Override
public GenericUDAFEvaluator getEvaluator(@Nonnull TypeInfo[] argTypes)
        throws SemanticException {
    if (argTypes.length != 2) {
        throw new UDFArgumentLengthException(
            "Exactly two arguments are expected: " + argTypes.length);
    }
    ObjectInspector yOI = TypeInfoUtils.getStandardJavaObjectInspectorFromTypeInfo(argTypes[1]);
    if (!ObjectInspectorUtils.compareSupported(yOI)) {
        throw new UDFArgumentTypeException(1,
            "Cannot support comparison of map<> type or complex type containing map<>.");
    }
    return new Evaluator();
}
 
Example #28
Source File: ObjectInspectorValidator.java    From incubator-datasketches-hive with Apache License 2.0 5 votes vote down vote up
static void validateCategoryPrimitive(
    final ObjectInspector inspector, final int index) throws SemanticException {
  if (inspector.getCategory() != ObjectInspector.Category.PRIMITIVE) {
    throw new UDFArgumentTypeException(index, "Primitive argument expected, but "
        + inspector.getCategory().name() + " was recieved");
  }
}
 
Example #29
Source File: MajorityVoteUDAF.java    From incubator-hivemall with Apache License 2.0 5 votes vote down vote up
@Override
public GenericUDAFEvaluator getEvaluator(@Nonnull final TypeInfo[] argTypes)
        throws SemanticException {
    if (argTypes.length != 1) {
        throw new UDFArgumentLengthException(
            "Expected ecactly one argument: " + argTypes.length);
    }
    if (!HiveUtils.isPrimitiveTypeInfo(argTypes[0])) {
        throw new UDFArgumentTypeException(0,
            "PRIMITIVE type is expected but got " + argTypes[0]);
    }
    return new Evaluator();
}
 
Example #30
Source File: MergeMapsUDAF.java    From incubator-hivemall with Apache License 2.0 5 votes vote down vote up
@Override
public MergeMapsEvaluator getEvaluator(TypeInfo[] types) throws SemanticException {
    if (types.length != 1) {
        throw new UDFArgumentTypeException(types.length - 1,
            "One argument is expected but got " + types.length);
    }
    TypeInfo paramType = types[0];
    if (paramType.getCategory() != Category.MAP) {
        throw new UDFArgumentTypeException(0, "Only maps supported for now ");
    }
    return new MergeMapsEvaluator();
}