flink-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fhueske <...@git.apache.org>
Subject [GitHub] flink pull request: [FLINK-3856] [core] Create types for java.sql....
Date Mon, 09 May 2016 12:59:24 GMT
Github user fhueske commented on a diff in the pull request:

    https://github.com/apache/flink/pull/1959#discussion_r62493248
  
    --- Diff: flink-core/src/main/java/org/apache/flink/api/common/typeutils/base/DateComparator.java
---
    @@ -59,15 +55,37 @@ public boolean isNormalizedKeyPrefixOnly(int keyBytes) {
     	}
     
     	@Override
    -	public void putNormalizedKey(Date lValue, MemorySegment target, int offset, int numBytes)
{
    -		long value = lValue.getTime() - Long.MIN_VALUE;
    -		
    +	public void putNormalizedKey(Date record, MemorySegment target, int offset, int numBytes)
{
    +		putNormalizedKeyDate(record, target, offset, numBytes);
    +	}
    +
    +	@Override
    +	public DateComparator duplicate() {
    +		return new DateComparator(ascendingComparison);
    +	}
    +
    +	// --------------------------------------------------------------------------------------------
    +	//                           Static Helpers for Date Comparison
    +	// --------------------------------------------------------------------------------------------
    +
    +	public static int compareSerializedDate(DataInputView firstSource, DataInputView secondSource,
    +			boolean ascendingComparison) throws IOException {
    +		final long l1 = firstSource.readLong();
    +		final long l2 = secondSource.readLong();
    +		final int comp = (l1 < l2 ? -1 : (l1 == l2 ? 0 : 1));
    +		return ascendingComparison ? comp : -comp;
    +	}
    +
    +	public static void putNormalizedKeyDate(Date record, MemorySegment target, int offset,
int numBytes) {
    +		final long value = record.getTime() - Long.MIN_VALUE;
    +
     		// see IntValue for an explanation of the logic
     		if (numBytes == 8) {
     			// default case, full normalized key
     			target.putLongBigEndian(offset, value);
     		}
     		else if (numBytes <= 0) {
    --- End diff --
    
    for `numBytes == 0`, the `numBytes < 8` branch would match and the loop would not be
entered, because `numBytes > 0`. So the check is not necessary and only adds overhead for
some cases. Actually, `numBytes` should be larger than `0` because otherwise calling this
method would not make sense.



---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message