bziobrowski commented on code in PR #14337: URL: https://github.com/apache/pinot/pull/14337#discussion_r1837772550
########## pinot-core/src/main/java/org/apache/pinot/core/util/NumberUtils.java: ########## @@ -0,0 +1,224 @@ +/** + * 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.core.util; + +/** + * Utility class with various number related methods. + */ +public class NumberUtils { + + public static final NumberFormatException NULL_EXCEPTION = new NumberFormatException("Can't parse null string"); + public static final NumberFormatException EXP_EXCEPTION = new NumberFormatException("Wrong exponent"); + public static final NumberFormatException EXCEPTION = new NumberFormatException("Can't parse value"); + + private static final long[] POWERS_OF_10 = new long[]{ + 1L, + 10L, + 100L, + 1000L, + 10000L, + 100000L, + 1000000L, + 10000000L, + 100000000L, + 1000000000L, + 10000000000L, + 100000000000L, + 1000000000000L, + 10000000000000L, + 100000000000000L, + 1000000000000000L, + 10000000000000000L, + 100000000000000000L, + 1000000000000000000L, + }; + + private NumberUtils() { + } + + /** + * Parses whole input char sequence. + * Throws static, pre-allocated NumberFormatException. + * If proper stack trace is required, caller has to catch it and throw another exception. + * @param cs char sequence to parse + * @return parsed long value + */ + public static long parseLong(CharSequence cs) { + if (cs == null) { + throw NULL_EXCEPTION; + } + return parseLong(cs, 0, cs.length()); + } + + /** + * Parses input char sequence between given indices. + * Throws static, pre-allocated NumberFormatException. + * If proper stack trace is required, caller has to catch it and throw another exception. + * @param cs char sequence to parse + * @param start start index (inclusive) + * @param end end index (exclusive) + * @return parsed long value + */ + public static long parseLong(CharSequence cs, int start, int end) { + if (cs == null) { + throw NULL_EXCEPTION; + } Review Comment: I agree about the checked exception but don't feel that multiplying methods is necessary. Throwing `stackless` exception is not a generic solution, it's meant to help in specific cases. I've seen plenty of places in the codebase that ignore caught exceptions (either completely or set some flag), suggesting that an error code (which this stackless exception is) is enough. As for the hotpath, I think we can safely assume anything appearing in e.g. an sql function method is going to be executed often and thus - is going to be hot. -- 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