forked from pingcap/tidb
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: engine plugin and csv dashbase example. (pingcap#5)
* first commit 1. plugin add Engine 2. show engine && show table status is work right with plugin 3. csv reader example * code support OnReaderNext and OnReaderOpen * plugin support selection
- Loading branch information
Showing
20 changed files
with
471 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package executor | ||
|
||
import ( | ||
"fmt" | ||
"github.com/davecgh/go-spew/spew" | ||
"github.com/pingcap/parser/model" | ||
"github.com/pingcap/tidb/plugin" | ||
"github.com/pingcap/tidb/util/chunk" | ||
"golang.org/x/net/context" | ||
) | ||
|
||
type PluginScanExecutor struct { | ||
baseExecutor | ||
Table *model.TableInfo | ||
Columns []*model.ColumnInfo | ||
Plugin *plugin.Plugin | ||
pm *plugin.EngineManifest | ||
meta *plugin.ExecutorMeta | ||
} | ||
|
||
func (e *PluginScanExecutor) Open(ctx context.Context) error { | ||
e.pm = plugin.DeclareEngineManifest(e.Plugin.Manifest) | ||
e.meta = &plugin.ExecutorMeta{ | ||
Table: e.Table, | ||
} | ||
e.pm.OnReaderOpen(ctx, e.meta) | ||
return nil | ||
} | ||
|
||
func (e *PluginScanExecutor) Next(ctx context.Context, chk *chunk.Chunk) error { | ||
chk.Reset() | ||
err := e.pm.OnReaderNext(ctx, chk, e.meta) | ||
fmt.Println("pe next finished", spew.Sdump(err)) | ||
return err | ||
} | ||
|
||
func (e *PluginScanExecutor) Close() error { | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
// Copyright 2019 PingCAP, Inc. | ||
// | ||
// 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, | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package main | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"github.com/pingcap/tidb/plugin" | ||
"github.com/pingcap/tidb/util/chunk" | ||
) | ||
|
||
type ReadExecutor struct { | ||
pos int | ||
} | ||
|
||
var Files = make(map[string]*ReadExecutor) | ||
|
||
// Validate implements TiDB plugin's Validate SPI. | ||
func Validate(ctx context.Context, m *plugin.Manifest) error { | ||
fmt.Println("csv plugin validate") | ||
return nil | ||
} | ||
|
||
// OnInit implements TiDB plugin's OnInit SPI. | ||
func OnInit(ctx context.Context, manifest *plugin.Manifest) error { | ||
fmt.Println("csv init called") | ||
return nil | ||
} | ||
|
||
// OnShutdown implements TiDB plugin's OnShutdown SPI. | ||
func OnShutdown(ctx context.Context, manifest *plugin.Manifest) error { | ||
fmt.Println("csv shutdown called") | ||
return nil | ||
} | ||
|
||
func OnReaderOpen(ctx context.Context, meta *plugin.ExecutorMeta) { | ||
Files[meta.Table.Name.L] = &ReadExecutor{ | ||
pos: 0, | ||
} | ||
} | ||
|
||
func OnReaderNext(ctx context.Context, chk *chunk.Chunk, meta *plugin.ExecutorMeta) error { | ||
if _, ok := Files[meta.Table.Name.L]; !ok { | ||
fmt.Println("have some problem") | ||
return nil | ||
} | ||
e := Files[meta.Table.Name.L] | ||
if e.pos > 5 { | ||
return nil | ||
} | ||
chk.AppendInt64(0, int64(e.pos)) | ||
chk.AppendString(1, "233333") | ||
e.pos += 1 | ||
return nil | ||
} |
Oops, something went wrong.