Skip to content

Commit

Permalink
thank you, next()
Browse files Browse the repository at this point in the history
  • Loading branch information
ie-pham committed Jun 27, 2024
1 parent 65dab55 commit 4c2887b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
26 changes: 22 additions & 4 deletions pkg/parquetquery/iters.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,8 @@ func (t *RowNumber) Next(repetitionLevel, definitionLevel int) {
t[5] = 0
t[6] = 0
t[7] = 0
default:
panicWhenInvalidDefinitionLevel(definitionLevel)
}
case 1:
switch definitionLevel {
Expand Down Expand Up @@ -270,6 +272,8 @@ func (t *RowNumber) Next(repetitionLevel, definitionLevel int) {
t[5] = 0
t[6] = 0
t[7] = 0
default:
panicWhenInvalidDefinitionLevel(definitionLevel)
}
case 2:
switch definitionLevel {
Expand Down Expand Up @@ -324,6 +328,8 @@ func (t *RowNumber) Next(repetitionLevel, definitionLevel int) {
t[5] = 0
t[6] = 0
t[7] = 0
default:
panicWhenInvalidDefinitionLevel(definitionLevel)
}
case 3:
switch definitionLevel {
Expand Down Expand Up @@ -373,6 +379,8 @@ func (t *RowNumber) Next(repetitionLevel, definitionLevel int) {
t[5] = 0
t[6] = 0
t[7] = 0
default:
panicWhenInvalidDefinitionLevel(definitionLevel)
}
case 4:
switch definitionLevel {
Expand Down Expand Up @@ -418,6 +426,8 @@ func (t *RowNumber) Next(repetitionLevel, definitionLevel int) {
t[5] = 0
t[6] = 0
t[7] = 0
default:
panicWhenInvalidDefinitionLevel(definitionLevel)
}
case 5:
switch definitionLevel {
Expand Down Expand Up @@ -460,6 +470,8 @@ func (t *RowNumber) Next(repetitionLevel, definitionLevel int) {
case 7:
t[6] = 0
t[7] = 0
default:
panicWhenInvalidDefinitionLevel(definitionLevel)
}
case 6:
switch definitionLevel {
Expand Down Expand Up @@ -500,6 +512,8 @@ func (t *RowNumber) Next(repetitionLevel, definitionLevel int) {
t[7] = -1
case 7:
t[7] = 0
default:
panicWhenInvalidDefinitionLevel(definitionLevel)
}
case 7:
switch definitionLevel {
Expand Down Expand Up @@ -538,12 +552,11 @@ func (t *RowNumber) Next(repetitionLevel, definitionLevel int) {
t[7] = -1
case 6:
t[7] = -1
case 7:
default:
panicWhenInvalidDefinitionLevel(definitionLevel)
}
}
if definitionLevel > MaxDefinitionLevel || definitionLevel < 0 {
level.Error(log.Logger).Log("msg", "definition level out of bound: should be [0:7] but got %d", definitionLevel)
panic("invalid definition level")
}
}

// nextSlow is the original implementation of next. it is kept to test against
Expand Down Expand Up @@ -2190,6 +2203,11 @@ func (a *KeyValueGroupPredicate) KeepGroup(group *IteratorResult) bool {
return true
}

func panicWhenInvalidDefinitionLevel(definitionLevel int) {
level.Error(log.Logger).Log("msg", "definition level out of bound: should be [0:7] but got %d", definitionLevel)
panic("invalid definition level")
}

/*func printGroup(g *iteratorResult) {
fmt.Println("---group---")
for _, e := range g.entries {
Expand Down
4 changes: 2 additions & 2 deletions pkg/parquetquery/iters_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ func TestNext(t *testing.T) {
rn2 := RowNumber{0, 0, 0, 0, 0, 0, 0, 0}

for i := 0; i < 1000; i++ {
r := rand.Intn(MaxDefinitionLevel + 1)
d := rand.Intn(MaxDefinitionLevel + 1)
r := 7
d := 7

rn1.Next(r, d)
rn2.nextSlow(r, d)
Expand Down

0 comments on commit 4c2887b

Please sign in to comment.