gortiz commented on code in PR #15037:
URL: https://github.com/apache/pinot/pull/15037#discussion_r1975576427


##########
pinot-spi/src/main/java/org/apache/pinot/spi/exception/QueryErrorCode.java:
##########
@@ -0,0 +1,141 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.pinot.spi.exception;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+public enum QueryErrorCode {
+  JSON_PARSING(100, "JsonParsingError"),
+  SQL_PARSING(150, "SQLParsingError"),
+  SQL_RUNTIME(160, "SQLRuntimeError"),
+  ACCESS_DENIED(180, "AccessDenied"),
+  TABLE_DOES_NOT_EXIST(190, "TableDoesNotExistError"),
+  TABLE_IS_DISABLED(191, "TableIsDisabledError"),
+  QUERY_EXECUTION(200, "QueryExecutionError"),
+  SERVER_SHUTTING_DOWN(210, "ServerShuttingDown"),
+  SERVER_OUT_OF_CAPACITY(211, "ServerOutOfCapacity"),
+  SERVER_TABLE_MISSING(230, "ServerTableMissing"),
+  SERVER_SEGMENT_MISSING(235, "ServerSegmentMissing"),
+  QUERY_SCHEDULING_TIMEOUT(240, "QuerySchedulingTimeoutError"),
+  SERVER_RESOURCE_LIMIT_EXCEEDED(245, "ServerResourceLimitExceededError"),
+  EXECUTION_TIMEOUT(250, "ExecutionTimeoutError"),
+  BROKER_SEGMENT_UNAVAILABLE(305, ""),
+  BROKER_TIMEOUT(400, "BrokerTimeoutError"),
+  BROKER_RESOURCE_MISSING(410, "BrokerResourceMissingError"),
+  BROKER_INSTANCE_MISSING(420, "BrokerInstanceMissingError"),
+  BROKER_REQUEST_SEND(425, "BrokerRequestSend"),
+  SERVER_NOT_RESPONDING(427, "ServerNotResponding"),
+  TOO_MANY_REQUESTS(429, "TooManyRequests"),
+  INTERNAL(450, "InternalError"),
+  MERGE_RESPONSE(500, "MergeResponseError"),
+  QUERY_CANCELLATION(503, "QueryCancellationError"),
+  QUERY_VALIDATION(700, "QueryValidationError"),
+  UNKNOWN_COLUMN(710, "UnknownColumnError"),
+  QUERY_PLANNING(720, "QueryPlanningError"),
+  UNKNOWN(1000, "UnknownError");
+  private static final Logger LOGGER = 
LoggerFactory.getLogger(QueryErrorCode.class);
+
+  private static final QueryErrorCode[] BY_ID;
+
+  static {
+    int maxId = -1;
+    for (QueryErrorCode queryErrorCode : QueryErrorCode.values()) {
+      maxId = Math.max(maxId, queryErrorCode.getId());
+    }
+    BY_ID = new QueryErrorCode[maxId + 1];

Review Comment:
   It wastes a fixed amount of memory (close to 32KB if we use compressed 
pointers). In exchange, we have a super-fast way to look for elements. 
Alternatives are:
   1. To use a linear probe, which is unnecessarily expensive
   2. To use a switch, which is unnecessarily hard to maintain
   3. To use a HashMap, which is also pretty expensive in terms of memory and 
less efficient in terms of CPU.
   4. To use a map optimized for int keys, which could be more efficient in 
terms of memory, but again, it's an issue in the CPU.
   
   I think the array cost is acceptable, but we can change it to use a map if 
you think it is not.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@pinot.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@pinot.apache.org
For additional commands, e-mail: commits-h...@pinot.apache.org

Reply via email to