Skip to content

Commit

Permalink
Add few more type conversions
Browse files Browse the repository at this point in the history
  • Loading branch information
scgkiran committed Mar 7, 2025
1 parent 9cf4e59 commit 736685c
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 5 deletions.
40 changes: 35 additions & 5 deletions src/arrow_copy_functions.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
#include "arrow_copy_functions.hpp"
#include "arrow_to_ipc.hpp"
#include "duckdb/common/types/value.hpp"
#include "duckdb/main/config.hpp"
#include "duckdb/common/file_system.hpp"
#include "duckdb/function/table/arrow.hpp"
#include "arrow/c/bridge.h"
#include "arrow/io/file.h"
#include "arrow/ipc/writer.h"
#include "arrow_to_ipc.hpp"
#include "duckdb/common/file_system.hpp"
#include "duckdb/function/table/arrow.hpp"
#include "duckdb/main/config.hpp"

namespace duckdb {

Expand Down Expand Up @@ -48,6 +47,37 @@ ArrowIPCWriteInitializeGlobal(ClientContext &context, FunctionData &bind_data,
case LogicalTypeId::BIGINT:
arrow_type = arrow::int64();
break;
case LogicalTypeId::VARCHAR:
arrow_type = arrow::utf8();
break;
case LogicalTypeId::DOUBLE:
arrow_type = arrow::float64();
break;
case LogicalTypeId::BOOLEAN:
arrow_type = arrow::boolean();
break;
case LogicalTypeId::DATE:
arrow_type = arrow::date32();
break;
case LogicalTypeId::TIMESTAMP_SEC:
arrow_type = arrow::timestamp(arrow::TimeUnit::SECOND);
break;
case LogicalTypeId::TIMESTAMP_MS:
arrow_type = arrow::timestamp(arrow::TimeUnit::MILLI);
break;
case LogicalTypeId::TIMESTAMP:
arrow_type = arrow::timestamp(arrow::TimeUnit::MICRO);
break;
case LogicalTypeId::TIMESTAMP_NS:
arrow_type = arrow::timestamp(arrow::TimeUnit::NANO);
break;
case LogicalTypeId::BLOB:
arrow_type = arrow::binary();
break;
case LogicalTypeId::DECIMAL:
arrow_type = arrow::decimal(DecimalType::GetWidth(sql_type),
DecimalType::GetScale(sql_type));
break;
// Add more type conversions as needed
default:
throw IOException("Unsupported type for Arrow IPC: " +
Expand Down
22 changes: 22 additions & 0 deletions test/sql/arrow_ipc/write_arrow_ipc.test
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,25 @@ query I
SELECT COUNT(*) FROM test_verify;
----
1000

statement ok
CREATE TABLE all_types (id INTEGER, name TEXT, amount DOUBLE, is_active BOOLEAN, create_date DATE, created_at TIMESTAMP, big_number BIGINT, ratio DECIMAL(10,2), binary_data BLOB);

statement ok
INSERT INTO all_types VALUES
(1, 'Alice', 99.99, TRUE, '2024-02-01', '2024-02-01 12:00:00', 123456789012345, 3.14, X'68656C6C6F'),
(2, 'Bob', 250.75, FALSE, '2023-12-15', '2023-12-15 08:30:00', 987654321098765, 1.23, X'74657374');

statement ok
COPY all_types TO '__TEST_DIR__/all_types.arrow' (FORMAT 'arrow');

statement ok
CREATE TABLE all_types_verify (id INTEGER, name TEXT, amount DOUBLE, is_active BOOLEAN, create_date DATE, created_at TIMESTAMP, big_number BIGINT, ratio DECIMAL(10,2), binary_data BLOB);

statement ok
COPY all_types_verify FROM '__TEST_DIR__/all_types.arrow' (FORMAT 'arrow');

query I
SELECT COUNT(*) FROM all_types_verify;
----
2

0 comments on commit 736685c

Please sign in to comment.