Copilot commented on code in PR #1955: URL: https://github.com/apache/auron/pull/1955#discussion_r2726241476
########## native-engine/datafusion-ext-exprs/src/spark_monotonically_increasing_id.rs: ########## @@ -0,0 +1,245 @@ +// 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. + +use std::{ + any::Any, + fmt::{Debug, Display, Formatter}, + hash::{Hash, Hasher}, + sync::{ + Arc, + atomic::{AtomicI64, Ordering::SeqCst}, + }, +}; + +use arrow::{ + array::{Int64Array, RecordBatch}, + datatypes::{DataType, Schema}, +}; +use datafusion::{ + common::Result, + logical_expr::ColumnarValue, + physical_expr::{PhysicalExpr, PhysicalExprRef}, +}; + +pub struct SparkMonotonicallyIncreasingIdExpr { + partition_id: i64, + row_counter: AtomicI64, +} + +impl SparkMonotonicallyIncreasingIdExpr { + pub fn new(partition_id: usize) -> Self { + Self { + partition_id: partition_id as i64, + row_counter: AtomicI64::new(0), + } + } +} + +impl Display for SparkMonotonicallyIncreasingIdExpr { + fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + write!(f, "MonotonicallyIncreasingID") + } +} + +impl Debug for SparkMonotonicallyIncreasingIdExpr { + fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + write!(f, "MonotonicallyIncreasingID") + } +} + +impl PartialEq for SparkMonotonicallyIncreasingIdExpr { + fn eq(&self, other: &Self) -> bool { + self.partition_id == other.partition_id + && self.row_counter.load(SeqCst) == other.row_counter.load(SeqCst) + } +} + +impl Eq for SparkMonotonicallyIncreasingIdExpr {} + +impl Hash for SparkMonotonicallyIncreasingIdExpr { + fn hash<H: Hasher>(&self, state: &mut H) { + self.partition_id.hash(state); + self.row_counter.load(SeqCst).hash(state); + } Review Comment: `PartialEq` and `Hash` currently incorporate `row_counter`, so the equality and hash of `SparkMonotonicallyIncreasingIdExpr` change as the expression is evaluated. For non-deterministic physical expressions we generally avoid depending on mutable internal state in Eq/Hash (see `row_num.rs:53-64`), to keep expression identity stable for caching/reuse and map/set keys. Consider basing Eq/Hash only on the static configuration (e.g., `partition_id`) or mirroring `RowNumExpr` by making all instances equal with a constant hash. -- 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]
