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 Project: Qualitis   Author: WeBankFinTech   File: RuleDataSourceServiceImpl.java    License: 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 #2
Source Project: 163-bigdate-note   Author: jiaoqiyuan   File: UDAFCollectAction.java    License: 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 #3
Source Project: incubator-hivemall   Author: apache   File: FMPredictGenericUDAF.java    License: 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 #4
Source Project: incubator-hivemall   Author: apache   File: HitRateUDAF.java    License: 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 #5
Source Project: incubator-hivemall   Author: apache   File: AUCUDAF.java    License: 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 #6
Source Project: incubator-hivemall   Author: apache   File: NDCGUDAF.java    License: 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 #7
Source Project: incubator-datasketches-hive   Author: apache   File: UnionSketchUDAF.java    License: 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 #8
Source Project: incubator-datasketches-hive   Author: apache   File: UnionSketchUDAF.java    License: 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 #9
Source Project: incubator-datasketches-hive   Author: apache   File: DataToSketchUDAFTest.java    License: 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 #10
Source Project: Qualitis   Author: WeBankFinTech   File: RuleBatchServiceImpl.java    License: 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 #11
Source Project: Qualitis   Author: WeBankFinTech   File: RuleBatchServiceImpl.java    License: 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 #12
Source Project: incubator-datasketches-hive   Author: apache   File: UnionSketchUDAFTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test(expectedExceptions = { UDFArgumentTypeException.class })
public void initIvalidCategoryArg3() throws SemanticException {
  UnionSketchUDAF udf = new UnionSketchUDAF();
  GenericUDAFParameterInfo params = new SimpleGenericUDAFParameterInfo(
      new ObjectInspector[] { binaryInspector, intInspector, structInspector }, false, false, false);
  udf.getEvaluator(params);
}
 
Example #13
Source Project: circus-train   Author: HotelsDotCom   File: TableProcessor.java    License: Apache License 2.0 5 votes vote down vote up
private String extractTableName(ASTNode tabNameNode) {
  try {
    return BaseSemanticAnalyzer.getDotName(BaseSemanticAnalyzer.getQualifiedTableName(tabNameNode));
  } catch (SemanticException e) {
    throw new RuntimeException("Unable to extract qualified table name from node: " + tabNameNode.dump(), e);
  }
}
 
Example #14
Source Project: incubator-hivemall   Author: apache   File: FFMPredictGenericUDAF.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public Evaluator getEvaluator(@Nonnull TypeInfo[] typeInfo) throws SemanticException {
    if (typeInfo.length != 5) {
        throw new UDFArgumentLengthException(
            "Expected argument length is 5 but given argument length was " + typeInfo.length);
    }
    if (!HiveUtils.isNumberTypeInfo(typeInfo[0])) {
        throw new UDFArgumentTypeException(0,
            "Number type is expected for the first argument Wi: " + typeInfo[0].getTypeName());
    }
    if (typeInfo[1].getCategory() != Category.LIST) {
        throw new UDFArgumentTypeException(1,
            "List type is expected for the second argument Vifj: " + typeInfo[1].getTypeName());
    }
    if (typeInfo[2].getCategory() != Category.LIST) {
        throw new UDFArgumentTypeException(2,
            "List type is expected for the third argument Vjfi: " + typeInfo[2].getTypeName());
    }
    ListTypeInfo typeInfo1 = (ListTypeInfo) typeInfo[1];
    if (!HiveUtils.isFloatingPointTypeInfo(typeInfo1.getListElementTypeInfo())) {
        throw new UDFArgumentTypeException(1,
            "Double or Float type is expected for the element type of list Vifj: "
                    + typeInfo1.getTypeName());
    }
    ListTypeInfo typeInfo2 = (ListTypeInfo) typeInfo[2];
    if (!HiveUtils.isFloatingPointTypeInfo(typeInfo2.getListElementTypeInfo())) {
        throw new UDFArgumentTypeException(2,
            "Double or Float type is expected for the element type of list Vjfi: "
                    + typeInfo1.getTypeName());
    }
    if (!HiveUtils.isNumberTypeInfo(typeInfo[3])) {
        throw new UDFArgumentTypeException(3,
            "Number type is expected for the third argument Xi: " + typeInfo[3].getTypeName());
    }
    if (!HiveUtils.isNumberTypeInfo(typeInfo[4])) {
        throw new UDFArgumentTypeException(4,
            "Number type is expected for the third argument Xi: " + typeInfo[4].getTypeName());
    }
    return new Evaluator();
}
 
Example #15
Source Project: incubator-hivemall   Author: apache   File: FMeasureUDAF.java    License: 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 #16
Source Project: incubator-hivemall   Author: apache   File: ApproxCountDistinctUDAF.java    License: 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 #17
Source Project: incubator-hivemall   Author: apache   File: RandomForestEnsembleUDAF.java    License: 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 #18
Source Project: incubator-hivemall   Author: apache   File: CollectAllUDAF.java    License: 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 #19
Source Project: incubator-hivemall   Author: apache   File: ArrayAvgGenericUDAF.java    License: 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 #20
Source Project: incubator-hivemall   Author: apache   File: MinByUDAF.java    License: 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 #21
Source Project: incubator-hivemall   Author: apache   File: MajorityVoteUDAF.java    License: 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 #22
Source Project: incubator-hivemall   Author: apache   File: MergeMapsUDAF.java    License: 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();
}
 
Example #23
Source Project: incubator-datasketches-hive   Author: apache   File: UnionSketchUDAFTest.java    License: 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 #24
Source Project: incubator-datasketches-hive   Author: apache   File: UnionSketchUDAFTest.java    License: 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 #25
Source Project: incubator-hivemall   Author: apache   File: PLSAPredictUDAF.java    License: 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 #26
Source Project: incubator-hivemall   Author: apache   File: LDAPredictUDAF.java    License: 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 #27
Source Project: hive-funnel-udf   Author: yahoo   File: Merge.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public MergeEvaluator getEvaluator(GenericUDAFParameterInfo info) throws SemanticException {
    // Get the parameters
    TypeInfo [] parameters = info.getParameters();

    // Check number of arguments
    if (parameters.length != 1) {
        throw new UDFArgumentLengthException("Please specify the funnel column.");
    }

    // Check if the parameter is not a list
    if (parameters[0].getCategory() != ObjectInspector.Category.LIST) {
        throw new UDFArgumentTypeException(0, "Only list type arguments are accepted but " + parameters[0].getTypeName() + " was passed as the first parameter.");
    }

    // Check that the list is an array of primitives
    if (((ListTypeInfo) parameters[0]).getListElementTypeInfo().getCategory() != ObjectInspector.Category.PRIMITIVE) {
        throw new UDFArgumentTypeException(0, "A long array argument should be passed, but " + parameters[0].getTypeName() + " was passed instead.");
    }

    // Check that the list is of type long
    // May want to add support for int/double/float later
    switch (((PrimitiveTypeInfo) ((ListTypeInfo) parameters[0]).getListElementTypeInfo()).getPrimitiveCategory()) {
        case LONG:
            break;
        default:
            throw new UDFArgumentTypeException(0, "A long array argument should be passed, but " + parameters[0].getTypeName() + " was passed instead.");
    }

    return new MergeEvaluator();
}
 
Example #28
Source Project: incubator-datasketches-hive   Author: apache   File: UnionSketchUDAF.java    License: 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 #29
Source Project: incubator-datasketches-hive   Author: apache   File: UnionSketchUDAF.java    License: 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 seed 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.validateIntegralParameter(inspectors[2], 2);
    if (!ObjectInspectorUtils.isConstantObjectInspector(inspectors[2])) {
      throw new UDFArgumentTypeException(2, "The third argument must be a constant");
    }
  }

  return new UnionSketchUDAFEvaluator();
}
 
Example #30
Source Project: incubator-datasketches-hive   Author: apache   File: DataToItemsSketchUDAF.java    License: 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();
}