imay commented on a change in pull request #1453: Fix bug that user can set
null default value to non-nullable column in create table stmt
URL: https://github.com/apache/incubator-doris/pull/1453#discussion_r302088419
##########
File path: fe/src/main/java/org/apache/doris/analysis/ColumnDef.java
##########
@@ -38,27 +38,58 @@
// pv bigint sum NULL DEFAULT "-1" "page visit"
public class ColumnDef {
private static final Logger LOG = LogManager.getLogger(ColumnDef.class);
- private static final String HLL_EMPTY_SET = "0";
+
+ /*
+ * User can set default value for a column
+ * eg:
+ * k1 INT NOT NULL DEFAULT "10"
+ * k1 INT NULL
+ * k1 INT NULL DEFAULT NULL
+ *
+ * ColumnnDef will be transformed to Column in Analysis phase, and in
Column, default value is a String.
+ * No matter does the user set the default value as NULL explicitly, or
not set default value,
+ * the default value in Column will be "null", so that Doris can not
distinguish between "not set" and "set as null".
+ *
+ * But this is OK because Column has another attribute "isAllowNull".
+ * If the column is not allowed to be null, and user does not set the
default value,
+ * even if default value saved in Column is null, the "null" value can not
be loaded into this column,
+ * so data correctness can be guaranteed.
+ */
+ public static class DefaultValue {
+ public boolean isSet;
+ public String value;
+
+ public DefaultValue(boolean isSet, String value) {
+ this.isSet = isSet;
+ this.value = value;
+ }
+
+ // no default value
+ public static DefaultValue NOT_SET = new DefaultValue(false, null);
+ // default null
+ public static DefaultValue NULL_DEFAULT_VALUE = new DefaultValue(true,
null);
+ // default "valuie"
Review comment:
```suggestion
// default "value"
```
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]