Skip to content

Conversation

@adutra
Copy link
Contributor

@adutra adutra commented Dec 22, 2016

No description provided.

@adutra adutra changed the base branch from 3.2.x to 3.x December 22, 2016 16:30
@adutra adutra added this to the 3.2.0 milestone Dec 22, 2016
@adutra adutra force-pushed the java1347 branch 2 times, most recently from ed34457 to ecbe5a7 Compare January 4, 2017 11:20
@adutra adutra self-assigned this Jan 4, 2017

/**
*/
public static class DurationType extends CustomType {
Copy link
Contributor

Choose a reason for hiding this comment

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

Just a reminder to either fill in or remove the javadoc comment

private Duration(int months, int days, long nanoseconds) {
// Makes sure that all the values are negatives if one of them is
assert (months >= 0 && days >= 0 && nanoseconds >= 0)
|| ((months <= 0 && days <= 0 && nanoseconds <= 0));
Copy link
Contributor

Choose a reason for hiding this comment

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

We should throw an IllegalArgumentException rather than using an assertion, this is called directly from newInstance which is public.

this.nanoseconds = nanoseconds;
}

public static Duration newInstance(int months, int days, long nanoseconds) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Needs a javadoc with an explanation on positive/negative arguments.

* </ul>
*
* @param input the <code>String</code> to convert
* @return a number of nanoseconds
Copy link
Contributor

Choose a reason for hiding this comment

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

Returns a Duration rather.

} else if (s.equals("ns")) {
return builder.addNanos(number);
}
throw new InvalidTypeException(String.format("Unknown duration symbol '%s'", symbol));
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if InvalidTypeException is the best error to throw here, it's closely related to the codec system but this class is not. Maybe IllegalArgumentException would be more appropriate.


private DurationType() {
super(Name.CUSTOM, "org.apache.cassandra.db.marshal.DurationType");
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: we could override toString() here, as this produces a slightly better output, for example in TableMetadata.toString() (although the full custom type name is valid and entirely compatible).

*
* @return the Duration type.
*/
public static DurationType duration() {
Copy link
Contributor

Choose a reason for hiding this comment

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

We might want to add a special case in DataType.decode() to return this singleton as well.

Currently it returns a CustomType instance that is not a DurationType. It appears for example in the column definitions of a prepared statement.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch, thanks.

Copy link
Contributor

@tolbertam tolbertam left a comment

Choose a reason for hiding this comment

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

Looks good to me! I updated DurationIntegrationTest to test with some sample values defined in the unit tests just to get a wider range of values tried at the integration level. I also tried testing using Durations as a bind parameter for comparison operations w/ CASSANDRA-11936 (i.e. WHERE reading_time < now() - ?) but that doesn't seem to work yet on the C* side.

.put("tinyint", tinyint())
.put("smallint", smallint())
// duration is not really a native CQL type, but appears as so in system tables
.put("duration", duration())
Copy link
Contributor

Choose a reason for hiding this comment

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

It turns out it will be in the system tables in C* 4.x (v5 protocol), but is a custom type in v4 protocol.

Copy link
Contributor

Choose a reason for hiding this comment

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

Nice, I remember that it was a similar story with UDTs being a custom type between a later version of 2.0 and 2.1 (with protocol v3). I'm glad that is the case.

@olim7t olim7t merged commit 87cbb37 into 3.x Jan 16, 2017
@olim7t olim7t deleted the java1347 branch January 16, 2017 18:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants