From 3bc0dc28f00086e686f57124ac33290d401cd8dd Mon Sep 17 00:00:00 2001 From: Travis Date: Wed, 27 Nov 2019 16:09:06 -0600 Subject: [PATCH] Add StreamClient and StreamServer interfaces In order to standardize results as streams of RowResponse, this PR introduces two interfaces `StreamClient` and `StreamServer`) which mirror the grpc stream interfaces. Upstream users (sqlmapper, vdsm, etc) can implement instances of these interfaces to ensure that results can stream through the entire sytem in an expected way. This PR also fixes a couple of missing data types. --- api/client/grpc.go | 6 +++--- proto/interface.go | 23 +++++++++++++++++++++++ server/grpc.go | 14 ++++++++++++++ 3 files changed, 40 insertions(+), 3 deletions(-) create mode 100644 proto/interface.go diff --git a/api/client/grpc.go b/api/client/grpc.go index 5eb8d5c61..2d99ea76e 100644 --- a/api/client/grpc.go +++ b/api/client/grpc.go @@ -58,7 +58,7 @@ func (c *GRPCClient) Close() error { } // Query returns a stream of RowResponse for the given index and PQL string. -func (c *GRPCClient) Query(ctx context.Context, index string, pql string) (grpc.ClientStream, error) { +func (c *GRPCClient) Query(ctx context.Context, index string, pql string) (pb.StreamClient, error) { if c.conn == nil { return nil, errors.New("client has not established a grpc connection") } @@ -79,8 +79,8 @@ func (c *GRPCClient) Query(ctx context.Context, index string, pql string) (grpc. } // Inspect returns a stream of RowResponse for the given index, columns, and filters. -// It is inteded to mimic something like "select [fields] from table where recordID IN (...)". -func (c *GRPCClient) Inspect(ctx context.Context, index string, columnIDs []uint64, columnKeys []string, fieldFilters []string) (grpc.ClientStream, error) { +// It is intended to mimic something like "select [fields] from table where recordID IN (...)". +func (c *GRPCClient) Inspect(ctx context.Context, index string, columnIDs []uint64, columnKeys []string, fieldFilters []string) (pb.StreamClient, error) { if c.conn == nil { return nil, errors.New("client has not established a grpc connection") } diff --git a/proto/interface.go b/proto/interface.go new file mode 100644 index 000000000..0a3913921 --- /dev/null +++ b/proto/interface.go @@ -0,0 +1,23 @@ +// Copyright 2017 Pilosa Corp. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package pilosa + +type StreamClient interface { + Recv() (*RowResponse, error) +} + +type StreamServer interface { + Send(*RowResponse) error +} diff --git a/server/grpc.go b/server/grpc.go index c5cb97cd5..339e7efa2 100644 --- a/server/grpc.go +++ b/server/grpc.go @@ -205,6 +205,9 @@ func (h grpcHandler) Inspect(req *pb.InspectRequest, stream pb.Pilosa_InspectSer rowResp.Columns = append(rowResp.Columns, &pb.ColumnResponse{ColumnVal: nil}) } + case "time": + rowResp.Columns = append(rowResp.Columns, + &pb.ColumnResponse{ColumnVal: nil}) } } @@ -548,6 +551,17 @@ func makeRows(resp pilosa.QueryResponse, logger logger.Logger) chan *pb.RowRespo Columns: []*pb.ColumnResponse{ &pb.ColumnResponse{ColumnVal: &pb.ColumnResponse_BoolVal{BoolVal: r}}, }} + case pilosa.ValCount: + ci := []*pb.ColumnInfo{ + {Name: "value", Datatype: "int64"}, + {Name: "count", Datatype: "int64"}, + } + results <- &pb.RowResponse{ + Headers: ci, + Columns: []*pb.ColumnResponse{ + &pb.ColumnResponse{ColumnVal: &pb.ColumnResponse_Int64Val{Int64Val: r.Val}}, + &pb.ColumnResponse{ColumnVal: &pb.ColumnResponse_Int64Val{Int64Val: r.Count}}, + }} default: logger.Printf("unhandled %T\n", r) breakLoop = true