generate_error_codes.py 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. #!/usr/bin/env python
  2. # Copyright 2015 Cloudera Inc.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. # For readability purposes we define the error codes and messages at the top of the
  16. # file. New codes and messages must be added here. Old error messages MUST NEVER BE
  17. # DELETED, but can be renamed. The tuple layout for a new entry is: error code enum name,
  18. # numeric error code, format string of the message.
  19. #
  20. # TODO Add support for SQL Error Codes
  21. # https://msdn.microsoft.com/en-us/library/ms714687%28v=vs.85%29.aspx
  22. error_codes = (
  23. ("OK", 1, ""),
  24. ("GENERAL", 2, "$0"),
  25. ("CANCELLED", 3, "$0"),
  26. ("ANALYSIS_ERROR", 4, "$0"),
  27. ("NOT_IMPLEMENTED_ERROR", 5, "$0"),
  28. ("RUNTIME_ERROR", 6, "$0"),
  29. ("MEM_LIMIT_EXCEEDED", 7, "$0"),
  30. ("INTERNAL_ERROR", 8, "$0"),
  31. ("RECOVERABLE_ERROR", 9, "$0"),
  32. ("PARQUET_MULTIPLE_BLOCKS", 10,
  33. "Parquet files should not be split into multiple hdfs-blocks. file=$0"),
  34. ("PARQUET_COLUMN_METADATA_INVALID", 11,
  35. "Column metadata states there are $0 values, but read $1 values from column $2. "
  36. "file=$3"),
  37. ("PARQUET_HEADER_PAGE_SIZE_EXCEEDED", 12, "(unused)"),
  38. ("PARQUET_HEADER_EOF", 13,
  39. "ParquetScanner: reached EOF while deserializing data page header. file=$0"),
  40. ("PARQUET_GROUP_ROW_COUNT_ERROR", 14,
  41. "Metadata states that in group $0($1) there are $2 rows, but $3 rows were read."),
  42. ("PARQUET_GROUP_ROW_COUNT_OVERFLOW", 15, "(unused)"),
  43. ("PARQUET_MISSING_PRECISION", 16,
  44. "File '$0' column '$1' does not have the decimal precision set."),
  45. ("PARQUET_WRONG_PRECISION", 17,
  46. "File '$0' column '$1' has a precision that does not match the table metadata "
  47. " precision. File metadata precision: $2, table metadata precision: $3."),
  48. ("PARQUET_BAD_CONVERTED_TYPE", 18,
  49. "File '$0' column '$1' does not have converted type set to DECIMAL"),
  50. ("PARQUET_INCOMPATIBLE_DECIMAL", 19,
  51. "File '$0' column '$1' contains decimal data but the table metadata has type $2"),
  52. ("SEQUENCE_SCANNER_PARSE_ERROR", 20,
  53. "Problem parsing file $0 at $1$2"),
  54. ("SNAPPY_DECOMPRESS_INVALID_BLOCK_SIZE", 21,
  55. "Decompressor: block size is too big. Data is likely corrupt. Size: $0"),
  56. ("SNAPPY_DECOMPRESS_INVALID_COMPRESSED_LENGTH", 22,
  57. "Decompressor: invalid compressed length. Data is likely corrupt."),
  58. ("SNAPPY_DECOMPRESS_UNCOMPRESSED_LENGTH_FAILED", 23,
  59. "Snappy: GetUncompressedLength failed"),
  60. ("SNAPPY_DECOMPRESS_RAW_UNCOMPRESS_FAILED", 24,
  61. "SnappyBlock: RawUncompress failed"),
  62. ("SNAPPY_DECOMPRESS_DECOMPRESS_SIZE_INCORRECT", 25,
  63. "Snappy: Decompressed size is not correct."),
  64. ("HDFS_SCAN_NODE_UNKNOWN_DISK", 26, "Unknown disk id. "
  65. "This will negatively affect performance. "
  66. "Check your hdfs settings to enable block location metadata."),
  67. ("FRAGMENT_EXECUTOR", 27, "Reserved resource size ($0) is larger than "
  68. "query mem limit ($1), and will be restricted to $1. Configure the reservation "
  69. "size by setting RM_INITIAL_MEM."),
  70. ("PARTITIONED_HASH_JOIN_MAX_PARTITION_DEPTH", 28,
  71. "Cannot perform join at hash join node with id $0."
  72. " The input data was partitioned the maximum number of $1 times."
  73. " This could mean there is significant skew in the data or the memory limit is"
  74. " set too low."),
  75. ("PARTITIONED_AGG_MAX_PARTITION_DEPTH", 29,
  76. "Cannot perform aggregation at hash aggregation node with id $0."
  77. " The input data was partitioned the maximum number of $1 times."
  78. " This could mean there is significant skew in the data or the memory limit is"
  79. " set too low."),
  80. ("MISSING_BUILTIN", 30, "Builtin '$0' with symbol '$1' does not exist. "
  81. "Verify that all your impalads are the same version."),
  82. ("RPC_GENERAL_ERROR", 31, "RPC Error: $0"),
  83. ("RPC_TIMEOUT", 32, "RPC timed out"),
  84. ("UDF_VERIFY_FAILED", 33,
  85. "Failed to verify function $0 from LLVM module $1, see log for more details."),
  86. ("PARQUET_CORRUPT_VALUE", 34, "File $0 corrupt. RLE level data bytes = $1"),
  87. ("AVRO_DECIMAL_RESOLUTION_ERROR", 35, "Column '$0' has conflicting Avro decimal types. "
  88. "Table schema $1: $2, file schema $1: $3"),
  89. ("AVRO_DECIMAL_METADATA_MISMATCH", 36, "Column '$0' has conflicting Avro decimal types. "
  90. "Declared $1: $2, $1 in table's Avro schema: $3"),
  91. ("AVRO_SCHEMA_RESOLUTION_ERROR", 37, "Unresolvable types for column '$0': "
  92. "table type: $1, file type: $2"),
  93. ("AVRO_SCHEMA_METADATA_MISMATCH", 38, "Unresolvable types for column '$0': "
  94. "declared column type: $1, table's Avro schema type: $2"),
  95. ("AVRO_UNSUPPORTED_DEFAULT_VALUE", 39, "Field $0 is missing from file and default "
  96. "values of type $1 are not yet supported."),
  97. ("AVRO_MISSING_FIELD", 40, "Inconsistent table metadata. Mismatch between column "
  98. "definition and Avro schema: cannot read field $0 because there are only $1 fields."),
  99. ("AVRO_MISSING_DEFAULT", 41,
  100. "Field $0 is missing from file and does not have a default value."),
  101. ("AVRO_NULLABILITY_MISMATCH", 42,
  102. "Field $0 is nullable in the file schema but not the table schema."),
  103. ("AVRO_NOT_A_RECORD", 43,
  104. "Inconsistent table metadata. Field $0 is not a record in the Avro schema."),
  105. ("PARQUET_DEF_LEVEL_ERROR", 44, "Could not read definition level, even though metadata"
  106. " states there are $0 values remaining in data page. file=$1"),
  107. ("PARQUET_NUM_COL_VALS_ERROR", 45, "Mismatched number of values in column index $0 "
  108. "($1 vs. $2). file=$3"),
  109. ("PARQUET_DICT_DECODE_FAILURE", 46, "Failed to decode dictionary-encoded value. "
  110. "file=$0"),
  111. ("SSL_PASSWORD_CMD_FAILED", 47,
  112. "SSL private-key password command ('$0') failed with error: $1"),
  113. ("SSL_CERTIFICATE_PATH_BLANK", 48, "The SSL certificate path is blank"),
  114. ("SSL_PRIVATE_KEY_PATH_BLANK", 49, "The SSL private key path is blank"),
  115. ("SSL_CERTIFICATE_NOT_FOUND", 50, "The SSL certificate file does not exist at path $0"),
  116. ("SSL_PRIVATE_KEY_NOT_FOUND", 51, "The SSL private key file does not exist at path $0"),
  117. ("SSL_SOCKET_CREATION_FAILED", 52, "SSL socket creation failed: $0"),
  118. ("MEM_ALLOC_FAILED", 53, "Memory allocation of $0 bytes failed"),
  119. ("PARQUET_REP_LEVEL_ERROR", 54, "Could not read repetition level, even though metadata"
  120. " states there are $0 values remaining in data page. file=$1"),
  121. ("PARQUET_UNRECOGNIZED_SCHEMA", 55, "File '$0' has an incompatible Parquet schema for "
  122. "column '$1'. Column type: $2, Parquet schema:\\n$3"),
  123. ("COLLECTION_ALLOC_FAILED", 56, "Failed to allocate buffer for collection '$0'."),
  124. ("TMP_DEVICE_BLACKLISTED", 57,
  125. "Temporary device for directory $0 is blacklisted from a previous error and cannot "
  126. "be used."),
  127. ("TMP_FILE_BLACKLISTED", 58,
  128. "Temporary file $0 is blacklisted from a previous error and cannot be expanded."),
  129. ("RPC_CLIENT_CONNECT_FAILURE", 59,
  130. "RPC client failed to connect: $0"),
  131. ("STALE_METADATA_FILE_TOO_SHORT", 60, "Metadata for file '$0' appears stale. "
  132. "Try running \\\"refresh $1\\\" to reload the file metadata."),
  133. ("PARQUET_BAD_VERSION_NUMBER", 61, "File '$0' has an invalid version number: $1\\n"
  134. "This could be due to stale metadata. Try running \\\"refresh $2\\\"."),
  135. ("SCANNER_INCOMPLETE_READ", 62, "Tried to read $0 bytes but could only read $1 bytes. "
  136. "This may indicate data file corruption. (file $2, byte offset: $3)"),
  137. ("SCANNER_INVALID_READ", 63, "Invalid read of $0 bytes. This may indicate data file "
  138. "corruption. (file $1, byte offset: $2)"),
  139. ("AVRO_BAD_VERSION_HEADER", 64, "File '$0' has an invalid version header: $1\\n"
  140. "Make sure the file is an Avro data file."),
  141. ("IMPALA_2598_KERBEROS_SSL_DISALLOWED", 65, "Enabling server-to-server SSL connections "
  142. "in conjunction with Kerberos authentication is not supported at the same time. "
  143. "Disable server-to-server SSL by unsetting --ssl_client_ca_certificate."),
  144. )
  145. import sys
  146. import os
  147. # Verifies the uniqueness of the error constants and numeric error codes.
  148. def check_duplicates(codes):
  149. constants = {}
  150. num_codes = {}
  151. for row in codes:
  152. if row[0] in constants:
  153. print("Constant %s already used, please check definition of '%s'!" % \
  154. (row[0], constants[row[0]]))
  155. exit(1)
  156. if row[1] in num_codes:
  157. print("Numeric error code %d already used, please check definition of '%s'!" % \
  158. (row[1], num_codes[row[1]]))
  159. exit(1)
  160. constants[row[0]] = row[2]
  161. num_codes[row[1]] = row[2]
  162. preamble = """
  163. // Copyright 2015 Cloudera Inc.
  164. //
  165. // Licensed under the Apache License, Version 2.0 (the "License");
  166. // you may not use this file except in compliance with the License.
  167. // You may obtain a copy of the License at
  168. //
  169. // http://www.apache.org/licenses/LICENSE-2.0
  170. //
  171. // Unless required by applicable law or agreed to in writing, software
  172. // distributed under the License is distributed on an "AS IS" BASIS,
  173. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  174. // See the License for the specific language governing permissions and
  175. // limitations under the License.
  176. //
  177. //
  178. // THIS FILE IS AUTO GENERATED BY generated_error_codes.py DO NOT MODIFY
  179. // IT BY HAND.
  180. //
  181. namespace cpp impala
  182. namespace java com.cloudera.impala.thrift
  183. """
  184. # The script will always generate the file, CMake will take care of running it only if
  185. # necessary.
  186. target_file = "ErrorCodes.thrift"
  187. # Check uniqueness of error constants and numeric codes
  188. check_duplicates(error_codes)
  189. fid = open(target_file, "w+")
  190. try:
  191. fid.write(preamble)
  192. fid.write("""\nenum TErrorCode {\n""")
  193. fid.write(",\n".join(map(lambda x: " %s" % x[0], error_codes)))
  194. fid.write("\n}")
  195. fid.write("\n")
  196. fid.write("const list<string> TErrorMessage = [\n")
  197. fid.write(",\n".join(map(lambda x: " // %s\n \"%s\"" %(x[0], x[2]), error_codes)))
  198. fid.write("\n]")
  199. finally:
  200. fid.close()
  201. print("%s created." % target_file)