rluvaton commented on code in PR #1199: URL: https://github.com/apache/datafusion-comet/pull/1199#discussion_r1903241784
########## native/spark-expr/src/rand.rs: ########## @@ -0,0 +1,272 @@ +// 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 crate::spark_hash::spark_compatible_murmur3_hash; +use arrow_array::builder::Float64Builder; +use arrow_array::{Float64Array, RecordBatch}; +use arrow_schema::{DataType, Schema}; +use datafusion::logical_expr::ColumnarValue; +use datafusion::physical_expr::PhysicalExpr; +use datafusion::physical_expr_common::physical_expr::down_cast_any_ref; +use datafusion_common::ScalarValue; +use datafusion_common::{DataFusionError, Result}; +use std::any::Any; +use std::fmt::Display; +use std::hash::{Hash, Hasher}; +use std::sync::{Arc, Mutex}; + +/// Adoption of the XOR-shift algorithm used in Apache Spark. +/// See: https://github.com/apache/spark/blob/master/core/src/main/scala/org/apache/spark/util/random/XORShiftRandom.scala + +/// Normalization multiplier used in mapping from a random i64 value to the f64 interval [0.0, 1.0). +/// Corresponds to the java implementation: https://github.com/openjdk/jdk/blob/master/src/java.base/share/classes/java/util/Random.java#L302) +/// Due to the lack of hexadecimal float literals support in rust, the scientific notation is used instead. +const DOUBLE_UNIT: f64 = 1.1102230246251565e-16; + +/// Spark-compatible initial seed which is actually a part of the scala standard library murmurhash3 implementation. +/// The references: +/// https://github.com/apache/spark/blob/master/core/src/main/scala/org/apache/spark/util/random/XORShiftRandom.scala#L63 +/// https://github.com/scala/scala/blob/2.13.x/src/library/scala/util/hashing/MurmurHash3.scala#L331 +const SPARK_MURMUR_ARRAY_SEED: u32 = 0x3c074a61; Review Comment: Please replace the links with peramlink as when the file will move the link will not be valid anymore + if the logic changed we can know when -- 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: github-unsubscr...@datafusion.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org For additional commands, e-mail: github-h...@datafusion.apache.org