datafusion_physical_plan/windows/utils.rs
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
18use arrow::datatypes::{Schema, SchemaBuilder};
19use datafusion_common::Result;
20use datafusion_physical_expr::window::WindowExpr;
21use std::sync::Arc;
22
23pub(crate) fn create_schema(
24 input_schema: &Schema,
25 window_expr: &[Arc<dyn WindowExpr>],
26) -> Result<Schema> {
27 let capacity = input_schema.fields().len() + window_expr.len();
28 let mut builder = SchemaBuilder::with_capacity(capacity);
29 builder.extend(input_schema.fields().iter().cloned());
30 // append results to the schema
31 for expr in window_expr {
32 builder.push(expr.field()?);
33 }
34 Ok(builder
35 .finish()
36 .with_metadata(input_schema.metadata().clone()))
37}