Skip to content

Apache DataFusion SQL Query Engine

ARROW-8853: [Rust] [Integration Testing] Enable Flight tests

Carol (Nichols || Goulding)b97599385b15
diff --git a/dev/archery/archery/integration/runner.py b/dev/archery/archery/integration/runner.py
index c1d7a697ab..520f9c4b71 100644
--- a/dev/archery/archery/integration/runner.py
+++ b/dev/archery/archery/integration/runner.py
@@ -347,7 +347,9 @@ def run_all_tests(with_cpp=True, with_java=True, with_js=True,
description="Authenticate using the BasicAuth protobuf."),
Scenario(
"middleware",
- description="Ensure headers are propagated via middleware."),
+ description="Ensure headers are propagated via middleware.",
+ skip={"Rust"} # TODO(ARROW-10961): tonic upgrade needed
+ ),
]
runner = IntegrationRunner(json_files, flight_scenarios, testers, **kwargs)
diff --git a/dev/archery/archery/integration/tester_rust.py b/dev/archery/archery/integration/tester_rust.py
index 23c2d37386..bca80ebae3 100644
--- a/dev/archery/archery/integration/tester_rust.py
+++ b/dev/archery/archery/integration/tester_rust.py
@@ -15,7 +15,9 @@
# specific language governing permissions and limitations
# under the License.
+import contextlib
import os
+import subprocess
from .tester import Tester
from .util import run_cmd, ARROW_ROOT_DEFAULT, log
@@ -24,8 +26,8 @@ from .util import run_cmd, ARROW_ROOT_DEFAULT, log
class RustTester(Tester):
PRODUCER = True
CONSUMER = True
- # FLIGHT_SERVER = True
- # FLIGHT_CLIENT = True
+ FLIGHT_SERVER = True
+ FLIGHT_CLIENT = True
EXE_PATH = os.path.join(ARROW_ROOT_DEFAULT, 'rust/target/debug')
@@ -34,11 +36,11 @@ class RustTester(Tester):
STREAM_TO_FILE = os.path.join(EXE_PATH, 'arrow-stream-to-file')
FILE_TO_STREAM = os.path.join(EXE_PATH, 'arrow-file-to-stream')
- # FLIGHT_SERVER_CMD = [
- # os.path.join(EXE_PATH, 'flight-test-integration-server')]
- # FLIGHT_CLIENT_CMD = [
- # os.path.join(EXE_PATH, 'flight-test-integration-client'),
- # "-host", "localhost"]
+ FLIGHT_SERVER_CMD = [
+ os.path.join(EXE_PATH, 'flight-test-integration-server')]
+ FLIGHT_CLIENT_CMD = [
+ os.path.join(EXE_PATH, 'flight-test-integration-client'),
+ "--host", "localhost"]
name = 'Rust'
@@ -72,34 +74,42 @@ class RustTester(Tester):
cmd = [self.FILE_TO_STREAM, file_path, '>', stream_path]
self.run_shell_command(cmd)
- # @contextlib.contextmanager
- # def flight_server(self):
- # cmd = self.FLIGHT_SERVER_CMD + ['-port=0']
- # if self.debug:
- # log(' '.join(cmd))
- # server = subprocess.Popen(cmd,
- # stdout=subprocess.PIPE,
- # stderr=subprocess.PIPE)
- # try:
- # output = server.stdout.readline().decode()
- # if not output.startswith("Server listening on localhost:"):
- # server.kill()
- # out, err = server.communicate()
- # raise RuntimeError(
- # "Flight-C++ server did not start properly, "
- # "stdout:\n{}\n\nstderr:\n{}\n"
- # .format(output + out.decode(), err.decode()))
- # port = int(output.split(":")[1])
- # yield port
- # finally:
- # server.kill()
- # server.wait(5)
-
- # def flight_request(self, port, json_path):
- # cmd = self.FLIGHT_CLIENT_CMD + [
- # '-port=' + str(port),
- # '-path=' + json_path,
- # ]
- # if self.debug:
- # log(' '.join(cmd))
- # run_cmd(cmd)
+ @contextlib.contextmanager
+ def flight_server(self, scenario_name=None):
+ cmd = self.FLIGHT_SERVER_CMD + ['--port=0']
+ if scenario_name:
+ cmd = cmd + ["--scenario", scenario_name]
+ if self.debug:
+ log(' '.join(cmd))
+ server = subprocess.Popen(cmd,
+ stdout=subprocess.PIPE,
+ stderr=subprocess.PIPE)
+ try:
+ output = server.stdout.readline().decode()
+ if not output.startswith("Server listening on localhost:"):
+ server.kill()
+ out, err = server.communicate()
+ raise RuntimeError(
+ "Flight-Rust server did not start properly, "
+ "stdout:\n{}\n\nstderr:\n{}\n"
+ .format(output + out.decode(), err.decode()))
+ port = int(output.split(":")[1])
+ yield port
+ finally:
+ server.kill()
+ server.wait(5)
+
+ def flight_request(self, port, json_path=None, scenario_name=None):
+ cmd = self.FLIGHT_CLIENT_CMD + [
+ '--port=' + str(port),
+ ]
+ if json_path:
+ cmd.extend(('--path', json_path))
+ elif scenario_name:
+ cmd.extend(('--scenario', scenario_name))
+ else:
+ raise TypeError("Must provide one of json_path or scenario_name")
+
+ if self.debug:
+ log(' '.join(cmd))
+ run_cmd(cmd)
diff --git a/rust/datafusion/examples/flight_client.rs b/rust/datafusion/examples/flight_client.rs
index 13fd394d18..2c2954d5a0 100644
--- a/rust/datafusion/examples/flight_client.rs
+++ b/rust/datafusion/examples/flight_client.rs
@@ -62,10 +62,13 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
// all the remaining stream messages should be dictionary and record batches
let mut results = vec![];
+ let dictionaries_by_field = vec![None; schema.fields().len()];
while let Some(flight_data) = stream.message().await? {
- // the unwrap is infallible and thus safe
- let record_batch =
- flight_data_to_arrow_batch(&flight_data, schema.clone()).unwrap()?;
+ let record_batch = flight_data_to_arrow_batch(
+ &flight_data,
+ schema.clone(),
+ &dictionaries_by_field,
+ )?;
results.push(record_batch);
}
diff --git a/rust/datafusion/examples/flight_server.rs b/rust/datafusion/examples/flight_server.rs
index 47c476a88a..75b470d708 100644
--- a/rust/datafusion/examples/flight_server.rs
+++ b/rust/datafusion/examples/flight_server.rs
@@ -125,11 +125,14 @@ impl FlightService for FlightServiceImpl {
let mut batches: Vec<Result<FlightData, Status>> = results
.iter()
.flat_map(|batch| {
- let flight_data =
+ let (flight_dictionaries, flight_batch) =
arrow_flight::utils::flight_data_from_arrow_batch(
batch, &options,
);
- flight_data.into_iter().map(Ok)
+ flight_dictionaries
+ .into_iter()
+ .chain(std::iter::once(flight_batch))
+ .map(Ok)
})
.collect();