|
| 1 | +// Licensed to the Apache Software Foundation (ASF) under one |
| 2 | +// or more contributor license agreements. See the NOTICE file |
| 3 | +// distributed with this work for additional information |
| 4 | +// regarding copyright ownership. The ASF licenses this file |
| 5 | +// to you under the Apache License, Version 2.0 (the |
| 6 | +// "License"); you may not use this file except in compliance |
| 7 | +// with the License. You may obtain a copy of the License at |
| 8 | +// |
| 9 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +// |
| 11 | +// Unless required by applicable law or agreed to in writing, |
| 12 | +// software distributed under the License is distributed on an |
| 13 | +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 14 | +// KIND, either express or implied. See the License for the |
| 15 | +// specific language governing permissions and limitations |
| 16 | +// under the License. |
| 17 | + |
| 18 | +//! Defines physical expressions that can evaluated at runtime during query execution |
| 19 | +
|
| 20 | +use std::any::Any; |
| 21 | +use std::convert::TryFrom; |
| 22 | +use std::sync::Arc; |
| 23 | + |
| 24 | +use crate::error::{DataFusionError, Result}; |
| 25 | +use crate::physical_plan::{Accumulator, AggregateExpr, PhysicalExpr}; |
| 26 | +use crate::scalar::ScalarValue; |
| 27 | +use arrow::compute; |
| 28 | +use arrow::datatypes::{DataType, TimeUnit}; |
| 29 | +use arrow::{ |
| 30 | + array::{ |
| 31 | + ArrayRef, Float32Array, Float64Array, Int16Array, Int32Array, Int64Array, Int8Array, |
| 32 | + LargeStringArray, StringArray, TimestampMicrosecondArray, TimestampMillisecondArray, |
| 33 | + TimestampNanosecondArray, TimestampSecondArray, UInt16Array, UInt32Array, |
| 34 | + UInt64Array, UInt8Array, |
| 35 | + }, |
| 36 | + datatypes::Field, |
| 37 | +}; |
| 38 | + |
| 39 | +pub struct RowNumber { |
| 40 | + name: String, |
| 41 | + expr: Arc<dyn PhysicalSortExpr>, |
| 42 | +} |
| 43 | + |
| 44 | +impl RowNumber { |
| 45 | + /// Create a new MAX aggregate function |
| 46 | + pub fn new(expr: Arc<dyn PhysicalExpr>, name: String) -> Self { |
| 47 | + Self { name, expr } |
| 48 | + } |
| 49 | +} |
| 50 | + |
| 51 | +impl BuiltInWindowFunctionExpr for RowNumber { |
| 52 | + /// Return a reference to Any that can be used for downcasting |
| 53 | + fn as_any(&self) -> &dyn Any { |
| 54 | + self |
| 55 | + } |
| 56 | + |
| 57 | + fn field(&self) -> Result<Field> { |
| 58 | + let nullable = false; |
| 59 | + let data_type = DataType::UInt64; |
| 60 | + Ok(Field::new(&self.name, data_type, nullable)) |
| 61 | + } |
| 62 | + |
| 63 | + fn expressions(&self) -> Vec<Arc<dyn PhysicalExpr>> { |
| 64 | + vec![self.expr.clone()] |
| 65 | + } |
| 66 | + |
| 67 | + fn name(&self) -> &str { |
| 68 | + &self.name |
| 69 | + } |
| 70 | +} |
0 commit comments