forked from arana-db/arana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: use new dataset api with streaming style (arana-db#196)
* add license for dockerfile * feat: use new dataset api with streaming style * fix review * fix review Co-authored-by: AlexStocks <[email protected]>
- Loading branch information
1 parent
c761426
commit 8210501
Showing
56 changed files
with
3,295 additions
and
2,569 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
* Licensed to the 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. | ||
* The 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 dataset | ||
|
||
import ( | ||
"github.com/arana-db/arana/pkg/proto" | ||
) | ||
|
||
type pipeOption []func(proto.Dataset) proto.Dataset | ||
|
||
func Filter(predicate PredicateFunc) Option { | ||
return func(option *pipeOption) { | ||
*option = append(*option, func(prev proto.Dataset) proto.Dataset { | ||
return FilterDataset{ | ||
Dataset: prev, | ||
Predicate: predicate, | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func Map(generateFields FieldsFunc, transform TransformFunc) Option { | ||
return func(option *pipeOption) { | ||
*option = append(*option, func(dataset proto.Dataset) proto.Dataset { | ||
return &TransformDataset{ | ||
Dataset: dataset, | ||
FieldsGetter: generateFields, | ||
Transform: transform, | ||
} | ||
}) | ||
} | ||
} | ||
|
||
type Option func(*pipeOption) | ||
|
||
func Pipe(root proto.Dataset, options ...Option) proto.Dataset { | ||
var o pipeOption | ||
for _, it := range options { | ||
it(&o) | ||
} | ||
|
||
next := root | ||
for _, it := range o { | ||
next = it(next) | ||
} | ||
|
||
return next | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* Licensed to the 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. | ||
* The 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 dataset | ||
|
||
import ( | ||
"errors" | ||
) | ||
|
||
import ( | ||
perrors "github.com/pkg/errors" | ||
) | ||
|
||
var errLengthNotMatched = errors.New("dataset: the length of dest values doesn't match") | ||
|
||
// IsLengthNotMatchedError returns true if target error is length-not-matched error. | ||
func IsLengthNotMatchedError(err error) bool { | ||
return perrors.Is(err, errLengthNotMatched) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
* Licensed to the 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. | ||
* The 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 dataset | ||
|
||
import ( | ||
"github.com/pkg/errors" | ||
) | ||
|
||
import ( | ||
"github.com/arana-db/arana/pkg/proto" | ||
) | ||
|
||
var _ proto.Dataset = (*FilterDataset)(nil) | ||
|
||
type PredicateFunc func(proto.Row) bool | ||
|
||
type FilterDataset struct { | ||
proto.Dataset | ||
Predicate PredicateFunc | ||
} | ||
|
||
func (f FilterDataset) Next() (proto.Row, error) { | ||
if f.Predicate == nil { | ||
return f.Dataset.Next() | ||
} | ||
|
||
row, err := f.Dataset.Next() | ||
if err != nil { | ||
return nil, errors.WithStack(err) | ||
} | ||
|
||
if !f.Predicate(row) { | ||
return f.Next() | ||
} | ||
|
||
return row, nil | ||
} |
Oops, something went wrong.