Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature-wip] support datev2/datetimev2/timev2 in FE #9611

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions fe/fe-core/src/main/cup/sql_parser.cup
Original file line number Diff line number Diff line change
Expand Up @@ -4599,11 +4599,15 @@ type ::=
| KW_DOUBLE
{: RESULT = Type.DOUBLE; :}
| KW_DATE
{: RESULT = Type.DATE; :}
{: RESULT = ScalarType.createDateType(); :}
| KW_DATETIME LPAREN INTEGER_LITERAL:precision RPAREN
{: RESULT = ScalarType.createDatetimeV2Type(precision.intValue()); :}
| KW_DATETIME
{: RESULT = Type.DATETIME; :}
{: RESULT = ScalarType.createDatetimeType(); :}
| KW_TIME LPAREN INTEGER_LITERAL:precision RPAREN
{: RESULT = ScalarType.createTimeV2Type(precision.intValue()); :}
| KW_TIME
{: RESULT = Type.TIME; :}
{: RESULT = ScalarType.createTimeType(); :}
| KW_BITMAP
{: RESULT = Type.BITMAP; :}
| KW_QUANTILE_STATE
Expand Down
11 changes: 9 additions & 2 deletions fe/fe-core/src/main/java/org/apache/doris/alter/Alter.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
import org.apache.doris.catalog.Type;
import org.apache.doris.catalog.View;
import org.apache.doris.common.AnalysisException;
import org.apache.doris.common.Config;
import org.apache.doris.common.DdlException;
import org.apache.doris.common.MetaNotFoundException;
import org.apache.doris.common.UserException;
Expand Down Expand Up @@ -677,12 +678,18 @@ public void modifyPartitionsProperty(Database db,
// 4.2 combine the old properties with new ones
Map<String, String> newProperties = new HashMap<>();
newProperties.put(PropertyAnalyzer.PROPERTIES_STORAGE_MEDIUM, dataProperty.getStorageMedium().name());
Type datetimeType;
if (Config.use_date_v2_by_default) {
datetimeType = Type.DATETIMEV2;
} else {
datetimeType = Type.DATETIME;
}
DateLiteral dateLiteral = new DateLiteral(dataProperty.getCooldownTimeMs(),
TimeUtils.getTimeZone(), Type.DATETIME);
TimeUtils.getTimeZone(), datetimeType);
newProperties.put(PropertyAnalyzer.PROPERTIES_STORAGE_COOLDOWN_TIME, dateLiteral.getStringValue());
newProperties.put(PropertyAnalyzer.PROPERTIES_REMOTE_STORAGE_RESOURCE, dataProperty.getRemoteStorageResourceName());
DateLiteral dateLiteral1 = new DateLiteral(dataProperty.getRemoteCooldownTimeMs(),
TimeUtils.getTimeZone(), Type.DATETIME);
TimeUtils.getTimeZone(), datetimeType);
newProperties.put(PropertyAnalyzer.PROPERTIES_REMOTE_STORAGE_COOLDOWN_TIME, dateLiteral1.getStringValue());
newProperties.putAll(properties);
// 4.3 analyze new properties
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,7 @@ public TypeDef getTargetTypeDef() {

private static boolean disableRegisterCastingFunction(Type fromType, Type toType) {
// Disable casting from boolean to decimal or datetime or date
if (fromType.isBoolean()
&& (toType.equals(Type.DECIMALV2) || toType.equals(Type.DATETIME) || toType.equals(Type.DATE))) {
if (fromType.isBoolean() && (toType.equals(Type.DECIMALV2) || toType.isDateType())) {
return true;
}

Expand All @@ -165,7 +164,9 @@ public static void initBuiltins(FunctionSet functionSet) {
beClass = "TimeOperators";
}
String typeName = Function.getUdfTypeName(toType.getPrimitiveType());
if (toType.getPrimitiveType() == PrimitiveType.DATE) {
// only refactor date/datetime for vectorized engine.
if (toType.getPrimitiveType() == PrimitiveType.DATE
|| toType.getPrimitiveType() == PrimitiveType.DATEV2) {
typeName = "date_val";
}
String beSymbol = "doris::" + beClass + "::cast_to_"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,9 @@ public static void validateDefaultValue(Type type, String defaultValue) throws A
break;
case DATE:
case DATETIME:
new DateLiteral(defaultValue, type);
case DATEV2:
case DATETIMEV2:
new DateLiteral(defaultValue, DateLiteral.getDefaultDateType(type));
break;
case CHAR:
case VARCHAR:
Expand All @@ -327,11 +329,8 @@ public static void validateDefaultValue(Type type, String defaultValue) throws A
}
break;
case BITMAP:
break;
case ARRAY:
break;
case MAP:
break;
case STRUCT:
break;
case BOOLEAN:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -467,10 +467,13 @@ private Types.PGenericType convertToPParameterType(Type arg) throws AnalysisExce
typeBuilder.setId(Types.PGenericType.TypeId.BITMAP);
break;
case DATE:
case DATEV2:
typeBuilder.setId(Types.PGenericType.TypeId.DATE);
break;
case DATETIME:
case DATETIMEV2:
case TIME:
case TIMEV2:
typeBuilder.setId(Types.PGenericType.TypeId.DATETIME);
break;
case DECIMALV2:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ private static void validateHllHash(List<String> args, Map<String, String> colum
}

private static void validateNowFunction(Column mappingColumn) throws AnalysisException {
if (!mappingColumn.getOriginType().equals(Type.DATE) && !mappingColumn.getOriginType().equals(Type.DATETIME)) {
if (!mappingColumn.getOriginType().isDateType()) {
throw new AnalysisException("Now() function is only support for DATE/DATETIME column");
}
}
Expand Down
Loading