Ejemplo n.º 1
0
        public async Task TestPutSingleRecordBatch()
        {
            var flightDescriptor = FlightDescriptor.CreatePathDescriptor("test");
            var expectedBatch    = CreateTestBatch(0, 100);

            var putStream = _flightClient.StartPut(flightDescriptor);
            await putStream.RequestStream.WriteAsync(expectedBatch);

            await putStream.RequestStream.CompleteAsync();

            var putResults = await putStream.ResponseStream.ToListAsync();

            Assert.Single(putResults);

            var actualBatches = GetStoreBatch(flightDescriptor);

            Assert.Single(actualBatches);

            ArrowReaderVerifier.CompareBatches(expectedBatch, actualBatches.First().RecordBatch);
        }
Ejemplo n.º 2
0
        public static async Task Main(string[] args)
        {
            string host = args.Length > 0 ? args[0] : "localhost";
            string port = args.Length > 1 ? args[1] : "5000";

            // Create client
            // (In production systems, you should use https not http)
            var address = $"http://{host}:{port}";

            Console.WriteLine($"Connecting to: {address}");
            var channel = GrpcChannel.ForAddress(address);
            var client  = new FlightClient(channel);

            var recordBatches = new RecordBatch[] {
                CreateTestBatch(0, 2000), CreateTestBatch(50, 9000)
            };

            // Particular flights are identified by a descriptor. This might be a name,
            // a SQL query, or a path. Here, just using the name "test".
            var descriptor = FlightDescriptor.CreateCommandDescriptor("test");

            // Upload data with StartPut
            var batchStreamingCall = client.StartPut(descriptor);

            foreach (var batch in recordBatches)
            {
                await batchStreamingCall.RequestStream.WriteAsync(batch);
            }
            // Signal we are done sending record batches
            await batchStreamingCall.RequestStream.CompleteAsync();

            // Retrieve final response
            await batchStreamingCall.ResponseStream.MoveNext();

            Console.WriteLine(batchStreamingCall.ResponseStream.Current.ApplicationMetadata.ToStringUtf8());
            Console.WriteLine($"Wrote {recordBatches.Length} batches to server.");

            // Request information:
            var schema = await client.GetSchema(descriptor).ResponseAsync;

            Console.WriteLine($"Schema saved as: \n {schema}");

            var info = await client.GetInfo(descriptor).ResponseAsync;

            Console.WriteLine($"Info provided: \n {info}");

            Console.WriteLine($"Available flights:");
            var flights_call = client.ListFlights();

            while (await flights_call.ResponseStream.MoveNext())
            {
                Console.WriteLine("  " + flights_call.ResponseStream.Current.ToString());
            }

            // Download data
            await foreach (var batch in StreamRecordBatches(info))
            {
                Console.WriteLine($"Read batch from flight server: \n {batch}");
            }

            // See available comands on this server
            var action_stream = client.ListActions();

            Console.WriteLine("Actions:");
            while (await action_stream.ResponseStream.MoveNext())
            {
                var action = action_stream.ResponseStream.Current;
                Console.WriteLine($"  {action.Type}: {action.Description}");
            }

            // Send clear command to drop all data from the server.
            var clear_result = client.DoAction(new FlightAction("clear"));
            await clear_result.ResponseStream.MoveNext(default);