diff --git a/app/server/datasource/mongodb/type_mapping.go b/app/server/datasource/mongodb/type_mapping.go index c12bd8a0..5a67e642 100644 --- a/app/server/datasource/mongodb/type_mapping.go +++ b/app/server/datasource/mongodb/type_mapping.go @@ -81,22 +81,19 @@ func bsonToYqlColumn(docs []bson.Raw, doSkipUnsupported bool, logger *zap.Logger } prevType, prevTypeExists := deducedTypes[key] - prevTypeString := prevType.String() t, err := typeMap(elem.Value(), logger) if err != nil { if errors.Is(err, errNull) { - if !prevTypeExists { - ambiguousFields[key] = struct{}{} - } + ambiguousFields[key] = struct{}{} continue } else if errors.Is(err, errEmptyArray) { if prevTypeExists && prevType.GetListType() == nil { deducedTypes[key] = common.MakePrimitiveType(Ydb.Type_UTF8) - logger.Debug(fmt.Sprintf("bsonToYqlColumn: keeping serialized %v. prev: %v curr: []", key, prevTypeString)) - } else if !prevTypeExists { + logger.Debug(fmt.Sprintf("bsonToYqlColumn: keeping serialized %v. prev: %v curr: []", key, prevType.String())) + } else { ambiguousFields[key] = struct{}{} } @@ -116,23 +113,21 @@ func bsonToYqlColumn(docs []bson.Raw, doSkipUnsupported bool, logger *zap.Logger tString := t.String() - if !prevTypeExists { + if prevTypeExists && prevType.String() != tString { + deducedTypes[key] = common.MakePrimitiveType(Ydb.Type_UTF8) + + logger.Debug(fmt.Sprintf("bsonToYqlColumn: keeping serialized %v. prev: %v curr: %v", key, prevType.String(), tString)) + } else { deducedTypes[key] = t logger.Debug(fmt.Sprintf("bsonToYqlColumn: new column %v %v", key, tString)) - } else if prevTypeString != tString { - deducedTypes[key] = common.MakePrimitiveType(Ydb.Type_UTF8) - - logger.Debug(fmt.Sprintf("bsonToYqlColumn: keeping serialized %v. curr: %v prev: %v", key, prevTypeString, tString)) } } } - if !doSkipUnsupported { - for field := range ambiguousFields { - if _, ok := deducedTypes[field]; !ok { - deducedTypes[field] = common.MakePrimitiveType(Ydb.Type_UTF8) - } + for field := range ambiguousFields { + if _, ok := deducedTypes[field]; !ok { + deducedTypes[field] = common.MakePrimitiveType(Ydb.Type_UTF8) } } @@ -140,7 +135,7 @@ func bsonToYqlColumn(docs []bson.Raw, doSkipUnsupported bool, logger *zap.Logger for columnName, deducedType := range deducedTypes { if columnName == idColumn { - columns = append(columns, &Ydb.Column{Name: columnName, Type: deducedTypes[columnName]}) + columns = append(columns, &Ydb.Column{Name: columnName, Type: deducedType}) } else { columns = append(columns, &Ydb.Column{Name: columnName, Type: common.MakeOptionalType(deducedType)}) }