Skip to content
This repository was archived by the owner on Nov 7, 2025. It is now read-only.

Commit 0770fb4

Browse files
committed
WIP
1 parent 53b661a commit 0770fb4

File tree

1 file changed

+28
-30
lines changed

1 file changed

+28
-30
lines changed

platform/ingest/processor.go

Lines changed: 28 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -415,32 +415,29 @@ type NonSchemaField struct {
415415
Type string // inferred from incoming json
416416
}
417417

418-
func convertNonSchemaFieldsToString(nonSchemaFields []NonSchemaField) string {
419-
if len(nonSchemaFields) <= 0 {
420-
return ""
421-
}
422-
attributesColumns := []string{chLib.AttributesValuesColumn, chLib.AttributesMetadataColumn}
423-
var nonSchemaStr string
424-
for columnIndex, column := range attributesColumns {
425-
var value string
426-
if columnIndex > 0 {
427-
nonSchemaStr += ","
418+
func convertNonSchemaFieldsToMap(nonSchemaFields []NonSchemaField) map[string]any {
419+
values := make(map[string]string)
420+
typesMap := make(map[string]string)
421+
422+
for _, f := range nonSchemaFields {
423+
if f.Value != "" {
424+
values[f.Key] = f.Value
428425
}
429-
nonSchemaStr += "\"" + column + "\":{"
430-
for i := 0; i < len(nonSchemaFields); i++ {
431-
if columnIndex > 0 {
432-
value = nonSchemaFields[i].Type
433-
} else {
434-
value = nonSchemaFields[i].Value
435-
}
436-
if i > 0 {
437-
nonSchemaStr += ","
438-
}
439-
nonSchemaStr += fmt.Sprintf("\"%s\":\"%s\"", nonSchemaFields[i].Key, value)
426+
if f.Type != "" {
427+
typesMap[f.Key] = f.Type
440428
}
441-
nonSchemaStr = nonSchemaStr + "}"
442429
}
443-
return nonSchemaStr
430+
431+
result := make(map[string]any)
432+
433+
if len(values) > 0 {
434+
result[chLib.AttributesValuesColumn] = values
435+
}
436+
if len(typesMap) > 0 {
437+
result[chLib.AttributesMetadataColumn] = typesMap
438+
}
439+
440+
return result
444441
}
445442

446443
func generateNonSchemaFields(attrsMap map[string][]interface{}) ([]NonSchemaField, error) {
@@ -588,16 +585,17 @@ func (ip *IngestProcessor) GenerateIngestContent(table *chLib.Table,
588585
}
589586

590587
func generateInsertJson(nonSchemaFields []NonSchemaField, onlySchemaFields types.JSON) (string, error) {
591-
nonSchemaStr := convertNonSchemaFieldsToString(nonSchemaFields)
592-
schemaFieldsJson, err := json.Marshal(onlySchemaFields)
588+
result := convertNonSchemaFieldsToMap(nonSchemaFields)
589+
590+
for k, v := range onlySchemaFields {
591+
result[k] = v
592+
}
593+
594+
jsonBytes, err := json.Marshal(result)
593595
if err != nil {
594596
return "", err
595597
}
596-
comma := ""
597-
if nonSchemaStr != "" && len(schemaFieldsJson) > 2 {
598-
comma = ","
599-
}
600-
return fmt.Sprintf("{%s%s%s", nonSchemaStr, comma, schemaFieldsJson[1:]), err
598+
return string(jsonBytes), nil
601599
}
602600

603601
func generateSqlStatements(createTableCmd string, alterCmd []string, insert string) []string {

0 commit comments

Comments
 (0)