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

WIP - Buffered Ingest #1148

Closed
wants to merge 2 commits into from
Closed
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
18 changes: 15 additions & 3 deletions quesma/ingest/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -548,11 +548,14 @@ func generateInsertJson(nonSchemaFields []NonSchemaField, onlySchemaFields types
return fmt.Sprintf("{%s%s%s", nonSchemaStr, comma, schemaFieldsJson[1:]), err
}

func generateSqlStatements(createTableCmd string, alterCmd []string, insert string) []string {
func generateSqlStatements(createTableCmd string, creatBufferCmd string, alterCmd []string, insert string) []string {
var statements []string
if createTableCmd != "" {
statements = append(statements, createTableCmd)
}
if creatBufferCmd != "" {
statements = append(statements, creatBufferCmd)
}
statements = append(statements, alterCmd...)
statements = append(statements, insert)
return statements
Expand Down Expand Up @@ -622,6 +625,9 @@ func (ip *IngestProcessor) processInsertQuery(ctx context.Context,
table := ip.FindTable(tableName)
var tableConfig *chLib.ChTableConfig
var createTableCmd string
bufferName := fmt.Sprintf("quesma_buffer_%s", tableName)
var createBufferCmd string

if table == nil {
tableConfig = NewOnlySchemaFieldsCHConfig()
columnsFromJson := JsonToColumns(transformedJsons[0], tableConfig)
Expand All @@ -645,10 +651,16 @@ func (ip *IngestProcessor) processInsertQuery(ctx context.Context,
logger.ErrorWithCtx(ctx).Msgf("error createTableObjectAndAttributes, can't create table: %v", err)
return nil, err
}

createBufferCmd = fmt.Sprintf(`CREATE TABLE %s AS %s ENGINE = Buffer(currentDatabase(), %s, 1, 10, 100, 10000, 1000000, 10000000, 100000000)`, bufferName, tableName, tableName)

// Set pointer to table after creating it
table = ip.FindTable(tableName)
} else if !table.Created {
createTableCmd = table.CreateTableString()

createBufferCmd = fmt.Sprintf(`CREATE TABLE %s AS %s ENGINE = Buffer(currentDatabase(), %s, 1, 10, 100, 10000, 1000000, 10000000, 100000000)`, bufferName, tableName, tableName)

}
if table == nil {
return nil, fmt.Errorf("table %s not found", tableName)
Expand Down Expand Up @@ -681,9 +693,9 @@ func (ip *IngestProcessor) processInsertQuery(ctx context.Context,
}

insertValues := strings.Join(jsonsReadyForInsertion, ", ")
insert := fmt.Sprintf("INSERT INTO \"%s\" FORMAT JSONEachRow %s", table.Name, insertValues)
insert := fmt.Sprintf("INSERT INTO \"%s\" FORMAT JSONEachRow %s", bufferName, insertValues)

return generateSqlStatements(createTableCmd, alterCmd, insert), nil
return generateSqlStatements(createTableCmd, createBufferCmd, alterCmd, insert), nil
}

func (lm *IngestProcessor) Ingest(ctx context.Context, indexName string, jsonData []types.JSON) error {
Expand Down
2 changes: 1 addition & 1 deletion quesma/ingest/processor2.go
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ func (ip *IngestProcessor2) processInsertQuery(ctx context.Context,
insertValues := strings.Join(jsonsReadyForInsertion, ", ")
insert := fmt.Sprintf("INSERT INTO \"%s\" FORMAT JSONEachRow %s", table.Name, insertValues)

return generateSqlStatements(createTableCmd, alterCmd, insert), nil
return generateSqlStatements(createTableCmd, "", alterCmd, insert), nil
}

func (lm *IngestProcessor2) Ingest(ctx context.Context, tableName string, jsonData []types.JSON) error {
Expand Down
2 changes: 1 addition & 1 deletion quesma/quesma/config/config_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -779,7 +779,7 @@ func (c *QuesmaNewConfiguration) TranslateToLegacyConfig() QuesmaConfiguration {
}

conf.EnableIngest = true
conf.IngestStatistics = true
conf.IngestStatistics = c.IngestStatistics

for indexName, indexConfig := range ingestProcessor.Config.IndexConfig {
processedConfig, found := conf.IndexConfig[indexName]
Expand Down
Loading