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

Commit 17ad0d7

Browse files
committed
Array mapping parser improvements
1 parent 4ceb984 commit 17ad0d7

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

platform/ingest/parser.go

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,22 @@ func columnsToString(columnsFromJson []CreateTableEntry,
5656
columnMetadata.Values[comment_metadata.ElasticFieldName] = propertyName
5757
comment := columnMetadata.Marshall()
5858

59-
if columnFromSchema, found := columnsFromSchema[schema.FieldName(columnFromJson.ClickHouseColumnName)]; found && !strings.Contains(columnFromJson.ClickHouseType, "Array") {
60-
// Schema takes precedence over JSON (except for Arrays which are not currently handled)
61-
result.WriteString(fmt.Sprintf("\"%s\" %s '%s'", columnFromSchema.ClickHouseColumnName, columnFromSchema.ClickHouseType+" COMMENT ", comment))
59+
if columnFromSchema, found := columnsFromSchema[schema.FieldName(columnFromJson.ClickHouseColumnName)]; found {
60+
// Schema takes precedence over inferred type from JSON
61+
if strings.Contains(columnFromJson.ClickHouseType, "Array") {
62+
// The schema (e.g. PUT /:index/_mapping) doesn't contain information about whether a field is an array or not.
63+
// Therefore, we have to combine the information from the schema and the JSON in such case.
64+
// For example: in the mapping we have a field "products.name" with type "keyword" (String)
65+
// and in the JSON "products.name" is an array of strings (Array(String)).
66+
67+
if strings.Count(columnFromJson.ClickHouseType, "Array") > 1 {
68+
logger.Warn().Msgf("Column '%s' has type '%s' - an array nested multiple times. Such case might not be handled correctly.", columnFromJson.ClickHouseColumnName, columnFromJson.ClickHouseType)
69+
}
70+
71+
result.WriteString(fmt.Sprintf("\"%s\" Array(%s) COMMENT '%s'", columnFromSchema.ClickHouseColumnName, columnFromSchema.ClickHouseType, comment))
72+
} else {
73+
result.WriteString(fmt.Sprintf("\"%s\" %s '%s'", columnFromSchema.ClickHouseColumnName, columnFromSchema.ClickHouseType+" COMMENT ", comment))
74+
}
6275
} else {
6376
result.WriteString(fmt.Sprintf("\"%s\" %s '%s'", columnFromJson.ClickHouseColumnName, columnFromJson.ClickHouseType+" COMMENT ", comment))
6477
}

0 commit comments

Comments
 (0)