PageRenderTime 44ms CodeModel.GetById 19ms RepoModel.GetById 0ms 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
Possible License(s): Apache-2.0, BSD-3-Clause, JSON, CPL-1.0
  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. package org.apache.hadoop.hive.ql.exec.errors;
  19. import java.util.List;
  20. import java.util.regex.Matcher;
  21. import java.util.regex.Pattern;
  22. /**
  23. * Detects when a query has failed because a user's script that was specified in
  24. * transform returns a non-zero error code.
  25. *
  26. * Conditions to check:
  27. *
  28. * 1. "Script failed with code <some number>" is in the log
  29. *
  30. */
  31. public class ScriptErrorHeuristic extends RegexErrorHeuristic {
  32. private static final String FAILED_REGEX = "Script failed with code [0-9]+";
  33. public ScriptErrorHeuristic() {
  34. setQueryRegex(".*");
  35. getLogRegexes().add(FAILED_REGEX);
  36. }
  37. @Override
  38. public ErrorAndSolution getErrorAndSolution() {
  39. ErrorAndSolution es = null;
  40. if(getQueryMatches()) {
  41. for(List<String> matchingLines : getRegexToLogLines().values()) {
  42. // There should really only be one line with "Script failed..."
  43. if (matchingLines.size() > 0) {
  44. assert(matchingLines.size() == 1);
  45. // Get "Script failed with code <some number>"
  46. Matcher m1 = Pattern.compile(FAILED_REGEX).matcher(matchingLines.get(0));
  47. m1.find();
  48. String failedStr = m1.group();
  49. // Get "<some number>"
  50. Matcher m2 = Pattern.compile("[0-9]+").matcher(failedStr);
  51. m2.find();
  52. String errorCode = m2.group();
  53. es = new ErrorAndSolution(
  54. "A user-supplied transfrom script has exited with error code " +
  55. errorCode + " instead of 0.",
  56. "Verify that the script can properly handle all the input rows " +
  57. "without throwing exceptions and exits properly.");
  58. }
  59. }
  60. }
  61. reset();
  62. return es;
  63. }
  64. }