adelapena commented on code in PR #2236:
URL: https://github.com/apache/cassandra/pull/2236#discussion_r1155904964
##########
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:
It should, good catch. I think I had a some point the inverse condition
(`useNewName`) and forgot to update on refactor. Incidentally it wasn't
breaking anything because in the end we add both names to the collection of
native functions and we don't make any distinction between them. I have fixed
it and added a new check to the existing test.
--
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]