mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-08-03 06:17:29 +08:00
Implement InsertDataset and InsertMetadata in GO (#13883)
### What problem does this PR solve? Implement InsertDataset and InsertMetadata in GO new internal cli for go: INSERT DATASET FROM FILE "file_name" INSERT METADATA FROM FILE "file_name" ### Type of change - [x] Refactoring
This commit is contained in:
@@ -32,6 +32,21 @@ func (p *Parser) parseLoginUser() (*Command, error) {
|
||||
cmd.Params["email"] = email
|
||||
|
||||
p.nextToken()
|
||||
// Optional: WITH PASSWORD 'password'
|
||||
if p.curToken.Type == TokenWith {
|
||||
p.nextToken()
|
||||
if p.curToken.Type != TokenPassword {
|
||||
return nil, fmt.Errorf("expected PASSWORD after WITH")
|
||||
}
|
||||
p.nextToken()
|
||||
password, err := p.parseQuotedString()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
cmd.Params["password"] = password
|
||||
p.nextToken()
|
||||
}
|
||||
|
||||
// Semicolon is optional for UNSET TOKEN
|
||||
if p.curToken.Type == TokenSemicolon {
|
||||
p.nextToken()
|
||||
@@ -1531,6 +1546,88 @@ func (p *Parser) parseImportCommand() (*Command, error) {
|
||||
return cmd, nil
|
||||
}
|
||||
|
||||
// parseInsertCommand parses INSERT command and dispatches to specific handler
|
||||
func (p *Parser) parseInsertCommand() (*Command, error) {
|
||||
p.nextToken() // consume INSERT
|
||||
|
||||
// Expect DATASET or METADATA
|
||||
if p.curToken.Type == TokenDataset {
|
||||
return p.parseInsertDatasetFromFile()
|
||||
}
|
||||
if p.curToken.Type == TokenMetadata {
|
||||
return p.parseInsertMetadataFromFile()
|
||||
}
|
||||
return nil, fmt.Errorf("expected DATASET or METADATA after INSERT, got %s", p.curToken.Value)
|
||||
}
|
||||
|
||||
// Internal CLI for GO
|
||||
// parseInsertDatasetFromFile parses: INSERT DATASET FROM FILE "file_path"
|
||||
func (p *Parser) parseInsertDatasetFromFile() (*Command, error) {
|
||||
p.nextToken() // consume DATASET
|
||||
|
||||
// Expect FROM
|
||||
if p.curToken.Type != TokenFrom {
|
||||
return nil, fmt.Errorf("expected FROM, got %s", p.curToken.Value)
|
||||
}
|
||||
p.nextToken()
|
||||
|
||||
// Expect FILE
|
||||
if p.curToken.Type != TokenFile {
|
||||
return nil, fmt.Errorf("expected FILE, got %s", p.curToken.Value)
|
||||
}
|
||||
p.nextToken()
|
||||
|
||||
// Get file path (quoted string)
|
||||
filePath, err := p.parseQuotedString()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
cmd := NewCommand("insert_dataset_from_file")
|
||||
cmd.Params["file_path"] = filePath
|
||||
|
||||
p.nextToken()
|
||||
// Semicolon is optional
|
||||
if p.curToken.Type == TokenSemicolon {
|
||||
p.nextToken()
|
||||
}
|
||||
return cmd, nil
|
||||
}
|
||||
|
||||
// Internal CLI for GO
|
||||
// parseInsertMetadataFromFile parses: INSERT INTO METADATA FROM FILE "file_path"
|
||||
func (p *Parser) parseInsertMetadataFromFile() (*Command, error) {
|
||||
p.nextToken() // consume METADATA
|
||||
|
||||
// Expect FROM
|
||||
if p.curToken.Type != TokenFrom {
|
||||
return nil, fmt.Errorf("expected FROM, got %s", p.curToken.Value)
|
||||
}
|
||||
p.nextToken()
|
||||
|
||||
// Expect FILE
|
||||
if p.curToken.Type != TokenFile {
|
||||
return nil, fmt.Errorf("expected FILE, got %s", p.curToken.Value)
|
||||
}
|
||||
p.nextToken()
|
||||
|
||||
// Get file path (quoted string)
|
||||
filePath, err := p.parseQuotedString()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
cmd := NewCommand("insert_metadata_from_file")
|
||||
cmd.Params["file_path"] = filePath
|
||||
|
||||
p.nextToken()
|
||||
// Semicolon is optional
|
||||
if p.curToken.Type == TokenSemicolon {
|
||||
p.nextToken()
|
||||
}
|
||||
return cmd, nil
|
||||
}
|
||||
|
||||
func (p *Parser) parseSearchCommand() (*Command, error) {
|
||||
p.nextToken() // consume SEARCH
|
||||
question, err := p.parseQuotedString()
|
||||
@@ -1687,6 +1784,8 @@ func (p *Parser) parseUserStatement() (*Command, error) {
|
||||
return p.parseParseCommand()
|
||||
case TokenImport:
|
||||
return p.parseImportCommand()
|
||||
case TokenInsert:
|
||||
return p.parseInsertCommand()
|
||||
case TokenSearch:
|
||||
return p.parseSearchCommand()
|
||||
default:
|
||||
|
||||
Reference in New Issue
Block a user