Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix the bug of importing fixed_string or int8/16/32 type data #293

Merged
merged 1 commit into from
Sep 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 17 additions & 17 deletions app/stores/import.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,21 @@ import service from '@app/config/service';
import { IBasicConfig, IEdgeConfig, ITaskItem, IVerticesConfig } from '@app/interfaces/import';
import { configToJson } from '@app/utils/import';
import { getRootStore } from '.';

const handlePropertyMap = (item, defaultValueFields) => {
let type = item.Type;
if(item.Type.startsWith('fixed_string')) {
type = 'string';
} else if (item.Type.startsWith('int')) {
type = 'int';
}
return {
name: item.Field,
type,
isDefault: defaultValueFields.includes(item.Field),
mapping: null,
};
}
export class ImportStore {
taskList: ITaskItem[] = [];
verticesConfig: IVerticesConfig[] = [];
Expand Down Expand Up @@ -144,14 +159,7 @@ export class ImportStore {
});
}
if (code === 0) {
const props = data.tables.map(attr => {
return {
name: attr.Field,
type: attr.Type === 'int64' ? 'int' : attr.Type, // HACK: exec return int64 but importer only use int
isDefault: defaultValueFields.includes(attr.Field),
mapping: null,
};
});
const props = data.tables.map(attr => handlePropertyMap(attr, defaultValueFields));
runInAction(() => {
this.verticesConfig[configIndex].tags[tagIndex] = {
name: tag,
Expand Down Expand Up @@ -192,15 +200,7 @@ export class ImportStore {
});
}
if (code === 0) {
const props = data.tables.map(item => {
return {
name: item.Field,
type: item.Type === 'int64' ? 'int' : item.Type,
isDefault: defaultValueFields.includes(item.Field),
mapping: null,
};
});

const props = data.tables.map(item => handlePropertyMap(item, defaultValueFields));
runInAction(() => {
this.edgesConfig[index].type = edgeType;
this.edgesConfig[index].props = [
Expand Down
30 changes: 15 additions & 15 deletions server/api/studio/internal/service/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,31 +73,31 @@ func (i *importService) CreateImportTask(req *types.CreateImportTaskRequest) (*t
conf := importconfig.YAMLConfig{}
err = json.Unmarshal(jsons, &conf)
if err != nil {
return nil, err
return nil, ecode.WithErrorMessage(ecode.ErrInternalServer, err)
}

if err = validClientParams(&conf); err != nil {
err = importererrors.Wrap(importererrors.InvalidConfigPathOrFormat, err)
zap.L().Warn("client params is wrong", zap.Error(err))
return nil, err
return nil, ecode.WithErrorMessage(ecode.ErrInternalServer, err)
}

taskDir, err := importer.GetNewTaskDir(i.svcCtx.Config.File.TasksDir)
if err != nil {
return nil, err
return nil, ecode.WithErrorMessage(ecode.ErrInternalServer, err)
}
logPath := filepath.Join(taskDir, importLogName)
conf.LogPath = &logPath

// create config file
if err := importer.CreateConfigFile(i.svcCtx.Config.File.UploadDir, taskDir, conf); err != nil {
return nil, err
return nil, ecode.WithErrorMessage(ecode.ErrInternalServer, err)
}

// create err dir
taskErrDir := filepath.Join(taskDir, "err")
if err = utils.CreateDir(taskErrDir); err != nil {
return nil, err
return nil, ecode.WithErrorMessage(ecode.ErrInternalServer, err)
}

// import
Expand All @@ -108,7 +108,7 @@ func (i *importService) CreateImportTask(req *types.CreateImportTaskRequest) (*t
task, taskID, err := importer.GetTaskMgr().NewTask(nebulaAddress, user, name, space)
if err != nil {
zap.L().Warn("init task fail", zap.Error(err))
return nil, err
return nil, ecode.WithErrorMessage(ecode.ErrInternalServer, err)
}
if err = importer.Import(taskID, &conf); err != nil {
// task err: import task not start err
Expand All @@ -118,21 +118,21 @@ func (i *importService) CreateImportTask(req *types.CreateImportTaskRequest) (*t
zap.L().Warn("finish task fail", zap.Error(err1))
}
zap.L().Error(fmt.Sprintf("Failed to start a import task: `%s`, task result: `%v`", taskID, err))
return nil, err
return nil, ecode.WithErrorMessage(ecode.ErrInternalServer, err)
}

// write taskId to file
muTaskId.Lock()
taskIDBytes, err := ioutil.ReadFile(i.svcCtx.Config.File.TaskIdPath)
if err != nil {
zap.L().Warn("read taskId file error", zap.Error(err))
return nil, err
return nil, ecode.WithErrorMessage(ecode.ErrInternalServer, err)
}
taskIdJSON := make(map[string]bool)
if len(taskIDBytes) != 0 {
if err := json.Unmarshal(taskIDBytes, &taskIdJSON); err != nil {
zap.L().Warn("read taskId file error", zap.Error(err))
return nil, err
return nil, ecode.WithErrorMessage(ecode.ErrInternalServer, err)
}
}
taskIdJSON[taskID] = true
Expand Down Expand Up @@ -228,7 +228,7 @@ func (i *importService) GetImportTaskLogNames(req *types.GetImportTaskLogNamesRe
errLogDir := filepath.Join(i.svcCtx.Config.File.TasksDir, id, "err")
fileInfos, err := ioutil.ReadDir(errLogDir)
if err != nil {
return nil, err
return nil, ecode.WithErrorMessage(ecode.ErrInternalServer, err)
}

data := &types.GetImportTaskLogNamesData{
Expand All @@ -251,22 +251,22 @@ func (i *importService) GetManyImportTaskLog(req *types.GetManyImportTaskLogRequ
}
lines, err := readFileLines(path, req.Offset, req.Limit)
if err != nil {
return nil, err
return nil, ecode.WithErrorMessage(ecode.ErrInternalServer, err)
}

muTaskId.RLock()
taskIdBytes, err := ioutil.ReadFile(i.svcCtx.Config.File.TaskIdPath)
muTaskId.RUnlock()
if err != nil {
zap.L().Warn("read taskId file error", zap.Error(err))
return nil, err
return nil, ecode.WithErrorMessage(ecode.ErrInternalServer, err)
}
taskIdJSON := make(map[string]bool)
if len(taskIdBytes) != 0 {
err = json.Unmarshal(taskIdBytes, &taskIdJSON)
if err != nil {
zap.L().Warn("parse taskId file error", zap.Error(err))
return nil, err
return nil, ecode.WithErrorMessage(ecode.ErrInternalServer, err)
}
}
data := &types.GetManyImportTaskLogData{
Expand All @@ -276,7 +276,7 @@ func (i *importService) GetManyImportTaskLog(req *types.GetManyImportTaskLogRequ
return data, nil
}
if len(lines) == 0 {
return data, errors.New("no task")
return data, ecode.WithErrorMessage(ecode.ErrInternalServer, errors.New("no task"))
}

return data, nil
Expand Down Expand Up @@ -307,7 +307,7 @@ func readFileLines(path string, offset int64, limit int64) ([]string, error) {
file, err := os.Open(path)
if err != nil {
zap.L().Warn("open file error", zap.Error(err))
return nil, err
return nil, ecode.WithErrorMessage(ecode.ErrInternalServer, err)
}
defer file.Close()
scanner := bufio.NewScanner(file)
Expand Down