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 8fabbb9 Add support for prepared statement SELECT without parameters
(#179)
8fabbb9 is described below
commit 8fabbb96a5c703f4f7be4278b8280603bff1f219
Author: Sutou Kouhei <[email protected]>
AuthorDate: Sun Dec 10 07:44:25 2023 +0900
Add support for prepared statement SELECT without parameters (#179)
Closes GH-178
---
src/afs.cc | 13 +++++++++++++
test/test-flight-sql.rb | 16 ++++++++++++++++
2 files changed, 29 insertions(+)
diff --git a/src/afs.cc b/src/afs.cc
index d564fbc..2d77798 100644
--- a/src/afs.cc
+++ b/src/afs.cc
@@ -1309,6 +1309,19 @@ class PreparedStatement {
using WriteFunc = std::add_pointer<arrow::Status(void*)>::type;
arrow::Status select(WriteFunc write, void* writeData)
{
+ if (parameters_.empty())
+ {
+ auto result = SPI_execute(query_.c_str(), false, 0);
+ if (result <= 0)
+ {
+ return arrow::Status::Invalid("failed to run a
query: ",
+
SPI_result_code_string(result),
+ ": ",
+ query_);
+ }
+ return write(writeData);
+ }
+
for (const auto& recordBatch : parameters_)
{
SPIExecuteOptions options = {};
diff --git a/test/test-flight-sql.rb b/test/test-flight-sql.rb
index 87abc59..2b3640d 100644
--- a/test/test-flight-sql.rb
+++ b/test/test-flight-sql.rb
@@ -114,6 +114,22 @@ class FlightSQLTest < Test::Unit::TestCase
end
end
+ def test_select_prepare_without_parameters
+ unless flight_sql_client.respond_to?(:prepare)
+ omit("red-arrow-flight-sql 14.0.0 or later is required")
+ end
+
+ flight_sql_client.prepare("SELECT 29 AS value", @options) do |statement|
+ info = statement.execute(@options)
+ assert_equal(Arrow::Schema.new(value: :int32),
+ info.get_schema)
+ endpoint = info.endpoints.first
+ reader = flight_sql_client.do_get(endpoint.ticket, @options)
+ assert_equal(Arrow::Table.new(value: Arrow::Int32Array.new([29])),
+ reader.read_all)
+ end
+ end
+
def test_select_from
run_sql("CREATE TABLE data (value integer)")
run_sql("INSERT INTO data VALUES (1), (-2), (3)")