bereng commented on code in PR #2236:
URL: https://github.com/apache/cassandra/pull/2236#discussion_r1155634167
##########
src/java/org/apache/cassandra/cql3/functions/TimeFcts.java:
##########
@@ -101,94 +136,154 @@ public ByteBuffer execute(ProtocolVersion
protocolVersion, List<ByteBuffer> para
return
TimeUUID.maxAtUnixMillis(TimestampType.instance.compose(bb).getTime()).toBytes();
}
- };
-
- /**
- * Creates a function that convert a value of the specified type into a
<code>DATE</code>.
- * @param type the temporal type
- * @return a function that convert a value of the specified type into a
<code>DATE</code>.
- */
- public static final NativeScalarFunction toDate(final TemporalType<?> type)
- {
- return new NativeScalarFunction("todate", SimpleDateType.instance, type)
- {
- public ByteBuffer execute(ProtocolVersion protocolVersion,
List<ByteBuffer> parameters)
- {
- ByteBuffer bb = parameters.get(0);
- if (bb == null || !bb.hasRemaining())
- return null;
-
- long millis = type.toTimeInMillis(bb);
- return SimpleDateType.instance.fromTimeInMillis(millis);
- }
-
- @Override
- public boolean isMonotonic()
- {
- return true;
- }
- };
- }
-
- /**
- * Creates a function that convert a value of the specified type into a
<code>TIMESTAMP</code>.
- * @param type the temporal type
- * @return a function that convert a value of the specified type into a
<code>TIMESTAMP</code>.
- */
- public static final NativeScalarFunction toTimestamp(final TemporalType<?>
type)
- {
- return new NativeScalarFunction("totimestamp", TimestampType.instance,
type)
- {
- public ByteBuffer execute(ProtocolVersion protocolVersion,
List<ByteBuffer> parameters)
- {
- ByteBuffer bb = parameters.get(0);
- if (bb == null || !bb.hasRemaining())
- return null;
-
- long millis = type.toTimeInMillis(bb);
- return TimestampType.instance.fromTimeInMillis(millis);
- }
-
- @Override
- public boolean isMonotonic()
- {
- return true;
- }
- };
- }
+
+ @Override
+ public NativeFunction withLegacyName()
+ {
+ return new MaxTimeuuidFunction(true);
+ }
+ }
+
+ /**
+ * Creates a function that converts a value of the specified type into a
{@code DATE}.
+ *
+ * @param type the temporal type
+ * @return a function that convert a value of the specified type into a
<code>DATE</code>.
+ */
+ public static NativeScalarFunction toDate(TemporalType<?> type)
+ {
+ return new ToDateFunction(type, false);
+ }
+
+ private static class ToDateFunction extends NativeScalarFunction
+ {
+ private final TemporalType<?> type;
+
+ public ToDateFunction(TemporalType<?> type, boolean useLegacyName)
+ {
+ super(useLegacyName ? "to_date" : "todate",
SimpleDateType.instance, type);
+ this.type = type;
+ }
+
+ @Override
+ public ByteBuffer execute(ProtocolVersion protocolVersion,
List<ByteBuffer> parameters)
+ {
+ ByteBuffer bb = parameters.get(0);
+ if (bb == null || !bb.hasRemaining())
+ return null;
+
+ long millis = type.toTimeInMillis(bb);
+ return SimpleDateType.instance.fromTimeInMillis(millis);
+ }
+
+ @Override
+ public boolean isMonotonic()
+ {
+ return true;
+ }
+
+ @Override
+ public NativeFunction withLegacyName()
+ {
+ return new ToDateFunction(type, true);
+ }
+ }
/**
- * Creates a function that convert a value of the specified type into an
UNIX timestamp.
+ * Creates a function that converts a value of the specified type into a
{@code TIMESTAMP}.
+ *
* @param type the temporal type
- * @return a function that convert a value of the specified type into an
UNIX timestamp.
+ * @return a function that convert a value of the specified type into a
{@code TIMESTAMP}.
*/
- public static final NativeScalarFunction toUnixTimestamp(final
TemporalType<?> type)
+ public static NativeScalarFunction toTimestamp(TemporalType<?> type)
{
- return new NativeScalarFunction("tounixtimestamp", LongType.instance,
type)
+ return new ToTimestampFunction(type, false);
+ }
+
+ private static class ToTimestampFunction extends NativeScalarFunction
+ {
+ private final TemporalType<?> type;
+
+ public ToTimestampFunction(TemporalType<?> type, boolean useLegacyName)
{
- public ByteBuffer execute(ProtocolVersion protocolVersion,
List<ByteBuffer> parameters)
- {
- ByteBuffer bb = parameters.get(0);
- if (bb == null || !bb.hasRemaining())
- return null;
-
- return ByteBufferUtil.bytes(type.toTimeInMillis(bb));
- }
-
- @Override
- public boolean isMonotonic()
- {
- return true;
- }
- };
+ super(useLegacyName ? "to_timestamp" : "totimestamp",
TimestampType.instance, type);
Review Comment:
Shouldn't this be reversed? There are a few like this one. I would suggest
reviewing all just in case if my comment is correct
--
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]