From 41a231b532a0113e295f900740cb9e54565569da Mon Sep 17 00:00:00 2001 From: Nikolai Amelichev <1126790+nvamelichev@users.noreply.github.com> Date: Thu, 29 Feb 2024 19:03:15 +0100 Subject: [PATCH] #20: Add warning about implicitly using legacy YOJ type mapping for YDB Issue: #20 --- .../yoj/repository/ydb/yql/YqlPrimitiveType.java | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/repository-ydb-v2/src/main/java/tech/ydb/yoj/repository/ydb/yql/YqlPrimitiveType.java b/repository-ydb-v2/src/main/java/tech/ydb/yoj/repository/ydb/yql/YqlPrimitiveType.java index 09040b32..4c17f99e 100644 --- a/repository-ydb-v2/src/main/java/tech/ydb/yoj/repository/ydb/yql/YqlPrimitiveType.java +++ b/repository-ydb-v2/src/main/java/tech/ydb/yoj/repository/ydb/yql/YqlPrimitiveType.java @@ -8,6 +8,8 @@ import lombok.NonNull; import lombok.Value; import lombok.With; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import tech.ydb.proto.ValueProtos; import tech.ydb.proto.ValueProtos.Type.PrimitiveTypeId; import tech.ydb.proto.ValueProtos.Value.ValueCase; @@ -50,6 +52,10 @@ @Value @AllArgsConstructor(access = PRIVATE) public class YqlPrimitiveType implements YqlType { + private static final Logger log = LoggerFactory.getLogger(YqlPrimitiveType.class); + + private static volatile boolean typeMappingExplicitlySet = false; + // Only table column data types. See https://ydb.tech/en/docs/yql/reference/types/ private static final Map YQL_TYPE_NAMES = Map.ofEntries( Map.entry(PrimitiveTypeId.BOOL, "Bool"), @@ -354,14 +360,14 @@ public static void resetStringDefaultTypeToDefaults() { * If you need to support legacy applications, call {@code useLegacyMappingFor(STRING, ENUM, TIMESTAMP)} before using * any YOJ features. * + * @param fieldValueTypes field value types to use legacy mapping for * @deprecated We STRONGLY advise against using the legacy mapping in new projects. * Please call {@link #useRecommendedMappingFor(FieldValueType...) useNewMappingFor(STRING, ENUM, TIMESTAMP)} instead, * and annotate custom-mapped columns with {@link Column @Column} where a different mapping is desired. - * - * @param fieldValueTypes field value types to use legacy mapping for */ @Deprecated public static void useLegacyMappingFor(FieldValueType... fieldValueTypes) { + typeMappingExplicitlySet = true; for (var fvt : fieldValueTypes) { switch (fvt) { case STRING, ENUM -> VALUE_DEFAULT_YQL_TYPES.put(fvt, new ValueYqlTypeSelector(fvt, PrimitiveTypeId.STRING, null)); @@ -386,6 +392,7 @@ public static void useLegacyMappingFor(FieldValueType... fieldValueTypes) { */ @ExperimentalApi(issue = "https://github.com/ydb-platform/yoj-project/issues/20") public static void useRecommendedMappingFor(FieldValueType... fieldValueTypes) { + typeMappingExplicitlySet = true; for (var fvt : fieldValueTypes) { switch (fvt) { case STRING, ENUM -> VALUE_DEFAULT_YQL_TYPES.put(fvt, new ValueYqlTypeSelector(fvt, PrimitiveTypeId.UTF8, null)); @@ -457,6 +464,11 @@ public static YqlPrimitiveType of(JavaField column) { @NonNull private static YqlPrimitiveType resolveYqlType(Type javaType, FieldValueType valueType, PrimitiveTypeId yqlType, String qualifier) { + if (!typeMappingExplicitlySet) { + typeMappingExplicitlySet = true; + log.error("YOJ's Java<->YDB type mapping IS NOT specified explicitly! See https://github.com/ydb-platform/yoj-project/issues/20#issuecomment-1971661677"); + } + YqlTypeSelector typeSelector; switch (valueType) {