Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

partition ranges, covering indexes, smarter iterators #1116

Merged
merged 13 commits into from
Dec 16, 2020
Prev Previous commit
Next Next commit
incensitive column name checks
  • Loading branch information
Brian Hendriks committed Dec 16, 2020
commit 12d95b8abe72a31b66664ac75a589b009b1b56eb
2 changes: 1 addition & 1 deletion go/libraries/doltcore/sqle/index_lookup.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ func (il *doltIndexLookup) indexCoversCols(cols []string) bool {
idxCols := il.idx.IndexSchema().GetPKCols()
covers := true
for _, colName := range cols {
if _, ok := idxCols.GetByName(colName); !ok {
if _, ok := idxCols.GetByNameCaseInsensitive(colName); !ok {
covers = false
break
}
Expand Down
4 changes: 2 additions & 2 deletions go/libraries/doltcore/sqle/index_row_iter.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,9 +211,9 @@ func NewCoveringIndexRowIterAdapter(ctx *sql.Context, idx DoltIndex, keyIter nom
cols := sch.GetAllCols().GetColumns()
tagToSqlColIdx := make(map[uint64]int)

resultColSet := set.NewStrSet(resultCols)
resultColSet := set.NewCaseInsensitiveStrSet(resultCols)
for i, col := range cols {
_, partOfIdxKey := idxCols.GetByName(col.Name)
_, partOfIdxKey := idxCols.GetByNameCaseInsensitive(col.Name)
if partOfIdxKey && resultColSet.Contains(col.Name) {
tagToSqlColIdx[col.Tag] = i
}
Expand Down
6 changes: 3 additions & 3 deletions go/libraries/utils/set/byteset.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@
package set

type ByteSet struct {
bytes map[byte]interface{}
bytes map[byte]bool
}

func NewByteSet(bytes []byte) *ByteSet {
s := &ByteSet{make(map[byte]interface{}, len(bytes))}
s := &ByteSet{make(map[byte]bool, len(bytes))}

for _, b := range bytes {
s.bytes[b] = emptyInstance
s.bytes[b] = true
}

return s
Expand Down
43 changes: 35 additions & 8 deletions go/libraries/utils/set/strset.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,52 +15,76 @@
package set

import (
"github.com/dolthub/dolt/go/libraries/utils/funcitr"
"sort"
"strings"
)

var emptyInstance = struct{}{}

// StrSet is a simple set implementation providing standard set operations for strings.
type StrSet struct {
items map[string]interface{}
items map[string]bool
caseSensitive bool
}

// NewStrSet creates a set from a list of strings
func NewStrSet(items []string) *StrSet {
s := &StrSet{make(map[string]interface{}, len(items))}
func newStrSet(items []string, caseSensitive bool) *StrSet {
s := &StrSet{make(map[string]bool, len(items)), caseSensitive}

if items != nil {
for _, item := range items {
s.items[item] = emptyInstance
s.items[item] = true
}
}

return s
}

func NewStrSet(items []string) *StrSet {
return newStrSet(items, true)
}

func NewCaseInsensitiveStrSet(items []string) *StrSet {
lwrStrs := funcitr.MapStrings(items, strings.ToLower)
return newStrSet(lwrStrs, false)
}

// Add adds new items to the set
func (s *StrSet) Add(items ...string) {
for _, item := range items {
s.items[item] = emptyInstance
if !s.caseSensitive {
item = strings.ToLower(item)
}
s.items[item] = true
}
}

// Remove removes existing items from the set
func (s *StrSet) Remove(items ...string) {
for _, item := range items {
if !s.caseSensitive {
item = strings.ToLower(item)
}

delete(s.items, item)
}
}

// Contains returns true if the item being checked is already in the set.
func (s *StrSet) Contains(item string) bool {
if !s.caseSensitive {
item = strings.ToLower(item)
}

_, present := s.items[item]
return present
}

// ContainsAll returns true if all the items being checked are already in the set.
func (s *StrSet) ContainsAll(items []string) bool {
if !s.caseSensitive {
items = funcitr.MapStrings(items, strings.ToLower)
}

for _, item := range items {
if _, present := s.items[item]; !present {
return false
Expand All @@ -71,6 +95,8 @@ func (s *StrSet) ContainsAll(items []string) bool {
}

func (s *StrSet) Equals(other *StrSet) bool {
// two string sets can be equal even if one is sensitive and the other is insensitive as long al the items are a
// case sensitive match.
ss := s.AsSlice()
os := other.AsSlice()
sort.Strings(ss)
Expand All @@ -93,7 +119,8 @@ func (s *StrSet) Size() int {
return len(s.items)
}

// AsSlice converts the set to a slice of strings
// AsSlice converts the set to a slice of strings. If this is an insensitive set the resulting slice will be lowercase
// regardless of the case that was used when adding the string to the set
func (s *StrSet) AsSlice() []string {
size := len(s.items)
sl := make([]string, size)
Expand Down
8 changes: 4 additions & 4 deletions go/libraries/utils/set/uint64set.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ package set
import "sort"

type Uint64Set struct {
uints map[uint64]interface{}
uints map[uint64]bool
}

func NewUint64Set(uints []uint64) *Uint64Set {
s := &Uint64Set{make(map[uint64]interface{}, len(uints))}
s := &Uint64Set{make(map[uint64]bool, len(uints))}

for _, b := range uints {
s.uints[b] = emptyInstance
s.uints[b] = true
}

return s
Expand All @@ -46,7 +46,7 @@ func (us *Uint64Set) ContainsAll(uints []uint64) bool {
}

func (us *Uint64Set) Add(i uint64) {
us.uints[i] = emptyInstance
us.uints[i] = true
}

func (us *Uint64Set) Remove(i uint64) {
Expand Down
7 changes: 7 additions & 0 deletions go/store/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@
// 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.
//
// This file incorporates work covered by the following copyright and
// permission notice:
//
// Copyright 2016 Attic Labs, Inc. All rights reserved.
// Licensed under the Apache License, version 2.0:
// http://www.apache.org/licenses/LICENSE-2.0

package store
bheni marked this conversation as resolved.
Show resolved Hide resolved

Expand Down