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 e65762b  Add support for Float (#71)
e65762b is described below

commit e65762b6df015f35477a3cb2a8d8012c5c63996d
Author: Sutou Kouhei <[email protected]>
AuthorDate: Tue Aug 22 15:47:52 2023 +0900

    Add support for Float (#71)
    
    Closes GH-55
---
 src/afs.cc              | 17 +++++++++++++++++
 test/test-flight-sql.rb |  8 +++++++-
 2 files changed, 24 insertions(+), 1 deletion(-)

diff --git a/src/afs.cc b/src/afs.cc
index 8e5e1f5..f945f7c 100644
--- a/src/afs.cc
+++ b/src/afs.cc
@@ -779,6 +779,12 @@ class ArrowPGTypeConverter : public arrow::TypeVisitor {
                return arrow::Status::OK();
        }
 
+       arrow::Status Visit(const arrow::FloatType& type)
+       {
+               oid_ = FLOAT4OID;
+               return arrow::Status::OK();
+       }
+
    private:
        Oid oid_;
 };
@@ -838,6 +844,12 @@ class ArrowPGValueConverter : public arrow::ArrayVisitor {
                return arrow::Status::OK();
        }
 
+       arrow::Status Visit(const arrow::FloatArray& array)
+       {
+               datum_ = Float4GetDatum(array.Value(i_row_));
+               return arrow::Status::OK();
+       }
+
    private:
        int64_t i_row_;
        Datum& datum_;
@@ -857,6 +869,8 @@ class PGArrowValueConverter : public arrow::ArrayVisitor {
                                return arrow::int32();
                        case INT8OID:
                                return arrow::int64();
+                       case FLOAT4OID:
+                               return arrow::float32();
                        default:
                                return 
arrow::Status::NotImplemented("Unsupported PostgreSQL type: ",
                                                                     
attribute_->atttypid);
@@ -876,6 +890,9 @@ class PGArrowValueConverter : public arrow::ArrayVisitor {
                        case INT8OID:
                                return 
static_cast<arrow::Int64Builder*>(builder)->Append(
                                        DatumGetInt64(datum));
+                       case FLOAT4OID:
+                               return 
static_cast<arrow::FloatBuilder*>(builder)->Append(
+                                       DatumGetFloat4(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 caf68c2..7d9ded8 100644
--- a/test/test-flight-sql.rb
+++ b/test/test-flight-sql.rb
@@ -32,6 +32,7 @@ class FlightSQLTest < Test::Unit::TestCase
   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])
   def test_select_type
     pg_type, array_class, value = data
     values = array_class.new([value])
@@ -89,6 +90,7 @@ 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]])
   def test_insert_type
     unless flight_sql_client.respond_to?(:prepare)
       omit("red-arrow-flight-sql 14.0.0 or later is required")
@@ -111,7 +113,11 @@ SELECT * FROM data
 -------
     RESULT
     values.each do |value|
-      output << (" %5d\n" % value)
+      if value.is_a?(Float)
+        output << (" %5.1f\n" % value)
+      else
+        output << (" %5d\n" % value)
+      end
     end
     output << "(#{values.size} rows)\n"
     output << "\n"

Reply via email to