Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ public class DayMicrosecondAdd extends ScalarFunction
implements BinaryExpression, ExplicitlyCastableSignature,
ComputeSignatureForDateArithmetic, PropagateNullable, DateAddSubMonotonic {
public static final List<FunctionSignature> SIGNATURES = ImmutableList.of(
FunctionSignature.ret(DateTimeV2Type.MAX)
.args(DateTimeV2Type.MAX, VarcharType.SYSTEM_DEFAULT),
FunctionSignature.ret(TimeStampTzType.MAX)
.args(TimeStampTzType.MAX, VarcharType.SYSTEM_DEFAULT)
FunctionSignature.ret(DateTimeV2Type.WILDCARD)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P1] Cover the remaining scale-promoting TIMESTAMPTZ siblings

These wildcard signatures fix the six day/hour/minute classes, but SecondMicrosecondAdd/Sub, MicroSecondsAdd/Sub, and MilliSecondsAdd/Sub still declare the ordered concrete pair DATETIMEV2(6) then TIMESTAMPTZ(6). For example, a typed scale-3 column still binds as:

Project(second_microsecond_add(
  CAST(ts3#1: TIMESTAMPTZ(3) AS DATETIMEV2(6)), '0.000001'
) : DATETIMEV2(6))

Neither concrete signature is identical for scales 0-5, both tie in the implicit round, and search keeps the first DATETIMEV2 candidate before those classes inspect the selected family. All six paths are reachable and already have dedicated TIMESTAMPTZ FE/BE overloads, so they still return the wrong family and use session-local DATETIMEV2 semantics. This is distinct from the earlier thread, which covered only the six changed classes. Please use family wildcard signatures for these siblings too and extend the typed scale-0/3/6 type/runtime matrix to cover them.

.args(DateTimeV2Type.WILDCARD, VarcharType.SYSTEM_DEFAULT),
FunctionSignature.ret(TimeStampTzType.WILDCARD)
.args(TimeStampTzType.WILDCARD, VarcharType.SYSTEM_DEFAULT)
);

public DayMicrosecondAdd(Expression arg0, Expression arg1) {
Expand Down Expand Up @@ -80,6 +80,9 @@ public Expression withConstantArgs(Expression literal) {
@Override
public FunctionSignature computeSignature(FunctionSignature signature) {
signature = super.computeSignature(signature);
if (signature.argumentsTypes.get(0) instanceof TimeStampTzType) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P1] Select the TIMESTAMPTZ family before forcing scale 6

For the test's ts TIMESTAMPTZ(3), neither concrete MAX-scale signature matches identically. In the implicit round both candidates match, receive equal scores, and SearchSignature keeps the first DATETIMEV2(6) signature. Because search runs before this method, super.computeSignature has already lost the source family and this condition is false:

Project(day_microsecond_add(
  CAST(ts#1: TIMESTAMPTZ(3) AS DATETIMEV2(6)), interval
) : DATETIMEV2(6))

Thus typed TIMESTAMPTZ columns, casts, and literals at scales 0-5 still take the old session-local DATETIMEV2 path in all six changed classes; only scale 6 and zoned string literals reach this branch. Please use wildcard-scale family signatures (the established sibling pattern), or otherwise preserve the typed family during selection without regressing the existing zoned-string selection, before promoting the selected family to scale 6. Also cover typed scales below 6.

return signature.withArgumentType(0, TimeStampTzType.MAX).withReturnType(TimeStampTzType.MAX);
}
return signature.withArgumentType(0, DateTimeV2Type.MAX).withReturnType(DateTimeV2Type.MAX);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ public class DayMicrosecondSub extends ScalarFunction
implements BinaryExpression, ExplicitlyCastableSignature,
ComputeSignatureForDateArithmetic, PropagateNullable, DateAddSubMonotonic {
public static final List<FunctionSignature> SIGNATURES = ImmutableList.of(
FunctionSignature.ret(DateTimeV2Type.MAX)
.args(DateTimeV2Type.MAX, VarcharType.SYSTEM_DEFAULT),
FunctionSignature.ret(TimeStampTzType.MAX)
.args(TimeStampTzType.MAX, VarcharType.SYSTEM_DEFAULT)
FunctionSignature.ret(DateTimeV2Type.WILDCARD)
.args(DateTimeV2Type.WILDCARD, VarcharType.SYSTEM_DEFAULT),
FunctionSignature.ret(TimeStampTzType.WILDCARD)
.args(TimeStampTzType.WILDCARD, VarcharType.SYSTEM_DEFAULT)
);

public DayMicrosecondSub(Expression arg0, Expression arg1) {
Expand Down Expand Up @@ -80,6 +80,9 @@ public Expression withConstantArgs(Expression literal) {
@Override
public FunctionSignature computeSignature(FunctionSignature signature) {
signature = super.computeSignature(signature);
if (signature.argumentsTypes.get(0) instanceof TimeStampTzType) {
return signature.withArgumentType(0, TimeStampTzType.MAX).withReturnType(TimeStampTzType.MAX);
}
return signature.withArgumentType(0, DateTimeV2Type.MAX).withReturnType(DateTimeV2Type.MAX);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ public class HourMicrosecondAdd extends ScalarFunction
implements BinaryExpression, ExplicitlyCastableSignature,
ComputeSignatureForDateArithmetic, PropagateNullable, DateAddSubMonotonic {
public static final List<FunctionSignature> SIGNATURES = ImmutableList.of(
FunctionSignature.ret(DateTimeV2Type.MAX)
.args(DateTimeV2Type.MAX, VarcharType.SYSTEM_DEFAULT),
FunctionSignature.ret(TimeStampTzType.MAX)
.args(TimeStampTzType.MAX, VarcharType.SYSTEM_DEFAULT)
FunctionSignature.ret(DateTimeV2Type.WILDCARD)
.args(DateTimeV2Type.WILDCARD, VarcharType.SYSTEM_DEFAULT),
FunctionSignature.ret(TimeStampTzType.WILDCARD)
.args(TimeStampTzType.WILDCARD, VarcharType.SYSTEM_DEFAULT)
);

public HourMicrosecondAdd(Expression arg0, Expression arg1) {
Expand Down Expand Up @@ -80,6 +80,9 @@ public Expression withConstantArgs(Expression literal) {
@Override
public FunctionSignature computeSignature(FunctionSignature signature) {
signature = super.computeSignature(signature);
if (signature.argumentsTypes.get(0) instanceof TimeStampTzType) {
return signature.withArgumentType(0, TimeStampTzType.MAX).withReturnType(TimeStampTzType.MAX);
}
return signature.withArgumentType(0, DateTimeV2Type.MAX).withReturnType(DateTimeV2Type.MAX);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ public class HourMicrosecondSub extends ScalarFunction
implements BinaryExpression, ExplicitlyCastableSignature,
ComputeSignatureForDateArithmetic, PropagateNullable, DateAddSubMonotonic {
public static final List<FunctionSignature> SIGNATURES = ImmutableList.of(
FunctionSignature.ret(DateTimeV2Type.MAX)
.args(DateTimeV2Type.MAX, VarcharType.SYSTEM_DEFAULT),
FunctionSignature.ret(TimeStampTzType.MAX)
.args(TimeStampTzType.MAX, VarcharType.SYSTEM_DEFAULT)
FunctionSignature.ret(DateTimeV2Type.WILDCARD)
.args(DateTimeV2Type.WILDCARD, VarcharType.SYSTEM_DEFAULT),
FunctionSignature.ret(TimeStampTzType.WILDCARD)
.args(TimeStampTzType.WILDCARD, VarcharType.SYSTEM_DEFAULT)
);

public HourMicrosecondSub(Expression arg0, Expression arg1) {
Expand Down Expand Up @@ -80,6 +80,9 @@ public Expression withConstantArgs(Expression literal) {
@Override
public FunctionSignature computeSignature(FunctionSignature signature) {
signature = super.computeSignature(signature);
if (signature.argumentsTypes.get(0) instanceof TimeStampTzType) {
return signature.withArgumentType(0, TimeStampTzType.MAX).withReturnType(TimeStampTzType.MAX);
}
return signature.withArgumentType(0, DateTimeV2Type.MAX).withReturnType(DateTimeV2Type.MAX);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,10 @@ public class MicroSecondsAdd extends ScalarFunction implements BinaryExpression,
PropagateNullable, DateAddSubMonotonic {

private static final List<FunctionSignature> SIGNATURES = ImmutableList.of(
FunctionSignature.ret(DateTimeV2Type.MAX).args(DateTimeV2Type.MAX, BigIntType.INSTANCE),
FunctionSignature.ret(TimeStampTzType.MAX).args(TimeStampTzType.MAX, BigIntType.INSTANCE)
FunctionSignature.ret(DateTimeV2Type.WILDCARD)
.args(DateTimeV2Type.WILDCARD, BigIntType.INSTANCE),
FunctionSignature.ret(TimeStampTzType.WILDCARD)
.args(TimeStampTzType.WILDCARD, BigIntType.INSTANCE)
);

public MicroSecondsAdd(Expression arg0, Expression arg1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,11 @@
public class MicroSecondsSub extends ScalarFunction implements BinaryExpression, ExplicitlyCastableSignature,
PropagateNullable, DateAddSubMonotonic {

private static final List<FunctionSignature> SIGNATURES = ImmutableList
.of(FunctionSignature.ret(DateTimeV2Type.MAX).args(DateTimeV2Type.MAX, BigIntType.INSTANCE),
FunctionSignature.ret(TimeStampTzType.MAX).args(TimeStampTzType.MAX, BigIntType.INSTANCE)
private static final List<FunctionSignature> SIGNATURES = ImmutableList.of(
FunctionSignature.ret(DateTimeV2Type.WILDCARD)
.args(DateTimeV2Type.WILDCARD, BigIntType.INSTANCE),
FunctionSignature.ret(TimeStampTzType.WILDCARD)
.args(TimeStampTzType.WILDCARD, BigIntType.INSTANCE)
);

public MicroSecondsSub(Expression arg0, Expression arg1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,12 @@
public class MilliSecondsAdd extends ScalarFunction implements BinaryExpression, ExplicitlyCastableSignature,
PropagateNullable, DateAddSubMonotonic {

private static final List<FunctionSignature> SIGNATURES = ImmutableList
.of(FunctionSignature.ret(DateTimeV2Type.MAX).args(DateTimeV2Type.MAX, BigIntType.INSTANCE),
FunctionSignature.ret(TimeStampTzType.MAX).args(TimeStampTzType.MAX, BigIntType.INSTANCE)
);
private static final List<FunctionSignature> SIGNATURES = ImmutableList.of(
FunctionSignature.ret(DateTimeV2Type.WILDCARD)
.args(DateTimeV2Type.WILDCARD, BigIntType.INSTANCE),
FunctionSignature.ret(TimeStampTzType.WILDCARD)
.args(TimeStampTzType.WILDCARD, BigIntType.INSTANCE)
);

public MilliSecondsAdd(Expression arg0, Expression arg1) {
super("milliseconds_add", arg0, arg1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,11 @@
public class MilliSecondsSub extends ScalarFunction implements BinaryExpression, ExplicitlyCastableSignature,
PropagateNullable, DateAddSubMonotonic {

private static final List<FunctionSignature> SIGNATURES = ImmutableList
.of(FunctionSignature.ret(DateTimeV2Type.MAX).args(DateTimeV2Type.MAX, BigIntType.INSTANCE),
FunctionSignature.ret(TimeStampTzType.MAX).args(TimeStampTzType.MAX, BigIntType.INSTANCE)
private static final List<FunctionSignature> SIGNATURES = ImmutableList.of(
FunctionSignature.ret(DateTimeV2Type.WILDCARD)
.args(DateTimeV2Type.WILDCARD, BigIntType.INSTANCE),
FunctionSignature.ret(TimeStampTzType.WILDCARD)
.args(TimeStampTzType.WILDCARD, BigIntType.INSTANCE)
);

public MilliSecondsSub(Expression arg0, Expression arg1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ public class MinuteMicrosecondAdd extends ScalarFunction
implements BinaryExpression, ExplicitlyCastableSignature,
ComputeSignatureForDateArithmetic, PropagateNullable, DateAddSubMonotonic {
public static final List<FunctionSignature> SIGNATURES = ImmutableList.of(
FunctionSignature.ret(DateTimeV2Type.MAX)
.args(DateTimeV2Type.MAX, VarcharType.SYSTEM_DEFAULT),
FunctionSignature.ret(TimeStampTzType.MAX)
.args(TimeStampTzType.MAX, VarcharType.SYSTEM_DEFAULT)
FunctionSignature.ret(DateTimeV2Type.WILDCARD)
.args(DateTimeV2Type.WILDCARD, VarcharType.SYSTEM_DEFAULT),
FunctionSignature.ret(TimeStampTzType.WILDCARD)
.args(TimeStampTzType.WILDCARD, VarcharType.SYSTEM_DEFAULT)
);

public MinuteMicrosecondAdd(Expression arg0, Expression arg1) {
Expand Down Expand Up @@ -80,6 +80,9 @@ public Expression withConstantArgs(Expression literal) {
@Override
public FunctionSignature computeSignature(FunctionSignature signature) {
signature = super.computeSignature(signature);
if (signature.argumentsTypes.get(0) instanceof TimeStampTzType) {
return signature.withArgumentType(0, TimeStampTzType.MAX).withReturnType(TimeStampTzType.MAX);
}
return signature.withArgumentType(0, DateTimeV2Type.MAX).withReturnType(DateTimeV2Type.MAX);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ public class MinuteMicrosecondSub extends ScalarFunction
implements BinaryExpression, ExplicitlyCastableSignature,
ComputeSignatureForDateArithmetic, PropagateNullable, DateAddSubMonotonic {
public static final List<FunctionSignature> SIGNATURES = ImmutableList.of(
FunctionSignature.ret(DateTimeV2Type.MAX)
.args(DateTimeV2Type.MAX, VarcharType.SYSTEM_DEFAULT),
FunctionSignature.ret(TimeStampTzType.MAX)
.args(TimeStampTzType.MAX, VarcharType.SYSTEM_DEFAULT)
FunctionSignature.ret(DateTimeV2Type.WILDCARD)
.args(DateTimeV2Type.WILDCARD, VarcharType.SYSTEM_DEFAULT),
FunctionSignature.ret(TimeStampTzType.WILDCARD)
.args(TimeStampTzType.WILDCARD, VarcharType.SYSTEM_DEFAULT)
);

public MinuteMicrosecondSub(Expression arg0, Expression arg1) {
Expand Down Expand Up @@ -80,6 +80,9 @@ public Expression withConstantArgs(Expression literal) {
@Override
public FunctionSignature computeSignature(FunctionSignature signature) {
signature = super.computeSignature(signature);
if (signature.argumentsTypes.get(0) instanceof TimeStampTzType) {
return signature.withArgumentType(0, TimeStampTzType.MAX).withReturnType(TimeStampTzType.MAX);
}
return signature.withArgumentType(0, DateTimeV2Type.MAX).withReturnType(DateTimeV2Type.MAX);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ public class SecondMicrosecondAdd extends ScalarFunction
implements BinaryExpression, ExplicitlyCastableSignature,
ComputeSignatureForDateArithmetic, PropagateNullable, DateAddSubMonotonic {
public static final List<FunctionSignature> SIGNATURES = ImmutableList.of(
FunctionSignature.ret(DateTimeV2Type.MAX).args(DateTimeV2Type.MAX,
VarcharType.SYSTEM_DEFAULT),
FunctionSignature.ret(TimeStampTzType.MAX).args(TimeStampTzType.MAX,
VarcharType.SYSTEM_DEFAULT)
FunctionSignature.ret(DateTimeV2Type.WILDCARD)
.args(DateTimeV2Type.WILDCARD, VarcharType.SYSTEM_DEFAULT),
FunctionSignature.ret(TimeStampTzType.WILDCARD)
.args(TimeStampTzType.WILDCARD, VarcharType.SYSTEM_DEFAULT)
);

public SecondMicrosecondAdd(Expression arg0, Expression arg1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ public class SecondMicrosecondSub extends ScalarFunction
implements BinaryExpression, ExplicitlyCastableSignature,
ComputeSignatureForDateArithmetic, PropagateNullable, DateAddSubMonotonic {
public static final List<FunctionSignature> SIGNATURES = ImmutableList.of(
FunctionSignature.ret(DateTimeV2Type.MAX).args(DateTimeV2Type.MAX,
VarcharType.SYSTEM_DEFAULT),
FunctionSignature.ret(TimeStampTzType.MAX).args(TimeStampTzType.MAX,
VarcharType.SYSTEM_DEFAULT)
FunctionSignature.ret(DateTimeV2Type.WILDCARD)
.args(DateTimeV2Type.WILDCARD, VarcharType.SYSTEM_DEFAULT),
FunctionSignature.ret(TimeStampTzType.WILDCARD)
.args(TimeStampTzType.WILDCARD, VarcharType.SYSTEM_DEFAULT)
);

public SecondMicrosecondSub(Expression arg0, Expression arg1) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
-- This file is automatically generated. You should know what you did if you want to edit this
-- !timestamptz_microsecond_interval_scale_0 --
1 2024-01-03 05:07:09.123456+08:00 2024-01-01 01:01:00.876544+08:00 2024-01-02 05:07:09.123456+08:00 2024-01-02 01:01:00.876544+08:00 2024-01-02 03:07:09.123456+08:00 2024-01-02 03:01:00.876544+08:00 2024-01-02 03:04:09.123456+08:00 2024-01-02 03:04:00.876544+08:00 2024-01-02 03:04:05.123456+08:00 2024-01-02 03:04:04.876544+08:00 2024-01-02 03:04:05.123000+08:00 2024-01-02 03:04:04.877000+08:00

-- !timestamptz_microsecond_interval_scale_3 --
1 2024-01-03 05:07:09.246456+08:00 2024-01-01 01:01:00.999544+08:00 2024-01-02 05:07:09.246456+08:00 2024-01-02 01:01:00.999544+08:00 2024-01-02 03:07:09.246456+08:00 2024-01-02 03:01:00.999544+08:00 2024-01-02 03:04:09.246456+08:00 2024-01-02 03:04:00.999544+08:00 2024-01-02 03:04:05.246456+08:00 2024-01-02 03:04:04.999544+08:00 2024-01-02 03:04:05.246000+08:00 2024-01-02 03:04:05.000000+08:00

-- !timestamptz_microsecond_interval_scale_6 --
1 2024-01-03 05:07:09.246912+08:00 2024-01-01 01:01:01.000000+08:00 2024-01-02 05:07:09.246912+08:00 2024-01-02 01:01:01.000000+08:00 2024-01-02 03:07:09.246912+08:00 2024-01-02 03:01:01.000000+08:00 2024-01-02 03:04:09.246912+08:00 2024-01-02 03:04:01.000000+08:00 2024-01-02 03:04:05.246912+08:00 2024-01-02 03:04:05.000000+08:00 2024-01-02 03:04:05.246456+08:00 2024-01-02 03:04:05.000456+08:00

Original file line number Diff line number Diff line change
Expand Up @@ -331,13 +331,13 @@
2024-07-31T10:20:30.123456

-- !day_microsecond_add_11 --
2024-08-31T11:20:30.123456
2024-08-31 11:20:30.123456+08:00

-- !day_microsecond_add_12 --
2024-09-30T19:20:30.123456
2024-09-30 19:20:30.123456+08:00

-- !day_microsecond_add_13 --
2024-11-01T00:50:30.123456
2024-11-01 00:50:30.123456+08:00

-- !day_microsecond_sub_1 --
2023-01-01T01:01:00.555566
Expand All @@ -352,13 +352,13 @@
2017-02-27T13:39:29.876544

-- !day_microsecond_sub_5 --
2017-03-30T14:39:29.876544
2017-03-30 14:39:29.876544+08:00

-- !day_microsecond_sub_6 --
2017-04-29T22:39:29.876544
2017-04-29 22:39:29.876544+08:00

-- !day_microsecond_sub_7 --
2017-05-31T04:09:29.876544
2017-05-31 04:09:29.876544+08:00

-- !day_microsecond_extract_1 --
02 03:04:05.123456
Expand Down Expand Up @@ -550,13 +550,13 @@
2013-12-31T10:20:30.123456

-- !hour_microsecond_add_10 --
2013-11-30T11:20:30.123456
2013-11-30 11:20:30.123456+08:00

-- !hour_microsecond_add_11 --
2013-10-31T19:20:30.123456
2013-10-31 19:20:30.123456+08:00

-- !hour_microsecond_add_12 --
2013-10-01T00:50:30.123456
2013-10-01 00:50:30.123456+08:00

-- !hour_microsecond_sub_1 --
2023-01-02T00:33:25
Expand All @@ -571,13 +571,13 @@
2011-12-30T13:39:29.876544

-- !hour_microsecond_sub_5 --
2011-11-29T14:39:29.876544
2011-11-29 14:39:29.876544+08:00

-- !hour_microsecond_sub_6 --
2011-10-30T22:39:29.876544
2011-10-30 22:39:29.876544+08:00

-- !hour_microsecond_sub_7 --
2011-09-30T04:09:29.876544
2011-09-30 04:09:29.876544+08:00

-- !hour_microsecond_extract_1 --
03:04:05.123456
Expand Down Expand Up @@ -699,13 +699,13 @@
2007-12-30T00:10:20.123456

-- !minute_microsecond_add_11 --
2007-11-30T01:10:20.123456
2007-11-30 01:10:20.123456+08:00

-- !minute_microsecond_add_12 --
2007-10-31T09:10:20.123456
2007-10-31 09:10:20.123456+08:00

-- !minute_microsecond_add_13 --
2007-09-30T14:40:20.123456
2007-09-30 14:40:20.123456+08:00

-- !minute_microsecond_sub_1 --
2023-01-02T02:18:15
Expand All @@ -720,13 +720,13 @@
2005-12-30T23:49:39.876544

-- !minute_microsecond_sub_5 --
2005-11-30T00:49:39.876544
2005-11-30 00:49:39.876544+08:00

-- !minute_microsecond_sub_6 --
2005-10-31T08:49:39.876544
2005-10-31 08:49:39.876544+08:00

-- !minute_microsecond_sub_7 --
2005-09-30T14:19:39.876544
2005-09-30 14:19:39.876544+08:00

-- !minute_microsecond_extract_1 --
04:05.123456
Expand Down
Loading
Loading