Skip to content

Commit

Permalink
Merge #40495
Browse files Browse the repository at this point in the history
40495: exec: Bug fixes in vectorized casts r=rohany a=rohany

* Fixed a bug where the appropriate setters and getters were not being
generated for the casts.

* Fixed a bug where columns were not getting sliced, causing column
length mismatches.

Fixes #40461.

Release note: None

Co-authored-by: Rohan Yadav <rohany@alumni.cmu.edu>
  • Loading branch information
craig[bot] and rohany committed Sep 5, 2019
2 parents 8ad7b52 + 8bb4562 commit 0fa30e5
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 8 deletions.
33 changes: 25 additions & 8 deletions pkg/sql/exec/cast_tmpl.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,21 @@ func _ASSIGN_CAST(to, from interface{}) {
execerror.VectorizedInternalPanic("")
}

// This will be replaced with execgen.GET.
func _FROM_TYPE_GET(to, from interface{}) interface{} {
execerror.VectorizedInternalPanic("")
}

// This will be replaced with execgen.SET.
func _TO_TYPE_SET(to, from interface{}) {
execerror.VectorizedInternalPanic("")
}

// This will be replaced with execgen.SLICE.
func _FROM_TYPE_SLICE(col, i, j interface{}) interface{} {
execerror.VectorizedInternalPanic("")
}

// */}}

// Use execgen package to remove unused import warning.
Expand Down Expand Up @@ -127,39 +142,41 @@ func (c *castOp_FROMTYPE_TOTYPE) Next(ctx context.Context) coldata.Batch {
if vecNulls.NullAt(i) {
projNulls.SetNull(i)
} else {
v := execgen.GET(col, int(i))
v := _FROM_TYPE_GET(col, int(i))
var r _GOTYPE
_ASSIGN_CAST(r, v)
execgen.SET(projCol, int(i), r)
_TO_TYPE_SET(projCol, int(i), r)
}
}
} else {
col = _FROM_TYPE_SLICE(col, 0, int(n))
for execgen.RANGE(i, col) {
if vecNulls.NullAt(uint16(i)) {
projNulls.SetNull(uint16(i))
} else {
v := execgen.GET(col, i)
v := _FROM_TYPE_GET(col, int(i))
var r _GOTYPE
_ASSIGN_CAST(r, v)
execgen.SET(projCol, int(i), r)
_TO_TYPE_SET(projCol, int(i), r)
}
}
}
} else {
if sel := batch.Selection(); sel != nil {
sel = sel[:n]
for _, i := range sel {
v := execgen.GET(col, int(i))
v := _FROM_TYPE_GET(col, int(i))
var r _GOTYPE
_ASSIGN_CAST(r, v)
execgen.SET(projCol, int(i), r)
_TO_TYPE_SET(projCol, int(i), r)
}
} else {
col = _FROM_TYPE_SLICE(col, 0, int(n))
for execgen.RANGE(i, col) {
v := execgen.GET(col, i)
v := _FROM_TYPE_GET(col, int(i))
var r _GOTYPE
_ASSIGN_CAST(r, v)
execgen.SET(projCol, int(i), r)
_TO_TYPE_SET(projCol, int(i), r)
}
}
}
Expand Down
10 changes: 10 additions & 0 deletions pkg/sql/exec/execgen/cmd/execgen/cast_gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,18 @@ func genCastOperators(wr io.Writer) error {
s = strings.Replace(s, "_TOTYPE", "{{.ToTyp}}", -1)
s = strings.Replace(s, "_GOTYPE", "{{.ToGoTyp}}", -1)

// replace _FROM_TYPE_SLICE's with execgen.SLICE's of the correct type.
s = strings.Replace(s, "_FROM_TYPE_SLICE", "execgen.SLICE", -1)
s = replaceManipulationFuncs(".FromTyp", s)

// replace the _FROM_TYPE_GET's with execgen.GET's of the correct type.
s = strings.Replace(s, "_FROM_TYPE_GET", "execgen.GET", -1)
s = replaceManipulationFuncs(".FromTyp", s)

// replace the _TO_TYPE_GET's with execgen.SET's of the correct type
s = strings.Replace(s, "_TO_TYPE_SET", "execgen.SET", -1)
s = replaceManipulationFuncs(".ToTyp", s)

isCastFuncSet := func(ov castOverload) bool {
return ov.AssignFunc != nil
}
Expand Down

0 comments on commit 0fa30e5

Please sign in to comment.