risingwave_common/array/arrow/arrow_lancedb.rs
1// Copyright 2026 RisingWave Labs
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15//! Arrow conversion for `LanceDB` sink.
16//!
17//! `LanceDB` uses arrow-58, same as the `arrow_58` module.
18//! This module re-exports the arrow-58 types and provides a `LanceDbConvert` struct
19//! with a `to_record_batch` method (same pattern as `DeltaLakeConvert`).
20
21pub use super::arrow_58::{
22 FromArrow, ToArrow, arrow_array, arrow_buffer, arrow_cast, arrow_schema,
23};
24use crate::array::{ArrayError, DataChunk};
25use crate::catalog::Schema;
26
27pub struct LanceDbConvert;
28
29impl LanceDbConvert {
30 /// Convert a RisingWave `DataChunk` to an Arrow `RecordBatch`.
31 pub fn to_record_batch(
32 &self,
33 schema: arrow_schema::SchemaRef,
34 chunk: &DataChunk,
35 ) -> Result<arrow_array::RecordBatch, ArrayError> {
36 ToArrow::to_record_batch(self, schema, chunk)
37 }
38
39 /// Convert a RisingWave `Schema` to an Arrow `Schema`.
40 pub fn rw_schema_to_arrow_schema(
41 &self,
42 rw_schema: &Schema,
43 ) -> Result<arrow_schema::Schema, ArrayError> {
44 let fields = rw_schema
45 .fields()
46 .iter()
47 .map(|f| self.to_arrow_field(&f.name, &f.data_type))
48 .collect::<Result<Vec<_>, _>>()?;
49 Ok(arrow_schema::Schema::new(fields))
50 }
51}
52
53/// Use the default `ToArrow` implementation (no overrides needed for `LanceDB` initially).
54/// `DeltaLake` overrides `decimal_to_arrow` because of special Inf/NaN handling.
55/// `LanceDB` can use the default behavior. If custom type mapping is needed later
56/// (e.g., `Vector` -> `FixedSizeList`), add overrides here.
57impl ToArrow for LanceDbConvert {}
58impl FromArrow for LanceDbConvert {}