This is an automated email from the ASF dual-hosted git repository.
kou pushed a commit to branch main
in repository
https://gitbox.apache.org/repos/asf/arrow-flight-sql-postgresql.git
The following commit(s) were added to refs/heads/main by this push:
new ac275cf Add support for Double (#72)
ac275cf is described below
commit ac275cfaf19d2ba5bd613c7dfb6baae0785945af
Author: Sutou Kouhei <[email protected]>
AuthorDate: Tue Aug 22 16:17:00 2023 +0900
Add support for Double (#72)
Closes GH-56
---
src/afs.cc | 17 +++++++++++++++++
test/test-flight-sql.rb | 12 +++++++-----
2 files changed, 24 insertions(+), 5 deletions(-)
diff --git a/src/afs.cc b/src/afs.cc
index f945f7c..60a94ce 100644
--- a/src/afs.cc
+++ b/src/afs.cc
@@ -785,6 +785,12 @@ class ArrowPGTypeConverter : public arrow::TypeVisitor {
return arrow::Status::OK();
}
+ arrow::Status Visit(const arrow::DoubleType& type)
+ {
+ oid_ = FLOAT8OID;
+ return arrow::Status::OK();
+ }
+
private:
Oid oid_;
};
@@ -850,6 +856,12 @@ class ArrowPGValueConverter : public arrow::ArrayVisitor {
return arrow::Status::OK();
}
+ arrow::Status Visit(const arrow::DoubleArray& array)
+ {
+ datum_ = Float8GetDatum(array.Value(i_row_));
+ return arrow::Status::OK();
+ }
+
private:
int64_t i_row_;
Datum& datum_;
@@ -871,6 +883,8 @@ class PGArrowValueConverter : public arrow::ArrayVisitor {
return arrow::int64();
case FLOAT4OID:
return arrow::float32();
+ case FLOAT8OID:
+ return arrow::float64();
default:
return
arrow::Status::NotImplemented("Unsupported PostgreSQL type: ",
attribute_->atttypid);
@@ -893,6 +907,9 @@ class PGArrowValueConverter : public arrow::ArrayVisitor {
case FLOAT4OID:
return
static_cast<arrow::FloatBuilder*>(builder)->Append(
DatumGetFloat4(datum));
+ case FLOAT8OID:
+ return
static_cast<arrow::DoubleBuilder*>(builder)->Append(
+ DatumGetFloat8(datum));
default:
return
arrow::Status::NotImplemented("Unsupported PostgreSQL type: ",
attribute_->atttypid);
diff --git a/test/test-flight-sql.rb b/test/test-flight-sql.rb
index 7d9ded8..d25ef51 100644
--- a/test/test-flight-sql.rb
+++ b/test/test-flight-sql.rb
@@ -29,10 +29,11 @@ class FlightSQLTest < Test::Unit::TestCase
flight_client.authenticate_basic(user, password, @options)
end
- data("int16", ["smallint", Arrow::Int16Array, -2])
- data("int32", ["integer", Arrow::Int32Array, -2])
- data("int64", ["bigint", Arrow::Int64Array, -2])
- data("float", ["real" , Arrow::FloatArray, -2.2])
+ data("int16", ["smallint", Arrow::Int16Array, -2])
+ data("int32", ["integer", Arrow::Int32Array, -2])
+ data("int64", ["bigint", Arrow::Int64Array, -2])
+ data("float", ["real", Arrow::FloatArray, -2.2])
+ data("double", ["double precision", Arrow::DoubleArray, -2.2])
def test_select_type
pg_type, array_class, value = data
values = array_class.new([value])
@@ -90,7 +91,8 @@ SELECT * FROM data
data("uint16", ["smallint", Arrow::UInt16Array, [1, 2, 3]])
data("uint32", ["integer", Arrow::UInt32Array, [1, 2, 3]])
data("uint64", ["bigint", Arrow::UInt64Array, [1, 2, 3]])
- data("float", ["real", Arrow::FloatArray, [1.1, -2.2, 3.3]])
+ data("float", ["real", Arrow::FloatArray, [1.1, -2.2, 3.3]])
+ data("double", ["double precision", Arrow::DoubleArray, [1.1, -2.2, 3.3]])
def test_insert_type
unless flight_sql_client.respond_to?(:prepare)
omit("red-arrow-flight-sql 14.0.0 or later is required")