Skip to content

Conversation

@nastra
Copy link
Contributor

@nastra nastra commented Jul 5, 2022

The only warning that is left is this one from

interleavedBytes[interleaveByte] |=
(columnsBinary[sourceColumn][sourceByte] & 1 << sourceBit) >>> sourceBit << interleaveBit;

which seems legit as we're doing a lossy cast that would fail compilation if I rewrite it (https://errorprone.info/bugpattern/NarrowingCompoundAssignment):

> Task :iceberg-core:compileJava
/home/nastra/Development/workspace/iceberg/core/src/main/java/org/apache/iceberg/util/ZOrderByteUtils.java:182: warning: [NarrowingCompoundAssignment] Compound assignments from int to byte hide lossy casts
      interleavedBytes[interleaveByte] |=
                                       ^
    (see https://errorprone.info/bugpattern/NarrowingCompoundAssignment)
  Did you mean 'interleavedBytes[interleaveByte] = (byte) (interleavedBytes[interleaveByte] | (columnsBinary[sourceColumn][sourceByte] & 1 << sourceBit) >>> sourceBit << interleaveBit);'?

@nastra nastra force-pushed the error-prone-warnings-core-module branch from 2f8a09a to fa8d8c5 Compare July 5, 2022 08:44
@rdblue
Copy link
Contributor

rdblue commented Jul 5, 2022

Thanks, @nastra! Looks good to me.

@rdblue rdblue merged commit d563d6d into apache:master Jul 5, 2022
@nastra nastra deleted the error-prone-warnings-core-module branch July 5, 2022 18:15
@RussellSpitzer
Copy link
Member

The only warning that is left is this one from

interleavedBytes[interleaveByte] |=
(columnsBinary[sourceColumn][sourceByte] & 1 << sourceBit) >>> sourceBit << interleaveBit;

which seems legit as we're doing a lossy cast that would fail compilation if I rewrite it (https://errorprone.info/bugpattern/NarrowingCompoundAssignment):

> Task :iceberg-core:compileJava
/home/nastra/Development/workspace/iceberg/core/src/main/java/org/apache/iceberg/util/ZOrderByteUtils.java:182: warning: [NarrowingCompoundAssignment] Compound assignments from int to byte hide lossy casts
      interleavedBytes[interleaveByte] |=
                                       ^
    (see https://errorprone.info/bugpattern/NarrowingCompoundAssignment)
  Did you mean 'interleavedBytes[interleaveByte] = (byte) (interleavedBytes[interleaveByte] | (columnsBinary[sourceColumn][sourceByte] & 1 << sourceBit) >>> sourceBit << interleaveBit);'?

So this is as intended

The code is a bit complicated but a description would be

 interleavedBytes[interleaveByte] |=  //  if the target bit isn't set it
         (columnsBinary[sourceColumn][sourceByte] & 1 << sourceBit) >>> sourceBit  // Get the bit we are checking and move it all the way into the 1's place
<< interleaveBit;  // Move the bit back into our target position

So

(columnsBinary[sourceColumn][sourceByte] & 1 << sourceBit) 

Can only produce values between 0 and 128 (00000000), (00000001), (00000010), .... (10000000)

Then

>>> sourceBit 

Can only produce values between 0 and 1

then

<< interleaveBit

Can only produce values again between 0 and 128

Now if interleave bit or source bit were greater than 7 we would be in trouble but those are locked down

@nastra
Copy link
Contributor Author

nastra commented Jul 6, 2022

thanks for the clarification @RussellSpitzer. I suppressed the warning for NarrowingCompoundAssignment in #5212

namrathamyske pushed a commit to namrathamyske/iceberg that referenced this pull request Jul 10, 2022
namrathamyske pushed a commit to namrathamyske/iceberg that referenced this pull request Jul 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants