github.com/matrixorigin/matrixone@v0.7.0/pkg/util/export/writer_factory.go (about) 1 // Copyright 2022 Matrix Origin 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package export 16 17 import ( 18 "bytes" 19 "context" 20 "time" 21 22 "github.com/matrixorigin/matrixone/pkg/common/mpool" 23 "github.com/matrixorigin/matrixone/pkg/fileservice" 24 "github.com/matrixorigin/matrixone/pkg/util/export/etl" 25 "github.com/matrixorigin/matrixone/pkg/util/export/table" 26 ) 27 28 func GetWriterFactory(fs fileservice.FileService, nodeUUID, nodeType string, ext string) (factory table.WriterFactory) { 29 30 var extension = table.GetExtension(ext) 31 var cfg = table.FilePathCfg{NodeUUID: nodeUUID, NodeType: nodeType, Extension: extension} 32 33 switch extension { 34 case table.CsvExtension: 35 factory = func(ctx context.Context, account string, tbl *table.Table, ts time.Time) table.RowWriter { 36 options := []etl.FSWriterOption{ 37 etl.WithFilePath(cfg.LogsFilePathFactory(account, tbl, ts)), 38 } 39 return etl.NewCSVWriter(ctx, bytes.NewBuffer(nil), etl.NewFSWriter(ctx, fs, options...)) 40 } 41 case table.TaeExtension: 42 mp, err := mpool.NewMPool("etl_fs_writer", 0, mpool.NoFixed) 43 if err != nil { 44 panic(err) 45 } 46 factory = func(ctx context.Context, account string, tbl *table.Table, ts time.Time) table.RowWriter { 47 filePath := cfg.LogsFilePathFactory(account, tbl, ts) 48 return etl.NewTAEWriter(ctx, tbl, mp, filePath, fs) 49 } 50 } 51 52 return factory 53 }