iceberg_datafusion/error.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 anyhow::anyhow;
19use iceberg::{Error, ErrorKind};
20
21/// Converts a datafusion error into an iceberg error.
22pub fn from_datafusion_error(error: datafusion::error::DataFusionError) -> Error {
23 Error::new(
24 ErrorKind::Unexpected,
25 "Operation failed for hitting datafusion error".to_string(),
26 )
27 .with_source(anyhow!("datafusion error: {:?}", error))
28}
29/// Converts an iceberg error into a datafusion error.
30pub fn to_datafusion_error(error: Error) -> datafusion::error::DataFusionError {
31 datafusion::error::DataFusionError::External(error.into())
32}