mchades commented on code in PR #9821:
URL: https://github.com/apache/gravitino/pull/9821#discussion_r2757827560
##########
catalogs/catalog-jdbc-common/src/main/java/org/apache/gravitino/catalog/jdbc/operation/JdbcTableOperations.java:
##########
@@ -95,6 +100,87 @@ public void initialize(
this.columnDefaultValueConverter = jdbcColumnDefaultValueConverter;
}
+ /**
+ * Handles quoting for default values based on the column data type. For
example, if the default
+ * valur is ""(empty string), it will be represented as two single quotes ''
for string-like
+ * columns, or NULL for others.
+ *
+ * @param column the column
+ * @param defaultValueExpression the default value expression
+ * @return the properly quoted default value as a string
+ */
+ protected String handleQuotingForDefaultValue(
+ JdbcColumn column, Expression defaultValueExpression) {
+ String defaultValue =
columnDefaultValueConverter.fromGravitino(defaultValueExpression);
+
+ // Special handling for SQL NULL: do not quote it, even for string-like
columns.
+ if (Literals.NULL.equals(defaultValueExpression)) {
+ return "NULL";
+ }
+
+ // Special handling for string-like columns.
+ if (column.dataType() instanceof VarCharType
+ || column.dataType() instanceof StringType
+ || column.dataType() instanceof FixedCharType) {
+ if (StringUtils.isEmpty(defaultValue)) {
+ // Represent empty string default as two single quotes.
+ return "''";
+ }
+
+ // If the converter already produced a quoted literal, preserve it.
Review Comment:
So, can we unify the string-like literal type in the converter? It seems to
simplify things.
--
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]