2 Star 2 Fork 1

cockroachdb/cockroach

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
values.go 2.64 KB
一键复制 编辑 原始数据 按行查看 历史
Matt Jibson 提交于 2017-08-03 14:40 . distsqlrun: export some types
// Copyright 2017 The Cockroach Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// 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.
package distsqlrun
import (
"sync"
"golang.org/x/net/context"
"github.com/cockroachdb/cockroach/pkg/sql/sqlbase"
"github.com/cockroachdb/cockroach/pkg/util/tracing"
)
// valuesProcessor is a processor that has no inputs and generates "pre-canned"
// rows.
type valuesProcessor struct {
processorBase
flowCtx *FlowCtx
columns []DatumInfo
data [][]byte
}
var _ Processor = &valuesProcessor{}
func newValuesProcessor(
flowCtx *FlowCtx, spec *ValuesCoreSpec, post *PostProcessSpec, output RowReceiver,
) (*valuesProcessor, error) {
v := &valuesProcessor{
flowCtx: flowCtx,
columns: spec.Columns,
data: spec.RawBytes,
}
types := make([]sqlbase.ColumnType, len(v.columns))
for i := range v.columns {
types[i] = v.columns[i].Type
}
if err := v.out.Init(post, types, &flowCtx.EvalCtx, output); err != nil {
return nil, err
}
return v, nil
}
// Run is part of the processor interface.
func (v *valuesProcessor) Run(ctx context.Context, wg *sync.WaitGroup) {
if wg != nil {
defer wg.Done()
}
ctx, span := processorSpan(ctx, "values")
defer tracing.FinishSpan(span)
// We reuse the code in StreamDecoder for decoding the raw data. We just need
// to manufacture ProducerMessages.
var sd StreamDecoder
m := ProducerMessage{
Typing: v.columns,
// Add a bogus header to apease the StreamDecoder, which wants to receive a
// header before any data.
Header: &ProducerHeader{}}
if err := sd.AddMessage(&m); err != nil {
DrainAndClose(ctx, v.out.output, err)
return
}
m = ProducerMessage{}
rowBuf := make(sqlbase.EncDatumRow, len(v.columns))
for len(v.data) > 0 {
// Push a chunk of data.
m.Data.RawBytes = v.data[0]
if err := sd.AddMessage(&m); err != nil {
DrainAndClose(ctx, v.out.output, err)
return
}
v.data = v.data[1:]
for {
row, meta, err := sd.GetRow(rowBuf)
if err != nil {
// If we got a decoding error, pass it along.
meta.Err = err
}
if row == nil && meta.Empty() {
break
}
if !emitHelper(ctx, &v.out, row, meta) {
return
}
}
}
sendTraceData(ctx, v.out.output)
v.out.Close()
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/mirrors_cockroachdb/cockroach.git
git@gitee.com:mirrors_cockroachdb/cockroach.git
mirrors_cockroachdb
cockroach
cockroach
v1.1.8

搜索帮助