drusso commented on a change in pull request #8222:
URL: https://github.com/apache/arrow/pull/8222#discussion_r500980028



##########
File path: rust/datafusion/src/physical_plan/group_scalar.rs
##########
@@ -0,0 +1,77 @@
+// 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.
+
+//! Defines scalars used to construct groups, ex. in GROUP BY clauses.
+
+use std::convert::{From, TryFrom};
+
+use crate::error::{ExecutionError, Result};
+use crate::scalar::ScalarValue;
+
+/// Enumeration of types that can be used in a GROUP BY expression (all 
primitives except
+/// for floating point numerics)
+#[derive(Debug, PartialEq, Eq, Hash, Clone)]
+pub(crate) enum GroupByScalar {
+    UInt8(u8),
+    UInt16(u16),
+    UInt32(u32),
+    UInt64(u64),
+    Int8(i8),
+    Int16(i16),
+    Int32(i32),
+    Int64(i64),
+    Utf8(String),
+}
+
+impl TryFrom<&ScalarValue> for GroupByScalar {
+    type Error = ExecutionError;
+
+    fn try_from(scalar_value: &ScalarValue) -> Result<Self> {
+        Ok(match scalar_value {
+            ScalarValue::Int8(Some(v)) => GroupByScalar::Int8(*v),
+            ScalarValue::Int16(Some(v)) => GroupByScalar::Int16(*v),
+            ScalarValue::Int32(Some(v)) => GroupByScalar::Int32(*v),
+            ScalarValue::Int64(Some(v)) => GroupByScalar::Int64(*v),
+            ScalarValue::UInt8(Some(v)) => GroupByScalar::UInt8(*v),
+            ScalarValue::UInt16(Some(v)) => GroupByScalar::UInt16(*v),
+            ScalarValue::UInt32(Some(v)) => GroupByScalar::UInt32(*v),
+            ScalarValue::UInt64(Some(v)) => GroupByScalar::UInt64(*v),
+            ScalarValue::Utf8(Some(v)) => GroupByScalar::Utf8(v.clone()),
+            _ => {
+                return Err(ExecutionError::InternalError(
+                    "Cannot convert ScalarValue to GroupByScalar".to_string(),

Review comment:
       See 0b45657. I also improved the error messages a bit when the 
conversion is attempted with a `ScalarValue` holding `None`. 




----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to