starocean999 commented on code in PR #64026:
URL: https://github.com/apache/doris/pull/64026#discussion_r3418983826


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/info/PartitionDefinition.java:
##########
@@ -189,12 +200,73 @@ public void setPartitionTypes(List<DataType> 
partitionTypes) {
         this.partitionTypes = partitionTypes;
     }
 
+    protected void ensurePartitionTypesInitialized() {
+        if (partitionTypes == null) {
+            throw new AnalysisException("partitionTypes should be initialized 
before validating partition definition");
+        }
+    }
+
+    protected Expression typedPartitionExpression(Expression expression, int 
index) {
+        ensurePartitionTypesInitialized();
+        return strictTypedPartitionExpression(expression, 
partitionTypes.get(index));
+    }
+
+    static Expression strictTypedPartitionExpression(Expression expression, 
DataType targetType) {
+        if (expression instanceof MaxValue || expression instanceof 
MaxLiteral) {
+            return expression;
+        }
+        if (expression.isNullLiteral()) {
+            return expression.checkedCastTo(targetType);
+        }
+        if (!expression.isLiteral()) {
+            throw new AnalysisException("Partition value must be literal: " + 
expression.toSql());
+        }
+        String value = ((Literal) expression).getStringValue();
+        try {
+            if (targetType.isDateTimeType() || targetType.isDateTimeV2Type() 
|| targetType.isTimeStampTzType()) {
+                return convertPartitionLiteral(value, 
targetType).checkedCastTo(targetType);
+            }
+            validateCharacterLength(value, targetType);
+            LiteralExpr typedLiteral = LiteralExprUtils.createLiteral(
+                    value, targetType.toCatalogDataType());
+            return Literal.fromLegacyLiteral(typedLiteral, 
typedLiteral.getType());

Review Comment:
   这里的核心逻辑是对于有精度信息的类型,直接从字符串解析出原始精度信息。后续cast到targetType时,需要一个无损转换。如果是有损的,则报错。



-- 
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]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to