Copilot commented on code in PR #16519: URL: https://github.com/apache/pinot/pull/16519#discussion_r2255502681
########## pinot-segment-local/src/main/java/org/apache/pinot/segment/local/aggregator/ValueAggregatorUtils.java: ########## @@ -0,0 +1,36 @@ +/** + * 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.segment.local.aggregator; + +public class ValueAggregatorUtils { + private ValueAggregatorUtils() { + } + + /// Tries to convert the given value to a double. + /// We need this for [ValueAggregator] because the raw value might not be converted to the desired data type yet if it + /// is not specified in the schema. + /// TODO: Provide a way to specify the desired data type for the raw value. Review Comment: Use proper Javadoc @param and @return tags, and replace [ValueAggregator] with {@link ValueAggregator} for proper cross-references in Javadoc. ```suggestion /** * Tries to convert the given value to a double. * <p> * We need this for {@link ValueAggregator} because the raw value might not be converted to the desired data type yet if it * is not specified in the schema. * TODO: Provide a way to specify the desired data type for the raw value. * * @param value The value to convert to double. * @return The double representation of the value. */ ``` ########## pinot-segment-local/src/main/java/org/apache/pinot/segment/local/aggregator/ValueAggregatorUtils.java: ########## @@ -0,0 +1,36 @@ +/** + * 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.segment.local.aggregator; + +public class ValueAggregatorUtils { + private ValueAggregatorUtils() { + } + + /// Tries to convert the given value to a double. + /// We need this for [ValueAggregator] because the raw value might not be converted to the desired data type yet if it + /// is not specified in the schema. + /// TODO: Provide a way to specify the desired data type for the raw value. Review Comment: Use Javadoc format (/** */) instead of triple slash comments for method documentation. The current comment style is inconsistent with Java conventions. ```suggestion /** * Tries to convert the given value to a double. * <p> * This is needed for {@code ValueAggregator} because the raw value might not be converted to the desired data type yet * if it is not specified in the schema. * <p> * TODO: Provide a way to specify the desired data type for the raw value. */ ``` ########## pinot-segment-local/src/main/java/org/apache/pinot/segment/local/aggregator/ValueAggregatorUtils.java: ########## @@ -0,0 +1,36 @@ +/** + * 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.segment.local.aggregator; + +public class ValueAggregatorUtils { + private ValueAggregatorUtils() { + } + + /// Tries to convert the given value to a double. + /// We need this for [ValueAggregator] because the raw value might not be converted to the desired data type yet if it + /// is not specified in the schema. + /// TODO: Provide a way to specify the desired data type for the raw value. + public static double toDouble(Object value) { + if (value instanceof Number) { + return ((Number) value).doubleValue(); + } else { + return Double.parseDouble(value.toString()); Review Comment: The method should handle NumberFormatException and provide a more descriptive error message that indicates the original value that failed to parse, similar to the pattern used in PercentileEstValueAggregator.toLong(). ########## pinot-segment-local/src/main/java/org/apache/pinot/segment/local/aggregator/PercentileEstValueAggregator.java: ########## @@ -62,12 +62,24 @@ public QuantileDigest applyRawValue(QuantileDigest value, Object rawValue) { if (rawValue instanceof byte[]) { value.merge(deserializeAggregatedValue((byte[]) rawValue)); } else { - value.add(((Number) rawValue).longValue()); + value.add(toLong(rawValue)); } _maxByteSize = Math.max(_maxByteSize, value.getByteSize()); return value; } + private static long toLong(Object rawValue) { + if (rawValue instanceof Number) { + return ((Number) rawValue).longValue(); + } + String stringValue = rawValue.toString(); + try { + return Long.parseLong(stringValue); + } catch (NumberFormatException e) { + return (long) Double.parseDouble(stringValue); + } + } + Review Comment: The toLong() method duplicates logic from ValueAggregatorUtils.toDouble(). Consider creating a ValueAggregatorUtils.toLong() method to avoid code duplication and maintain consistency across aggregators. ```suggestion value.add(ValueAggregatorUtils.toLong(rawValue)); } _maxByteSize = Math.max(_maxByteSize, value.getByteSize()); return value; } ``` -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
