Skip to content

Commit

Permalink
data can work when partition column is datetime
Browse files Browse the repository at this point in the history
  • Loading branch information
xiedeyantu committed Mar 17, 2024
1 parent 277b3cf commit 284fd4b
Showing 1 changed file with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
import org.apache.doris.common.AnalysisException;
import org.apache.doris.common.io.Text;
import org.apache.doris.common.io.Writable;
import org.apache.doris.nereids.trees.expressions.literal.DateTimeLiteral;
import org.apache.doris.nereids.trees.expressions.literal.DateTimeV2Literal;
import org.apache.doris.nereids.trees.expressions.literal.Literal;
import org.apache.doris.qe.SessionVariable;

import com.google.common.base.Joiner;
Expand Down Expand Up @@ -90,7 +93,14 @@ public static PartitionKey createPartitionKey(List<PartitionValue> keys, List<Co
Preconditions.checkArgument(keys.size() <= columns.size());
int i;
for (i = 0; i < keys.size(); ++i) {
partitionKey.keys.add(keys.get(i).getValue(columns.get(i).getType()));
Type keyType = columns.get(i).getType();
// If column type is datatime and key type is date, we should convert date to datetime.
if (keyType.isDatetime() || keyType.isDatetimeV2()){
Literal dateTimeLiteral = getDateTimeLiteral(keys.get(i).getStringValue(), keyType);
partitionKey.keys.add(dateTimeLiteral.toLegacyLiteral());
} else {
partitionKey.keys.add(keys.get(i).getValue(keyType));
}
partitionKey.types.add(columns.get(i).getDataType());
}

Expand All @@ -104,6 +114,15 @@ public static PartitionKey createPartitionKey(List<PartitionValue> keys, List<Co
return partitionKey;
}

private static Literal getDateTimeLiteral(String value, Type type) throws AnalysisException {
if (type.equals(Type.DATETIME)) {
return new DateTimeLiteral(value);
} else if (type.equals(Type.DATETIMEV2)) {
return new DateTimeV2Literal(value);
}
throw new AnalysisException("date convert to datetime failed.");
}

public static PartitionKey createListPartitionKeyWithTypes(List<PartitionValue> values, List<Type> types,
boolean isHive)
throws AnalysisException {
Expand Down

0 comments on commit 284fd4b

Please sign in to comment.