Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
58201: row: fix import default expr sequence logic r=pbardea a=adityamaru

Previously, we would attempt to create a sequence annotation when
creating a NewDatumConverter. This code path is shared by various
formats of IMPORT, and we only really want to create this annotation
when coming from a subset of them (CSV only as of today). The annotation
involves resolving sequence descs, and depending on whether we are
coming from an IMPORT PGDUMP or an IMPORT CSV we use different
resolvers to do this. Therefore, calling this method with the wrong
resolver can result in a "descriptor not found" error.

Informs: cockroachdb#58147

Release note: None

Co-authored-by: Aditya Maru <adityamaru@gmail.com>
  • Loading branch information
craig[bot] and adityamaru committed Dec 23, 2020
2 parents d07c9b4 + 2c31689 commit d2740b1
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions pkg/sql/row/row_converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -357,19 +357,25 @@ func NewDatumRowConverter(
c.Datums = make([]tree.Datum, len(targetColDescriptors), len(cols))
c.defaultCache = make([]tree.TypedExpr, len(cols))

annot := make(tree.Annotations, 1)
var cellInfoAnnot CellInfoAnnotation
// Currently, this is only true for an IMPORT INTO CSV.
if seqChunkProvider != nil {
seqNameToMetadata, err := c.getSequenceAnnotation(evalCtx, c.cols)
if err != nil {
return nil, err
}
cellInfoAnnot.seqNameToMetadata = seqNameToMetadata
cellInfoAnnot.seqChunkProvider = seqChunkProvider
}
cellInfoAnnot.uniqueRowIDInstance = 0
annot.Set(cellInfoAddr, &cellInfoAnnot)
c.EvalCtx.Annotations = &annot

// Check for a hidden column. This should be the unique_rowid PK if present.
// In addition, check for non-targeted columns with non-null DEFAULT expressions.
// If the DEFAULT expression is immutable, we can store it in the cache so that it
// doesn't have to be reevaluated for every row.
annot := make(tree.Annotations, 1)
var seqNameToMetadata map[string]*SequenceMetadata
seqNameToMetadata, err = c.getSequenceAnnotation(evalCtx, c.cols)
if err != nil {
return nil, err
}
annot.Set(cellInfoAddr, &CellInfoAnnotation{uniqueRowIDInstance: 0,
seqNameToMetadata: seqNameToMetadata, seqChunkProvider: seqChunkProvider})
c.EvalCtx.Annotations = &annot
for i := range cols {
col := &cols[i]
if col.DefaultExpr != nil {
Expand Down

0 comments on commit d2740b1

Please sign in to comment.