Repository: influxdata/influxdb
File: tsdb/field_validator.go (Go)

Code before:
			if pointSize > MaxFieldValueLength && iter.Type() == models.String {
				if sz := len(iter.StringValue()); sz > MaxFieldValueLength {
					return fieldsToCreate, &PartialWriteError{
						Reason: fmt.Sprintf(
							"input field %q on measurement %q is too long, %d > %d",
							iter.FieldKey(), point.Name(), sz, MaxFieldValueLength),
						Dropped: 1,
					}
				}
			}
		}

		fieldKey := iter.FieldKey()
		// Skip fields name "time", they are illegal.
		if bytes.Equal(fieldKey, timeBytes) {
			continue
		}

		dataType := dataTypeFromModelsFieldType(iter.Type())
		if dataType == influxql.Unknown {
			continue
		}

		// If the field is not present, remember to create it.
		fieldName := string(fieldKey)
		f, created, err := mf.CreateFieldIfNotExists(fieldName, dataType)
		if errors.Is(err, ErrFieldTypeConflict) {
			return fieldsToCreate, &PartialWriteError{
				Reason: fmt.Sprintf(
					"%s: input field %q on measurement %q is type %s, already exists as type %s",
					err, fieldName, point.Name(), dataType, f.Type),
				Dropped: 1,
			}
		} else if created {
			fieldsToCreate = append(fieldsToCreate, &FieldCreate{point.Name(), f})
		}
	}
	return fieldsToCreate, nil
}

// dataTypeFromModelsFieldType returns the influxql.DataType that corresponds to the
// passed in field type. If there is no good match, it returns Unknown.
func dataTypeFromModelsFieldType(fieldType models.FieldType) influxql.DataType {
	switch fieldType {
	case models.Float:
		return influxql.Float
	case models.Integer:
		return influxql.Integer
	case models.Unsigned:
		return influxql.Unsigned
	case models.Boolean:

Review comment (suggestion):
do you want to handle the case of `err != nil` (aka there is an error) but not a `ErrFieldTypeConflict`? 

`mf.CreateFieldIfNotExists` returns an `error` at the moment but I note that it is always a `ErrFieldTypeConflict` in the current code. 

It's not clear to me what should happen if `mf.CreateFieldIfNotExists` gains another error return type in the future (guess it would depend on that new error's meaning!)

Code after:
			if pointSize > MaxFieldValueLength && iter.Type() == models.String {
				if sz := len(iter.StringValue()); sz > MaxFieldValueLength {
					return fieldsToCreate, &PartialWriteError{
						Reason: fmt.Sprintf(
							"input field %q on measurement %q is too long, %d > %d",
							iter.FieldKey(), point.Name(), sz, MaxFieldValueLength),
						Dropped: 1,
					}
				}
			}
		}

		fieldKey := iter.FieldKey()
		// Skip fields name "time", they are illegal.
		if bytes.Equal(fieldKey, timeBytes) {
			continue
		}

		dataType := dataTypeFromModelsFieldType(iter.Type())
		if dataType == influxql.Unknown {
			continue
		}

		fieldName := string(fieldKey)
		f, created, err := mf.CreateFieldIfNotExists(fieldName, dataType)
		if errors.Is(err, ErrFieldTypeConflict) {
			return fieldsToCreate, &PartialWriteError{
				Reason: fmt.Sprintf(
					"%s: input field %q on measurement %q is type %s, already exists as type %s",
					err, fieldName, point.Name(), dataType, f.Type),
				Dropped: 1,
			}
		} else if err != nil {
			return fieldsToCreate, &PartialWriteError{
				Reason: fmt.Sprintf(
					"error adding field %q to measurement %q: %s",
					fieldName, point.Name(), err),
				Dropped: 1,
			}
		} else if created {
			fieldsToCreate = append(fieldsToCreate, &FieldCreate{point.Name(), f})
		}
	}
	return fieldsToCreate, nil
}

// dataTypeFromModelsFieldType returns the influxql.DataType that corresponds to the
// passed in field type. If there is no good match, it returns Unknown.
func dataTypeFromModelsFieldType(fieldType models.FieldType) influxql.DataType {
	switch fieldType {
	case models.Float: