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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]