mbrobbel commented on code in PR #1883: URL: https://github.com/apache/arrow-adbc/pull/1883#discussion_r1639503691
########## rust/drivers/dummy/tests/driver_exporter_dummy.rs: ########## @@ -0,0 +1,655 @@ +// 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. + +/// This integration test compares the output of the dummy driver when it's used +/// directly using the Rust API (native) and trough the exported driver via the +/// driver manager (exported). That allows us to test that data correctly round-trip +/// between C and Rust. +use std::ops::Deref; +use std::sync::Arc; + +use arrow::array::{Array, Float64Array, Int64Array, StringArray}; +use arrow::compute::concat_batches; +use arrow::datatypes::{DataType, Field, Schema}; +use arrow::record_batch::{RecordBatch, RecordBatchReader}; + +use adbc_core::driver_manager::{ + ManagedConnection, ManagedDatabase, ManagedDriver, ManagedStatement, +}; +use adbc_core::options::{ + AdbcVersion, InfoCode, IngestMode, IsolationLevel, ObjectDepth, OptionConnection, + OptionDatabase, OptionStatement, +}; +use adbc_core::Statement; +use adbc_core::{schemas, Connection, Database, Driver, Optionable}; + +use adbc_dummy::{DummyConnection, DummyDatabase, DummyDriver, DummyStatement, SingleBatchReader}; + +const OPTION_STRING_LONG: &str = "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"; +const OPTION_BYTES_LONG: &[u8] = b"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"; + +pub fn concat_reader(reader: impl RecordBatchReader) -> RecordBatch { + let schema = reader.schema(); + let batches: Vec<RecordBatch> = reader.map(|b| b.unwrap()).collect(); + concat_batches(&schema, &batches).unwrap() +} Review Comment: This looks like it's the same as https://github.com/apache/arrow-adbc/pull/1883/files#diff-9dc57bbb231bd39c254025eae69a0078c867005bacdee8ad5c3e336150d37045R81-R85. ########## rust/drivers/dummy/tests/driver_exporter_dummy.rs: ########## @@ -0,0 +1,655 @@ +// 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. + +/// This integration test compares the output of the dummy driver when it's used +/// directly using the Rust API (native) and trough the exported driver via the +/// driver manager (exported). That allows us to test that data correctly round-trip +/// between C and Rust. +use std::ops::Deref; +use std::sync::Arc; + +use arrow::array::{Array, Float64Array, Int64Array, StringArray}; +use arrow::compute::concat_batches; +use arrow::datatypes::{DataType, Field, Schema}; +use arrow::record_batch::{RecordBatch, RecordBatchReader}; + +use adbc_core::driver_manager::{ + ManagedConnection, ManagedDatabase, ManagedDriver, ManagedStatement, +}; +use adbc_core::options::{ + AdbcVersion, InfoCode, IngestMode, IsolationLevel, ObjectDepth, OptionConnection, + OptionDatabase, OptionStatement, +}; +use adbc_core::Statement; +use adbc_core::{schemas, Connection, Database, Driver, Optionable}; + +use adbc_dummy::{DummyConnection, DummyDatabase, DummyDriver, DummyStatement, SingleBatchReader}; + +const OPTION_STRING_LONG: &str = "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"; +const OPTION_BYTES_LONG: &[u8] = b"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"; + +pub fn concat_reader(reader: impl RecordBatchReader) -> RecordBatch { + let schema = reader.schema(); + let batches: Vec<RecordBatch> = reader.map(|b| b.unwrap()).collect(); + concat_batches(&schema, &batches).unwrap() +} + +pub fn sample_batch() -> RecordBatch { Review Comment: Also duplicated. ########## rust/core/tests/common/mod.rs: ########## @@ -0,0 +1,342 @@ +// 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. + +use std::collections::HashSet; +use std::ops::Deref; +use std::sync::Arc; + +use adbc_core::driver_manager::{ + ManagedConnection, ManagedDatabase, ManagedDriver, ManagedStatement, +}; +use adbc_core::error::Status; +use adbc_core::options::{ + InfoCode, IngestMode, ObjectDepth, OptionConnection, OptionDatabase, OptionStatement, +}; +use adbc_core::schemas; +use adbc_core::{Connection, Database, Driver, Optionable, Statement}; + +use arrow::array::{as_string_array, Array, Float64Array, Int64Array, StringArray}; +use arrow::compute::concat_batches; +use arrow::datatypes::{DataType, Field, Schema, SchemaRef}; +use arrow::error::ArrowError; +use arrow::record_batch::{RecordBatch, RecordBatchReader}; + +pub struct SingleBatchReader { + batch: Option<RecordBatch>, + schema: SchemaRef, +} + +impl SingleBatchReader { + pub fn new(batch: RecordBatch) -> Self { + let schema = batch.schema(); + Self { + batch: Some(batch), + schema, + } + } +} + +impl Iterator for SingleBatchReader { + type Item = std::result::Result<RecordBatch, ArrowError>; Review Comment: Maybe add a note why this is wrapped in `Result`? (seems to be for `RecordBatchReader`) -- 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. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
