You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by GitBox <gi...@apache.org> on 2022/07/24 02:39:44 UTC

[GitHub] [skywalking-banyandb] hanahmily commented on a diff in pull request #136: Add streaming API and topN aggregator

hanahmily commented on code in PR #136:
URL: https://github.com/apache/skywalking-banyandb/pull/136#discussion_r928185815


##########
pkg/flow/api/types.go:
##########
@@ -0,0 +1,98 @@
+// Licensed to Apache Software Foundation (ASF) under one or more contributor
+// license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright
+// ownership. Apache Software Foundation (ASF) licenses this file to you 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 api
+
+import (
+	"google.golang.org/protobuf/types/known/timestamppb"
+)
+
+type Flow interface {
+	Filter(f interface{}) Flow

Review Comment:
   Is `func(interface{}) bool` better for `f`?



##########
pkg/flow/api/types.go:
##########
@@ -0,0 +1,98 @@
+// Licensed to Apache Software Foundation (ASF) under one or more contributor
+// license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright
+// ownership. Apache Software Foundation (ASF) licenses this file to you 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 api
+
+import (
+	"google.golang.org/protobuf/types/known/timestamppb"
+)
+
+type Flow interface {
+	Filter(f interface{}) Flow
+	Map(f interface{}) Flow
+	Window(WindowAssigner) WindowedFlow
+	Offset(int) Flow
+	Limit(int) Flow
+	To(interface{}) Flow
+	OpenAsync() <-chan error
+	OpenSync() error
+}
+
+type WindowedFlow interface {
+	TopN(topNum int, opts ...any) Flow
+	Aggregate(aggrFunc AggregateFunction) Flow
+}
+
+type Window interface {
+	MaxTimestamp() int64
+}
+
+type WindowAssigner interface {
+	AssignWindows(int64) ([]Window, error)
+}
+
+//go:generate mockgen -destination=./aggregation_func_mock.go -package=api github.com/apache/skywalking-banyandb/pkg/flow/api AggregateFunction
+type AggregateFunction interface {
+	Add([]interface{})
+	GetResult() interface{}
+}
+
+type StreamRecord struct {
+	ts           int64
+	hasTimestamp bool

Review Comment:
   I didn't find any references from external packages? Is it redundant?



##########
pkg/flow/api/types.go:
##########
@@ -0,0 +1,98 @@
+// Licensed to Apache Software Foundation (ASF) under one or more contributor
+// license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright
+// ownership. Apache Software Foundation (ASF) licenses this file to you 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 api
+
+import (
+	"google.golang.org/protobuf/types/known/timestamppb"
+)
+
+type Flow interface {
+	Filter(f interface{}) Flow
+	Map(f interface{}) Flow
+	Window(WindowAssigner) WindowedFlow
+	Offset(int) Flow
+	Limit(int) Flow
+	To(interface{}) Flow
+	OpenAsync() <-chan error
+	OpenSync() error
+}
+
+type WindowedFlow interface {
+	TopN(topNum int, opts ...any) Flow
+	Aggregate(aggrFunc AggregateFunction) Flow
+}
+
+type Window interface {
+	MaxTimestamp() int64
+}
+
+type WindowAssigner interface {
+	AssignWindows(int64) ([]Window, error)

Review Comment:
   Is the parameter a time range?



##########
pkg/flow/api/types.go:
##########
@@ -0,0 +1,98 @@
+// Licensed to Apache Software Foundation (ASF) under one or more contributor
+// license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright
+// ownership. Apache Software Foundation (ASF) licenses this file to you 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 api
+
+import (
+	"google.golang.org/protobuf/types/known/timestamppb"
+)
+
+type Flow interface {
+	Filter(f interface{}) Flow
+	Map(f interface{}) Flow

Review Comment:
   how about opting to `func (i interface{}) interface{}` instead `interface`?



##########
pkg/flow/api/types.go:
##########
@@ -0,0 +1,98 @@
+// Licensed to Apache Software Foundation (ASF) under one or more contributor
+// license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright
+// ownership. Apache Software Foundation (ASF) licenses this file to you 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 api
+
+import (
+	"google.golang.org/protobuf/types/known/timestamppb"
+)
+
+type Flow interface {
+	Filter(f interface{}) Flow
+	Map(f interface{}) Flow
+	Window(WindowAssigner) WindowedFlow
+	Offset(int) Flow
+	Limit(int) Flow
+	To(interface{}) Flow
+	OpenAsync() <-chan error
+	OpenSync() error
+}
+
+type WindowedFlow interface {
+	TopN(topNum int, opts ...any) Flow
+	Aggregate(aggrFunc AggregateFunction) Flow
+}
+
+type Window interface {
+	MaxTimestamp() int64
+}
+
+type WindowAssigner interface {
+	AssignWindows(int64) ([]Window, error)
+}
+
+//go:generate mockgen -destination=./aggregation_func_mock.go -package=api github.com/apache/skywalking-banyandb/pkg/flow/api AggregateFunction
+type AggregateFunction interface {

Review Comment:
   From current implements, it is can be simplified by `type AggregateFunction func([]interface{})interface{}`.



##########
pkg/flow/api/types.go:
##########
@@ -0,0 +1,98 @@
+// Licensed to Apache Software Foundation (ASF) under one or more contributor
+// license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright
+// ownership. Apache Software Foundation (ASF) licenses this file to you 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 api
+
+import (
+	"google.golang.org/protobuf/types/known/timestamppb"
+)
+
+type Flow interface {
+	Filter(f interface{}) Flow
+	Map(f interface{}) Flow
+	Window(WindowAssigner) WindowedFlow
+	Offset(int) Flow
+	Limit(int) Flow
+	To(interface{}) Flow
+	OpenAsync() <-chan error
+	OpenSync() error
+}
+
+type WindowedFlow interface {
+	TopN(topNum int, opts ...any) Flow
+	Aggregate(aggrFunc AggregateFunction) Flow
+}
+
+type Window interface {
+	MaxTimestamp() int64
+}
+
+type WindowAssigner interface {
+	AssignWindows(int64) ([]Window, error)
+}
+
+//go:generate mockgen -destination=./aggregation_func_mock.go -package=api github.com/apache/skywalking-banyandb/pkg/flow/api AggregateFunction
+type AggregateFunction interface {
+	Add([]interface{})
+	GetResult() interface{}
+}
+
+type StreamRecord struct {
+	ts           int64
+	hasTimestamp bool
+	data         interface{}

Review Comment:
   You could leverage type parameters to implement this struct.
   
   ```
   type StreamRecord[T any] struct {
       ....
       data T
   }
   ```



##########
pkg/flow/api/types.go:
##########
@@ -0,0 +1,98 @@
+// Licensed to Apache Software Foundation (ASF) under one or more contributor
+// license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright
+// ownership. Apache Software Foundation (ASF) licenses this file to you 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 api
+
+import (
+	"google.golang.org/protobuf/types/known/timestamppb"
+)
+
+type Flow interface {

Review Comment:
   Could you add comments to all exported types? Now we have this checker in bydbctl, I would introduce it to other packages soon.



##########
pkg/flow/api/ds.go:
##########
@@ -0,0 +1,24 @@
+// Licensed to Apache Software Foundation (ASF) under one or more contributor
+// license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright
+// ownership. Apache Software Foundation (ASF) licenses this file to you 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 api
+
+type Data []any
+
+func Row(args ...any) Data {

Review Comment:
   Could you instance Data with `Data{...}` instead of this function.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@skywalking.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org