PageRenderTime 23ms CodeModel.GetById 15ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 0ms

/tags/release-0.0.0-rc0/hive/external/ql/src/java/org/apache/hadoop/hive/ql/exec/errors/ScriptErrorHeuristic.java

#
Java | 76 lines | 35 code | 12 blank | 29 comment | 4 complexity | ad74dea5ed3f06bb7276563f8f8abed2 MD5 | raw file
 1/**
 2 * Licensed to the Apache Software Foundation (ASF) under one
 3 * or more contributor license agreements.  See the NOTICE file
 4 * distributed with this work for additional information
 5 * regarding copyright ownership.  The ASF licenses this file
 6 * to you under the Apache License, Version 2.0 (the
 7 * "License"); you may not use this file except in compliance
 8 * with the License.  You may obtain a copy of the License at
 9 *
10 *     http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18
19package org.apache.hadoop.hive.ql.exec.errors;
20
21import java.util.List;
22import java.util.regex.Matcher;
23import java.util.regex.Pattern;
24
25/**
26 * Detects when a query has failed because a user's script that was specified in
27 * transform returns a non-zero error code.
28 *
29 * Conditions to check:
30 *
31 * 1. "Script failed with code <some number>" is in the log
32 *
33 */
34
35public class ScriptErrorHeuristic extends RegexErrorHeuristic {
36
37  private static final String FAILED_REGEX = "Script failed with code [0-9]+";
38
39  public ScriptErrorHeuristic() {
40    setQueryRegex(".*");
41    getLogRegexes().add(FAILED_REGEX);
42  }
43
44  @Override
45  public ErrorAndSolution getErrorAndSolution() {
46    ErrorAndSolution es = null;
47
48    if(getQueryMatches()) {
49      for(List<String> matchingLines : getRegexToLogLines().values()) {
50        // There should really only be one line with "Script failed..."
51        if (matchingLines.size() > 0) {
52          assert(matchingLines.size() == 1);
53
54          // Get "Script failed with code <some number>"
55          Matcher m1 = Pattern.compile(FAILED_REGEX).matcher(matchingLines.get(0));
56          m1.find();
57          String failedStr = m1.group();
58
59          // Get "<some number>"
60          Matcher m2 = Pattern.compile("[0-9]+").matcher(failedStr);
61          m2.find();
62          String errorCode = m2.group();
63
64          es = new ErrorAndSolution(
65            "A user-supplied transfrom script has exited with error code " +
66            errorCode + " instead of 0.",
67            "Verify that the script can properly handle all the input rows " +
68            "without throwing exceptions and exits properly.");
69        }
70      }
71    }
72
73    reset();
74    return es;
75  }
76}