org.apache.hadoop.hive.ql.parse.ParseException Java Examples
The following examples show how to use
org.apache.hadoop.hive.ql.parse.ParseException.
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: HiveASTRewriter.java From incubator-atlas with Apache License 2.0 | 6 votes |
public String rewrite(String sourceQry) throws RewriteException { String result = sourceQry; ASTNode tree = null; try { ParseDriver pd = new ParseDriver(); tree = pd.parse(sourceQry, queryContext, true); tree = ParseUtils.findRootNonNullToken(tree); this.rwCtx = new RewriteContext(sourceQry, tree, queryContext.getTokenRewriteStream()); rewrite(tree); result = toSQL(); } catch (ParseException e) { LOG.error("Could not parse the query {} ", sourceQry, e); throw new RewriteException("Could not parse query : " , e); } return result; }
Example #2
Source File: RuleBatchServiceImpl.java From Qualitis with Apache License 2.0 | 6 votes |
@Override public void getAndSaveRule(Map<String, List<ExcelTemplateRule>> rulePartitionedByRuleName, Map<String, List<ExcelCustomRule>> customRulePartitionedByRuleName, Map<String, List<ExcelMultiTemplateRule>> multiRulePartitionedByRuleName, Project project, String username) throws UnExpectedRequestException, MetaDataAcquireFailedException, SemanticException, ParseException { // Check if user has permission importing rule if (!project.getCreateUser().equals(username)) { throw new UnExpectedRequestException("User :[" + username + "] {&HAS_NO_PERMISSION_TO_IMPORT_RULES}"); } // Add template rule if (rulePartitionedByRuleName != null) { addTemplateRule(rulePartitionedByRuleName, project); } // Add custom rule if (customRulePartitionedByRuleName != null) { addCustomRule(customRulePartitionedByRuleName, project); } // Add multi-table rule if (multiRulePartitionedByRuleName != null) { addMultiTemplateRule(multiRulePartitionedByRuleName, project); } }
Example #3
Source File: RuleDataSourceServiceImpl.java From Qualitis with Apache License 2.0 | 6 votes |
@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 #4
Source File: AbstractHive_1_1QLProcessor.java From nifi with Apache License 2.0 | 5 votes |
protected Set<TableName> findTableNames(final String query) { final ASTNode node; try { node = new ParseDriver().parse(normalize(query)); } catch (ParseException e) { // If failed to parse the query, just log a message, but continue. getLogger().debug("Failed to parse query: {} due to {}", new Object[]{query, e}, e); return Collections.emptySet(); } final HashSet<TableName> tableNames = new HashSet<>(); findTableNames(node, tableNames); return tableNames; }
Example #5
Source File: AbstractHiveQLProcessor.java From nifi with Apache License 2.0 | 5 votes |
protected Set<TableName> findTableNames(final String query) { final ASTNode node; try { node = new ParseDriver().parse(normalize(query)); } catch (ParseException e) { // If failed to parse the query, just log a message, but continue. getLogger().debug("Failed to parse query: {} due to {}", new Object[]{query, e}, e); return Collections.emptySet(); } final HashSet<TableName> tableNames = new HashSet<>(); findTableNames(node, tableNames); return tableNames; }
Example #6
Source File: AbstractHive3QLProcessor.java From nifi with Apache License 2.0 | 5 votes |
protected Set<TableName> findTableNames(final String query) { final ASTNode node; try { node = new ParseDriver().parse(normalize(query)); } catch (ParseException e) { // If failed to parse the query, just log a message, but continue. getLogger().debug("Failed to parse query: {} due to {}", new Object[]{query, e}, e); return Collections.emptySet(); } final HashSet<TableName> tableNames = new HashSet<>(); findTableNames(node, tableNames); return tableNames; }
Example #7
Source File: RuleBatchServiceImpl.java From Qualitis with Apache License 2.0 | 5 votes |
@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 #8
Source File: RuleBatchServiceImpl.java From Qualitis with Apache License 2.0 | 5 votes |
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 #9
Source File: CustomRuleServiceImpl.java From Qualitis with Apache License 2.0 | 4 votes |
/** * Modify custom rule * 1.Find custom rule * 2.Delete template of custom rule * 3.Delete alarm_config of custom rule * 4.Delete ruleDataSources of custom rule * 5.Save custom rule template * 6.Modify custom rule and save * 7.Save rule alarm config and rule datasources * 8.Return result * @param request * @return * @throws UnExpectedRequestException */ @Override @Transactional(rollbackFor = {RuntimeException.class, UnExpectedRequestException.class, SemanticException.class, ParseException.class}) public GeneralResponse<RuleResponse> modifyCustomRule(ModifyCustomRuleRequest request) throws UnExpectedRequestException, SemanticException, ParseException { ModifyCustomRuleRequest.checkRequest(request); Rule ruleInDb = ruleDao.findById(request.getRuleId()); if (ruleInDb == null) { throw new UnExpectedRequestException("rule_id [" + request.getRuleId() + "] {&DOES_NOT_EXIST}"); } projectService.checkProjectExistence(ruleInDb.getProject().getId()); if (!ruleInDb.getRuleType().equals(RuleTypeEnum.CUSTOM_RULE.getCode())) { throw new UnExpectedRequestException("rule_id: [" + request.getRuleId() + "]) {&IS_NOT_A_CUSTOM_RULE}"); } LOGGER.info("Succeed to find custom rule. rule_id: {}", ruleInDb.getId()); // Check existence of project name ruleService.checkRuleName(request.getRuleName(), ruleInDb.getProject(), ruleInDb.getId()); // Check if cluster name supported ruleDataSourceService.checkDataSourceClusterSupport(request.getClusterName()); // Delete alarm config by custom rule alarmConfigService.deleteByRule(ruleInDb); LOGGER.info("Succeed to delete all alarm_config. rule_id: {}", ruleInDb.getId()); // Delete template of custom rule ruleTemplateService.deleteCustomTemplate(ruleInDb.getTemplate()); LOGGER.info("Succeed to delete custom rule template. rule_id: {}", request.getRuleId()); // Delete rule datasource of custom rule ruleDataSourceService.deleteByRule(ruleInDb); LOGGER.info("Succeed to delete all rule_dataSources. rule_id: {}", ruleInDb.getId()); // Save template, alarm config, rule datasource of custom rule AddCustomRuleRequest addCustomRuleRequest = new AddCustomRuleRequest(); BeanUtils.copyProperties(request, addCustomRuleRequest); Template template = ruleTemplateService.addCustomTemplate(addCustomRuleRequest); // Modify custom rule and save ruleInDb.setName(request.getRuleName()); ruleInDb.setOutputName(request.getOutputName()); ruleInDb.setTemplate(template); ruleInDb.setFunctionType(request.getFunctionType()); ruleInDb.setFunctionContent(request.getFunctionContent()); ruleInDb.setFromContent(request.getFromContent()); ruleInDb.setWhereContent(request.getWhereContent()); ruleInDb.setAlarm(request.getAlarm()); ruleInDb.setRuleTemplateName(template.getName()); Rule savedRule = ruleDao.saveRule(ruleInDb); // Save alarm config and rule datasource List<AlarmConfig> savedAlarmConfigs = new ArrayList<>(); if (request.getAlarm()) { savedAlarmConfigs = alarmConfigService.checkAndSaveCustomAlarmVariable(request.getAlarmVariable(), savedRule); LOGGER.info("Succeed to save alarm_configs, alarm_configs: {}", savedAlarmConfigs); } List<RuleDataSource> ruleDataSources = ruleDataSourceService.checkAndSaveCustomRuleDataSource(request.getClusterName(), savedRule); savedRule.setAlarmConfigs(new HashSet<>(savedAlarmConfigs)); savedRule.setRuleDataSources(new HashSet<>(ruleDataSources)); RuleResponse response = new RuleResponse(savedRule); LOGGER.info("Succeed to modify custom rule, rule_id: {}", savedRule.getId()); return new GeneralResponse<>("200", "{&SUCCEED_TO_MODIFY_CUSTOM_RULE}", response); }
Example #10
Source File: TestParser.java From eagle with Apache License 2.0 | 4 votes |
public void printQueryAST(String query) throws ParseException { ASTNode root = parser.generateAST(query); printTree(root, 0); }
Example #11
Source File: TestParser.java From Eagle with Apache License 2.0 | 4 votes |
public void printQueryAST(String query) throws ParseException { ASTNode root = parser.generateAST(query); printTree(root, 0); }
Example #12
Source File: HiveParseException.java From circus-train with Apache License 2.0 | 4 votes |
public HiveParseException(ParseException cause) { super(cause); }
Example #13
Source File: CustomRuleServiceImpl.java From Qualitis with Apache License 2.0 | 4 votes |
@Override @Transactional(rollbackFor = {RuntimeException.class, UnExpectedRequestException.class, SemanticException.class, ParseException.class}) public GeneralResponse<RuleResponse> addCustomRule(AddCustomRuleRequest request) throws UnExpectedRequestException, SemanticException, ParseException { // Check Arguments AddCustomRuleRequest.checkRequest(request); // Generate Template, TemplateStatisticsInputMeta and save Template template = ruleTemplateService.addCustomTemplate(request); // Save rule, rule_alarm_config and ruleDataSource // Check existence of project Project projectInDb = projectService.checkProjectExistence(request.getProjectId()); // Check unique of rule name ruleService.checkRuleName(request.getRuleName(), projectInDb, null); // Check if cluster name is supported ruleDataSourceService.checkDataSourceClusterSupport(request.getClusterName()); RuleGroup ruleGroup; if (request.getRuleGroupId() != null) { ruleGroup = ruleGroupDao.findById(request.getRuleGroupId()); if (ruleGroup == null) { throw new UnExpectedRequestException(String.format("Rule Group: %s {&CAN_NOT_BE_NULL_OR_EMPTY}", request.getRuleGroupId())); } } else { ruleGroup = ruleGroupDao.saveRuleGroup( new RuleGroup("Group_" + UUID.randomUUID().toString().replace("-", ""), projectInDb.getId())); } Rule newRule = new Rule(); newRule.setRuleType(RuleTypeEnum.CUSTOM_RULE.getCode()); newRule.setTemplate(template); newRule.setName(request.getRuleName()); newRule.setAlarm(request.getAlarm()); newRule.setProject(projectInDb); newRule.setRuleTemplateName(template.getName()); newRule.setFunctionType(request.getFunctionType()); newRule.setFunctionContent(request.getFunctionContent()); newRule.setFromContent(request.getFromContent()); newRule.setWhereContent(request.getWhereContent()); newRule.setOutputName(request.getOutputName()); newRule.setRuleTemplateName(template.getName()); newRule.setRuleGroup(ruleGroup); Rule savedRule = ruleDao.saveRule(newRule); LOGGER.info("Succeed to save custom rule, rule_id: {}", savedRule.getId()); List<AlarmConfig> savedAlarmConfigs = new ArrayList<>(); if (request.getAlarm()) { savedAlarmConfigs = alarmConfigService.checkAndSaveCustomAlarmVariable(request.getAlarmVariable(), savedRule); LOGGER.info("Succeed to save alarm_configs, alarm_configs: {}", savedAlarmConfigs); } List<RuleDataSource> ruleDataSources = ruleDataSourceService.checkAndSaveCustomRuleDataSource(request.getClusterName(), savedRule); savedRule.setAlarmConfigs(new HashSet<>(savedAlarmConfigs)); savedRule.setRuleDataSources(new HashSet<>(ruleDataSources)); RuleResponse response = new RuleResponse(savedRule); LOGGER.info("Succeed to add custom rule, rule_id: {}", savedRule.getId()); return new GeneralResponse<>("200", "{&SUCCEED_TO_ADD_CUSTOM_RULE}", response); }
Example #14
Source File: ProjectBatchServiceImpl.java From Qualitis with Apache License 2.0 | 4 votes |
@Override @Transactional(rollbackFor = {Exception.class}) public GeneralResponse<?> uploadProjects(InputStream fileInputStream, FormDataContentDisposition fileDisposition) throws UnExpectedRequestException, MetaDataAcquireFailedException, IOException, SemanticException, ParseException { 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 + "]"); } String username = HttpUtils.getUserName(httpServletRequest); if (username == null) { return new GeneralResponse<>("401", "{&PLEASE_LOGIN}", null); } Long userId = HttpUtils.getUserId(httpServletRequest); // Read file and create project ExcelProjectListener listener = readExcel(fileInputStream); // Check if excel file is empty if (listener.getExcelProjectContent().isEmpty() && listener.getExcelRuleContent().isEmpty() && listener.getExcelCustomRuleContent().isEmpty() && listener.getExcelMultiRuleContent().isEmpty()) { throw new UnExpectedRequestException("{&FILE_CAN_NOT_BE_EMPTY_OR_FILE_CAN_NOT_BE_RECOGNIZED}"); } for (ExcelProject excelProject : listener.getExcelProjectContent()) { // Check excel project arguments is valid or not AddProjectRequest request = convertExcelProjectToAddProjectRequest(excelProject); projectService.addProject(request, userId); } // Create rules according to excel sheet Map<String, Map<String, List<ExcelTemplateRule>>> excelTemplateRulePartitionedByProject = listener.getExcelRuleContent(); Map<String, Map<String, List<ExcelCustomRule>>> excelCustomRulePartitionedByProject = listener.getExcelCustomRuleContent(); Map<String, Map<String, List<ExcelMultiTemplateRule>>> excelMultiTemplateRulePartitionedByProject = listener.getExcelMultiRuleContent(); Set<String> allProjects = new HashSet<>(); allProjects.addAll(excelTemplateRulePartitionedByProject.keySet()); allProjects.addAll(excelCustomRulePartitionedByProject.keySet()); allProjects.addAll(excelMultiTemplateRulePartitionedByProject.keySet()); for (String projectName : allProjects) { Project projectInDb = projectDao.findByName(projectName); if (projectInDb == null) { throw new UnExpectedRequestException("{&PROJECT}: [" + projectName + "] {&DOES_NOT_EXIST}"); } ruleBatchService.getAndSaveRule(excelTemplateRulePartitionedByProject.get(projectName), excelCustomRulePartitionedByProject.get(projectName), excelMultiTemplateRulePartitionedByProject.get(projectName), projectInDb, username); } fileInputStream.close(); return new GeneralResponse<>("200", "{&SUCCEED_TO_UPLOAD_FILE}", null); }
Example #15
Source File: ProjectBatchService.java From Qualitis with Apache License 2.0 | 2 votes |
/** * Add project by project excel * @param fileInputStream * @param fileDisposition * @return * @throws UnExpectedRequestException * @throws MetaDataAcquireFailedException * @throws IOException * @throws ParseException * @throws SemanticException */ GeneralResponse<?> uploadProjects(InputStream fileInputStream, FormDataContentDisposition fileDisposition) throws UnExpectedRequestException, MetaDataAcquireFailedException, IOException, SemanticException, ParseException;
Example #16
Source File: RuleBatchService.java From Qualitis with Apache License 2.0 | 2 votes |
/** * Get and save rules * @param rulePartitionedByRuleName * @param customRulePartitionedByRuleName * @param multiRulePartitionedByRuleName * @param project * @param username * @throws UnExpectedRequestException * @throws MetaDataAcquireFailedException * @throws ParseException * @throws SemanticException */ void getAndSaveRule(Map<String, List<ExcelTemplateRule>> rulePartitionedByRuleName, Map<String, List<ExcelCustomRule>> customRulePartitionedByRuleName, Map<String, List<ExcelMultiTemplateRule>> multiRulePartitionedByRuleName, Project project, String username) throws UnExpectedRequestException, MetaDataAcquireFailedException, SemanticException, ParseException;
Example #17
Source File: Parser.java From Eagle with Apache License 2.0 | 2 votes |
/** * Parse an Hive QL into an Abstract Syntax Tree(AST). * @param query * @return * @throws ParseException */ public ASTNode generateAST(String query) throws ParseException { ParseDriver pd = new ParseDriver(); return pd.parse(query); }
Example #18
Source File: RuleBatchService.java From Qualitis with Apache License 2.0 | 2 votes |
/** * Upload rule from excel file * @param fileInputStream * @param formDataContentDisposition * @param projectId * @return * @throws UnExpectedRequestException * @throws IOException * @throws MetaDataAcquireFailedException * @throws ParseException * @throws SemanticException */ GeneralResponse<?> uploadRules(InputStream fileInputStream, FormDataContentDisposition formDataContentDisposition, Long projectId) throws UnExpectedRequestException, IOException, MetaDataAcquireFailedException, SemanticException, ParseException;
Example #19
Source File: Parser.java From eagle with Apache License 2.0 | 2 votes |
/** * Parse an Hive QL into an Abstract Syntax Tree(AST). * @param query * @return * @throws ParseException */ public ASTNode generateAST(String query) throws ParseException { ParseDriver pd = new ParseDriver(); return pd.parse(query); }
Example #20
Source File: CustomRuleService.java From Qualitis with Apache License 2.0 | 2 votes |
/** * Modifty custom rule * @param request * @return * @throws UnExpectedRequestException * @throws SemanticException * @throws ParseException */ GeneralResponse<RuleResponse> modifyCustomRule(ModifyCustomRuleRequest request) throws UnExpectedRequestException, SemanticException, ParseException;
Example #21
Source File: CustomRuleService.java From Qualitis with Apache License 2.0 | 2 votes |
/** * Add custom rule * @param request * @return * @throws UnExpectedRequestException * @throws SemanticException * @throws ParseException */ GeneralResponse<RuleResponse> addCustomRule(AddCustomRuleRequest request) throws UnExpectedRequestException, SemanticException, ParseException;
Example #22
Source File: RuleDataSourceService.java From Qualitis with Apache License 2.0 | 2 votes |
/** * Check and save custom ruleDatasource * @param clusterName * @param savedRule * @throws SemanticException * @throws ParseException * @return */ List<RuleDataSource> checkAndSaveCustomRuleDataSource(String clusterName, Rule savedRule) throws SemanticException, ParseException;