github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/pkg/sql/execinfrapb/api.go (about)

     1  // Copyright 2018 The Cockroach Authors.
     2  //
     3  // Use of this software is governed by the Business Source License
     4  // included in the file licenses/BSL.txt.
     5  //
     6  // As of the Change Date specified in that file, in accordance with
     7  // the Business Source License, use of this software will be governed
     8  // by the Apache License, Version 2.0, included in the file
     9  // licenses/APL.txt.
    10  
    11  package execinfrapb
    12  
    13  import (
    14  	"github.com/cockroachdb/cockroach/pkg/sql/lex"
    15  	"github.com/cockroachdb/cockroach/pkg/sql/sem/tree"
    16  	"github.com/cockroachdb/cockroach/pkg/util/uuid"
    17  )
    18  
    19  // StreamID identifies a stream; it may be local to a flow or it may cross
    20  // machine boundaries. The identifier can only be used in the context of a
    21  // specific flow.
    22  type StreamID int
    23  
    24  // FlowID identifies a flow. It is most importantly used when setting up streams
    25  // between nodes.
    26  type FlowID struct {
    27  	uuid.UUID
    28  }
    29  
    30  // DistSQLVersion identifies DistSQL engine versions.
    31  type DistSQLVersion uint32
    32  
    33  // MakeEvalContext serializes some of the fields of a tree.EvalContext into a
    34  // distsqlpb.EvalContext proto.
    35  func MakeEvalContext(evalCtx *tree.EvalContext) EvalContext {
    36  	var be BytesEncodeFormat
    37  	switch evalCtx.SessionData.DataConversion.BytesEncodeFormat {
    38  	case lex.BytesEncodeHex:
    39  		be = BytesEncodeFormat_HEX
    40  	case lex.BytesEncodeEscape:
    41  		be = BytesEncodeFormat_ESCAPE
    42  	case lex.BytesEncodeBase64:
    43  		be = BytesEncodeFormat_BASE64
    44  	default:
    45  		panic("unknown format")
    46  	}
    47  	res := EvalContext{
    48  		StmtTimestampNanos:  evalCtx.StmtTimestamp.UnixNano(),
    49  		TxnTimestampNanos:   evalCtx.TxnTimestamp.UnixNano(),
    50  		Location:            evalCtx.GetLocation().String(),
    51  		Database:            evalCtx.SessionData.Database,
    52  		TemporarySchemaName: evalCtx.SessionData.SearchPath.GetTemporarySchemaName(),
    53  		User:                evalCtx.SessionData.User,
    54  		ApplicationName:     evalCtx.SessionData.ApplicationName,
    55  		BytesEncodeFormat:   be,
    56  		ExtraFloatDigits:    int32(evalCtx.SessionData.DataConversion.ExtraFloatDigits),
    57  		Vectorize:           int32(evalCtx.SessionData.VectorizeMode),
    58  	}
    59  
    60  	// Populate the search path. Make sure not to include the implicit pg_catalog,
    61  	// since the remote end already knows to add the implicit pg_catalog if
    62  	// necessary, and sending it over would make the remote end think that
    63  	// pg_catalog was explicitly included by the user.
    64  	res.SearchPath = evalCtx.SessionData.SearchPath.GetPathArray()
    65  
    66  	// Populate the sequences state.
    67  	latestValues, lastIncremented := evalCtx.SessionData.SequenceState.Export()
    68  	if len(latestValues) > 0 {
    69  		res.SeqState.LastSeqIncremented = &lastIncremented
    70  		for seqID, latestVal := range latestValues {
    71  			res.SeqState.Seqs = append(res.SeqState.Seqs, &SequenceState_Seq{SeqID: seqID, LatestVal: latestVal})
    72  		}
    73  	}
    74  	return res
    75  }