You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ignite.apache.org by "AMashenkov (via GitHub)" <gi...@apache.org> on 2023/08/01 13:52:37 UTC

[GitHub] [ignite-3] AMashenkov opened a new pull request, #2391: IGNITE-20105 Set default precision and scale for new column descriptor when needed.

AMashenkov opened a new pull request, #2391:
URL: https://github.com/apache/ignite-3/pull/2391

   (no comment)


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [ignite-3] AMashenkov commented on a diff in pull request #2391: IGNITE-20105 Set default precision and scale for new column descriptor when needed.

Posted by "AMashenkov (via GitHub)" <gi...@apache.org>.
AMashenkov commented on code in PR #2391:
URL: https://github.com/apache/ignite-3/pull/2391#discussion_r1285574222


##########
modules/catalog/src/main/java/org/apache/ignite/internal/catalog/commands/CatalogUtils.java:
##########
@@ -155,9 +204,10 @@ public static CatalogZoneDescriptor fromParams(int id, CreateZoneParams params)
      * @return Column descriptor.
      */
     public static CatalogTableColumnDescriptor fromParams(ColumnParams params) {
-        int precision = params.precision() != null ? params.precision() : 0;
-        int scale = params.scale() != null ? params.scale() : 0;
-        int length = params.length() != null ? params.length() : 0;
+        int precision = params.precision() != null ? params.precision() : defaultPrecision(params.type());

Review Comment:
   1. java.util.Objects#requireNonNullElse will force argument evaluation.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [ignite-3] tkalkirill commented on a diff in pull request #2391: IGNITE-20105 Set default precision and scale for new column descriptor when needed.

Posted by "tkalkirill (via GitHub)" <gi...@apache.org>.
tkalkirill commented on code in PR #2391:
URL: https://github.com/apache/ignite-3/pull/2391#discussion_r1285366115


##########
modules/catalog/src/main/java/org/apache/ignite/internal/catalog/commands/ColumnParams.java:
##########
@@ -158,7 +158,7 @@ public Builder defaultValue(DefaultValue defaultValue) {
          *
          * @return {@code this}.
          */
-        public Builder precision(int precision) {
+        public Builder precision(Integer precision) {

Review Comment:
   Please add `@Nullable` for method `org.apache.ignite.internal.catalog.commands.ColumnParams#precision` and specify in documentation what `null` means.



##########
modules/catalog/src/main/java/org/apache/ignite/internal/catalog/commands/ColumnParams.java:
##########
@@ -169,7 +169,7 @@ public Builder precision(int precision) {
          *
          * @return {@code this}.
          */
-        public Builder scale(int scale) {
+        public Builder scale(Integer scale) {

Review Comment:
   Please add `@Nullable` for method `org.apache.ignite.internal.catalog.commands.ColumnParams#scale` and specify in documentation what `null` means.



##########
modules/catalog/src/main/java/org/apache/ignite/internal/catalog/commands/CatalogUtils.java:
##########
@@ -176,4 +226,36 @@ public static boolean isSupportedColumnTypeChange(ColumnType source, ColumnType
 
         return supportedTransitions != null && supportedTransitions.contains(target);
     }
+
+    private static int defaultPrecision(ColumnType columnType) {
+        //TODO IGNITE-19938: Add REAL,FLOAT and DOUBLE precision. See SQL`16 part 2 section 6.1 syntax rule 29-31
+        switch (columnType) {
+            case NUMBER:
+            case DECIMAL:
+                return DEFAULT_DECIMAL_PRECISION;
+            case TIME:
+                return DEFAULT_TIME_PRECISION;
+            case TIMESTAMP:
+            case DATETIME:
+                return DEFAULT_TIMESTAMP_PRECISION;
+            default:
+                return 0;
+        }
+    }
+
+    private static int defaultLength(ColumnType columnType) {
+        //TODO IGNITE-19938: Return length for other types. See SQL`16 part 2 section 6.1 syntax rule 39
+        switch (columnType) {
+            case BITMASK:
+            case STRING:
+            case BYTE_ARRAY:
+                return Integer.MAX_VALUE;
+            default:
+                /*
+                 * Default length is 1 if implicit.
+                 * SQL`16 part 2 section 6.1 syntax rule 5
+                 */
+                return Math.max(1, defaultPrecision(columnType));

Review Comment:
   I think it's worth putting `1` into a constant with a description.



##########
modules/catalog/src/main/java/org/apache/ignite/internal/catalog/commands/CatalogUtils.java:
##########
@@ -155,9 +204,10 @@ public static CatalogZoneDescriptor fromParams(int id, CreateZoneParams params)
      * @return Column descriptor.
      */
     public static CatalogTableColumnDescriptor fromParams(ColumnParams params) {
-        int precision = params.precision() != null ? params.precision() : 0;
-        int scale = params.scale() != null ? params.scale() : 0;
-        int length = params.length() != null ? params.length() : 0;
+        int precision = params.precision() != null ? params.precision() : defaultPrecision(params.type());

Review Comment:
   Maybe use **java.util.Objects#requireNonNullElse** ? =)



##########
modules/catalog/src/main/java/org/apache/ignite/internal/catalog/commands/ColumnParams.java:
##########
@@ -180,7 +180,7 @@ public Builder scale(int scale) {
          *
          * @return {@code this}.
          */
-        public Builder length(int length) {
+        public Builder length(Integer length) {

Review Comment:
   Please add `@Nullable` for method `org.apache.ignite.internal.catalog.commands.ColumnParams#length` and specify in documentation what `null` means.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [ignite-3] AMashenkov merged pull request #2391: IGNITE-20105 Set default precision and scale for new column descriptor when needed.

Posted by "AMashenkov (via GitHub)" <gi...@apache.org>.
AMashenkov merged PR #2391:
URL: https://github.com/apache/ignite-3/pull/2391


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [ignite-3] AMashenkov commented on a diff in pull request #2391: IGNITE-20105 Set default precision and scale for new column descriptor when needed.

Posted by "AMashenkov (via GitHub)" <gi...@apache.org>.
AMashenkov commented on code in PR #2391:
URL: https://github.com/apache/ignite-3/pull/2391#discussion_r1285574222


##########
modules/catalog/src/main/java/org/apache/ignite/internal/catalog/commands/CatalogUtils.java:
##########
@@ -155,9 +204,10 @@ public static CatalogZoneDescriptor fromParams(int id, CreateZoneParams params)
      * @return Column descriptor.
      */
     public static CatalogTableColumnDescriptor fromParams(ColumnParams params) {
-        int precision = params.precision() != null ? params.precision() : 0;
-        int scale = params.scale() != null ? params.scale() : 0;
-        int length = params.length() != null ? params.length() : 0;
+        int precision = params.precision() != null ? params.precision() : defaultPrecision(params.type());

Review Comment:
   1. java.util.Objects#requireNonNullElse will force argument evaluation.
   2. `int` argument will be boxed/unboxed.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [ignite-3] tkalkirill commented on a diff in pull request #2391: IGNITE-20105 Set default precision and scale for new column descriptor when needed.

Posted by "tkalkirill (via GitHub)" <gi...@apache.org>.
tkalkirill commented on code in PR #2391:
URL: https://github.com/apache/ignite-3/pull/2391#discussion_r1285594229


##########
modules/catalog/src/main/java/org/apache/ignite/internal/catalog/commands/CatalogUtils.java:
##########
@@ -155,9 +204,10 @@ public static CatalogZoneDescriptor fromParams(int id, CreateZoneParams params)
      * @return Column descriptor.
      */
     public static CatalogTableColumnDescriptor fromParams(ColumnParams params) {
-        int precision = params.precision() != null ? params.precision() : 0;
-        int scale = params.scale() != null ? params.scale() : 0;
-        int length = params.length() != null ? params.length() : 0;
+        int precision = params.precision() != null ? params.precision() : defaultPrecision(params.type());

Review Comment:
   At your discretion, this operation does not seem to be performed often, and you can omit this nuance.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org