[feature](Nereids) support datev1 and datetimev1 (#28581)
This commit is contained in:
@ -753,7 +753,7 @@ specifiedPartition
|
||||
|
||||
constant
|
||||
: NULL #nullLiteral
|
||||
| type=(DATE | DATEV1 | DATEV2 | TIMESTAMP) STRING_LITERAL #typeConstructor
|
||||
| type=(DATE | DATEV1 | DATEV2 | TIMESTAMP) STRING_LITERAL #typeConstructor
|
||||
| number #numericLiteral
|
||||
| booleanValue #booleanLiteral
|
||||
| STRING_LITERAL #stringLiteral
|
||||
|
||||
@ -216,6 +216,9 @@ public abstract class DataType {
|
||||
case "date":
|
||||
dataType = DateType.INSTANCE;
|
||||
break;
|
||||
case "datev1":
|
||||
dataType = DateType.NOT_CONVERSION;
|
||||
break;
|
||||
case "datev2":
|
||||
dataType = DateV2Type.INSTANCE;
|
||||
break;
|
||||
@ -234,6 +237,17 @@ public abstract class DataType {
|
||||
throw new AnalysisException("Nereids do not support type: " + type);
|
||||
}
|
||||
break;
|
||||
case "datetimev1":
|
||||
switch (types.size()) {
|
||||
case 1:
|
||||
dataType = DateTimeType.NOT_CONVERSION;
|
||||
break;
|
||||
case 2:
|
||||
throw new AnalysisException("Nereids do not support datetimev1 type with precision");
|
||||
default:
|
||||
throw new AnalysisException("Nereids do not support type: " + type);
|
||||
}
|
||||
break;
|
||||
case "datetimev2":
|
||||
switch (types.size()) {
|
||||
case 1:
|
||||
|
||||
@ -31,15 +31,23 @@ import java.time.temporal.ChronoUnit;
|
||||
public class DateTimeType extends DateLikeType {
|
||||
|
||||
public static final DateTimeType INSTANCE = new DateTimeType();
|
||||
public static final DateTimeType NOT_CONVERSION = new DateTimeType(false);
|
||||
|
||||
private static final int WIDTH = 16;
|
||||
|
||||
private final boolean shouldConversion;
|
||||
|
||||
private DateTimeType() {
|
||||
this.shouldConversion = true;
|
||||
}
|
||||
|
||||
private DateTimeType(boolean shouldConversion) {
|
||||
this.shouldConversion = shouldConversion;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataType conversion() {
|
||||
if (Config.enable_date_conversion) {
|
||||
if (Config.enable_date_conversion && shouldConversion) {
|
||||
return DateTimeV2Type.SYSTEM_DEFAULT;
|
||||
}
|
||||
return this;
|
||||
|
||||
@ -31,15 +31,23 @@ import java.time.temporal.ChronoUnit;
|
||||
public class DateType extends DateLikeType {
|
||||
|
||||
public static final DateType INSTANCE = new DateType();
|
||||
public static final DateType NOT_CONVERSION = new DateType(false);
|
||||
|
||||
private static final int WIDTH = 16;
|
||||
|
||||
private final boolean shouldConversion;
|
||||
|
||||
private DateType() {
|
||||
this.shouldConversion = true;
|
||||
}
|
||||
|
||||
private DateType(boolean shouldConversion) {
|
||||
this.shouldConversion = shouldConversion;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataType conversion() {
|
||||
if (Config.enable_date_conversion) {
|
||||
if (Config.enable_date_conversion && shouldConversion) {
|
||||
return DateV2Type.INSTANCE;
|
||||
}
|
||||
return this;
|
||||
|
||||
@ -22,6 +22,7 @@ import org.apache.doris.common.Config;
|
||||
import org.apache.doris.common.Pair;
|
||||
import org.apache.doris.nereids.StatementContext;
|
||||
import org.apache.doris.nereids.analyzer.UnboundResultSink;
|
||||
import org.apache.doris.nereids.exceptions.AnalysisException;
|
||||
import org.apache.doris.nereids.exceptions.ParseException;
|
||||
import org.apache.doris.nereids.glue.LogicalPlanAdapter;
|
||||
import org.apache.doris.nereids.trees.expressions.Cast;
|
||||
@ -37,6 +38,8 @@ import org.apache.doris.nereids.trees.plans.logical.LogicalCTE;
|
||||
import org.apache.doris.nereids.trees.plans.logical.LogicalJoin;
|
||||
import org.apache.doris.nereids.trees.plans.logical.LogicalPlan;
|
||||
import org.apache.doris.nereids.trees.plans.logical.LogicalProject;
|
||||
import org.apache.doris.nereids.types.DateTimeType;
|
||||
import org.apache.doris.nereids.types.DateType;
|
||||
import org.apache.doris.nereids.types.DecimalV2Type;
|
||||
import org.apache.doris.nereids.types.DecimalV3Type;
|
||||
import org.apache.doris.qe.SessionVariable;
|
||||
@ -305,7 +308,27 @@ public class NereidsParserTest extends ParserTestBase {
|
||||
.stream()
|
||||
.mapToLong(e -> e.<Set<DecimalLiteral>>collect(DecimalLiteral.class::isInstance).size())
|
||||
.sum();
|
||||
Assertions.assertEquals(doubleCount, Config.enable_decimal_conversion ? 0 : 1);
|
||||
Assertions.assertEquals(Config.enable_decimal_conversion ? 0 : 1, doubleCount);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDatev1() {
|
||||
String dv1 = "SELECT CAST('2023-12-18' AS DATEV1)";
|
||||
NereidsParser nereidsParser = new NereidsParser();
|
||||
LogicalPlan logicalPlan = (LogicalPlan) nereidsParser.parseSingle(dv1).child(0);
|
||||
Assertions.assertEquals(DateType.INSTANCE, logicalPlan.getExpressions().get(0).getDataType());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDatetimev1() {
|
||||
String dtv1 = "SELECT CAST('2023-12-18' AS DATETIMEV1)";
|
||||
NereidsParser nereidsParser = new NereidsParser();
|
||||
LogicalPlan logicalPlan = (LogicalPlan) nereidsParser.parseSingle(dtv1).child(0);
|
||||
Assertions.assertEquals(DateTimeType.INSTANCE, logicalPlan.getExpressions().get(0).getDataType());
|
||||
|
||||
String wrongDtv1 = "SELECT CAST('2023-12-18' AS DATETIMEV1(2))";
|
||||
Assertions.assertThrows(AnalysisException.class, () -> nereidsParser.parseSingle(wrongDtv1).child(0));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user