Skip to content

Commit 2e4513f

Browse files
authored
Merge pull request #560 from v3io/development
dev -> master
2 parents 56d00ae + f5660bd commit 2e4513f

File tree

6 files changed

+23
-4
lines changed

6 files changed

+23
-4
lines changed

backends/kv/backend.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ type Backend struct {
4141
inactivityTimeout time.Duration
4242
framesConfig *frames.Config
4343
v3ioContext v3io.Context
44+
maxRecordsInfer int
4445
}
4546

4647
// NewBackend returns a new NoSQL (key/value) backend
@@ -52,6 +53,7 @@ func NewBackend(logger logger.Logger, v3ioContext v3io.Context, config *frames.B
5253
framesConfig: framesConfig,
5354
v3ioContext: v3ioContext,
5455
inactivityTimeout: 0,
56+
maxRecordsInfer: config.MaxRecordsInferSchema,
5557
}
5658
return &newBackend, nil
5759
}

backends/kv/inferschema.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,18 +50,17 @@ func (b *Backend) inferSchema(request *frames.ExecRequest) error {
5050
if val, ok := request.Proto.Args["key"]; ok {
5151
keyField = val.GetSval()
5252
}
53-
maxrec := 10
5453

5554
input := v3io.GetItemsInput{Path: table, Filter: "", AttributeNames: []string{"*"}}
5655
b.logger.DebugWith("GetItems for schema", "input", input)
57-
iter, err := v3ioutils.NewAsyncItemsCursor(container, &input, b.numWorkers, []string{}, b.logger, 0, []string{table}, "", "")
56+
iter, err := v3ioutils.NewAsyncItemsCursor(container, &input, b.numWorkers, []string{}, b.logger, b.maxRecordsInfer, []string{table}, "", "")
5857
if err != nil {
5958
return err
6059
}
6160

6261
var rowSet []map[string]interface{}
6362

64-
for rowNum := 0; rowNum < maxrec && iter.Next(); rowNum++ {
63+
for rowNum := 0; iter.Next(); rowNum++ {
6564
row := iter.GetFields()
6665
rowSet = append(rowSet, row)
6766
}

backends/kv/reader.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ package kv
2323
import (
2424
"fmt"
2525
"net/http"
26+
"strings"
2627

2728
"github.com/pkg/errors"
2829
"github.com/v3io/frames"
@@ -338,6 +339,16 @@ func init() {
338339
}
339340
}
340341

342+
func filterPartitions(dirs []v3io.CommonPrefix) []v3io.CommonPrefix {
343+
tmp := dirs[:0]
344+
for _, p := range dirs {
345+
if strings.Contains(p.Prefix, "=") {
346+
tmp = append(tmp, p)
347+
}
348+
}
349+
return tmp
350+
}
351+
341352
func (kv *Backend) getPartitions(path string, container v3io.Container) ([]string, error) {
342353
var partitions []string
343354
var done bool
@@ -352,6 +363,7 @@ func (kv *Backend) getPartitions(path string, container v3io.Container) ([]strin
352363
res.Release() // Releasing underlying fasthttp response
353364
}
354365
out := res.Output.(*v3io.GetContainerContentsOutput)
366+
out.CommonPrefixes = filterPartitions(out.CommonPrefixes)
355367
if len(out.CommonPrefixes) > 0 {
356368
for _, partition := range out.CommonPrefixes {
357369
parts, err := kv.getPartitions(partition.Prefix, container)

config.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ type BackendConfig struct {
142142
V3ioGoRequestChanLength int `json:"v3ioGoRequestChanLength"`
143143
MaxConnections int `json:"maxConnections"`
144144
DialTimeoutSeconds int `json:"dialTimeoutSeconds"`
145+
MaxRecordsInferSchema int `json:"maxRecordsInferSchema"`
145146

146147
// backend specific options
147148
Options map[string]interface{} `json:"options"`
@@ -232,4 +233,8 @@ func initBackendDefaults(cfg *BackendConfig, framesConfig *Config) {
232233
if cfg.V3ioGoRequestChanLength == 0 {
233234
cfg.V3ioGoRequestChanLength = cfg.V3ioGoWorkers * 256
234235
}
236+
237+
if cfg.MaxRecordsInferSchema == 0 {
238+
cfg.MaxRecordsInferSchema = 10
239+
}
235240
}

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ require (
1212
github.com/pkg/errors v0.8.1
1313
github.com/stretchr/testify v1.4.0
1414
github.com/v3io/v3io-go v0.1.9
15-
github.com/v3io/v3io-tsdb v0.11.3
15+
github.com/v3io/v3io-tsdb v0.11.4
1616
github.com/valyala/fasthttp v1.2.0
1717
github.com/xwb1989/sqlparser v0.0.0-20180606152119-120387863bf2
1818
golang.org/x/net v0.0.0-20190311183353-d8887717615a

go.sum

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ github.com/v3io/v3io-go v0.1.9/go.mod h1:5poBlcjZG5TiexRTYI44PE6tHzZz5Z60w+iS899
7171
github.com/v3io/v3io-tsdb v0.11.2 h1:knT+IwB+Bkd1aRPTIKltBnYrue1z+2EXmESJLkCexe8=
7272
github.com/v3io/v3io-tsdb v0.11.2/go.mod h1:l+WxedjLmjy/TThj2vhSW/OnpRw8C7dOntIXHmM/a7I=
7373
github.com/v3io/v3io-tsdb v0.11.3/go.mod h1:kp586KxTfROIGwb/nzNxwDbX2Wterxro+HbiZHmK548=
74+
github.com/v3io/v3io-tsdb v0.11.4/go.mod h1:kp586KxTfROIGwb/nzNxwDbX2Wterxro+HbiZHmK548=
7475
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
7576
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
7677
github.com/valyala/fasthttp v1.2.0 h1:dzZJf2IuMiclVjdw0kkT+f9u4YdrapbNyGAN47E/qnk=

0 commit comments

Comments
 (0)