jayzhan211 commented on code in PR #14617: URL: https://github.com/apache/datafusion/pull/14617#discussion_r1951861002
########## datafusion/common/src/scalar/logical/logical_timestamp.rs: ########## @@ -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. + +use crate::types::{logical_timestamp, LogicalTypeRef}; +use crate::{Result, _internal_datafusion_err}; +use arrow_array::temporal_conversions::{as_datetime, as_datetime_with_timezone}; +use arrow_array::timezone::Tz; +use arrow_array::types::{ + TimestampMicrosecondType, TimestampMillisecondType, TimestampNanosecondType, + TimestampSecondType, +}; +use arrow_schema::TimeUnit; +use chrono::{DateTime, NaiveDateTime}; +use std::fmt::{Display, Formatter}; +use std::str::FromStr; +use std::sync::Arc; + +/// TODO logical-types +#[derive(Debug, Clone, Eq, Hash, PartialEq, PartialOrd, Ord)] +pub struct LogicalTimestamp { + time_unit: TimeUnit, + time_zone: Option<Arc<str>>, + value: i64, +} + +impl LogicalTimestamp { + /// Creates a new [LogicalTimestamp]. + pub fn new( + time_unit: TimeUnit, + time_zone: Option<Arc<str>>, + value: i64, + ) -> LogicalTimestamp { + LogicalTimestamp { + time_unit, + time_zone, + value, + } + } + + /// Returns the logical type of this value. + pub fn logical_type(&self) -> LogicalTypeRef { + logical_timestamp(self.time_unit, self.time_zone.clone()) + } + + /// Returns the [TimeUnit] of this value. + pub fn time_unit(&self) -> TimeUnit { + self.time_unit + } + + /// Returns the value of this timestamp as [DateTime] or [NaiveDateTime] depending on whether + /// there is a time zone. + pub fn value(&self) -> Result<LogicalTimestampValue> { Review Comment: Do we need `value` for LogicalScalar, we don't have similar functionality for ScalarValue -- 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