resolvedFields = fields();
+ for (PartitionField field : resolvedFields) {
if ("identity".equals(field.transform().toString())) {
sourceIds.add(field.sourceId());
}
@@ -295,6 +295,8 @@ public static Builder builderFor(Schema schema) {
*
* Call {@link #builderFor(Schema)} to create a new builder.
*/
+ // SuppressWarnings because builder classes should be allowed to copy names of passed in fields trivially.
+ @SuppressWarnings("checkstyle:HiddenField")
public static class Builder {
private final Schema schema;
private final List fields = Lists.newArrayList();
diff --git a/api/src/main/java/com/netflix/iceberg/RewriteFiles.java b/api/src/main/java/com/netflix/iceberg/RewriteFiles.java
index 1a8297298b7c..ca604e4cd8c7 100644
--- a/api/src/main/java/com/netflix/iceberg/RewriteFiles.java
+++ b/api/src/main/java/com/netflix/iceberg/RewriteFiles.java
@@ -34,12 +34,12 @@
* will throw a {@link ValidationException}.
*/
public interface RewriteFiles extends PendingUpdate {
- /**
- * Add a rewrite that replaces one set of files with another set that contains the same data.
- *
- * @param filesToDelete files that will be replaced (deleted), cannot be null or empty.
- * @param filesToAdd files that will be added, cannot be null or empty.
- * @return this for method chaining
- */
- RewriteFiles rewriteFiles(Set filesToDelete, Set filesToAdd);
+ /**
+ * Add a rewrite that replaces one set of files with another set that contains the same data.
+ *
+ * @param filesToDelete files that will be replaced (deleted), cannot be null or empty.
+ * @param filesToAdd files that will be added, cannot be null or empty.
+ * @return this for method chaining
+ */
+ RewriteFiles rewriteFiles(Set filesToDelete, Set filesToAdd);
}
diff --git a/api/src/main/java/com/netflix/iceberg/ScanTask.java b/api/src/main/java/com/netflix/iceberg/ScanTask.java
index a15fc18114b3..8c474bcdb82d 100644
--- a/api/src/main/java/com/netflix/iceberg/ScanTask.java
+++ b/api/src/main/java/com/netflix/iceberg/ScanTask.java
@@ -26,7 +26,7 @@
*/
public interface ScanTask extends Serializable {
/**
- * @return true if this is a {@link FileScanTask}, false otherwise.
+ * @return true if this is a {@link FileScanTask}, false otherwise
*/
default boolean isFileScanTask() {
return false;
diff --git a/api/src/main/java/com/netflix/iceberg/Schema.java b/api/src/main/java/com/netflix/iceberg/Schema.java
index 2ef872a38545..848f9c9e3a4a 100644
--- a/api/src/main/java/com/netflix/iceberg/Schema.java
+++ b/api/src/main/java/com/netflix/iceberg/Schema.java
@@ -89,14 +89,14 @@ public Map getAliases() {
/**
* Returns the underlying {@link Types.StructType struct type} for this schema.
*
- * @return the StructType version of this schema.
+ * @return the StructType version of this schema
*/
public Types.StructType asStruct() {
return struct;
}
/**
- * @return a List of the {@link Types.NestedField columns} in this Schema.
+ * @return a List of the {@link Types.NestedField columns} in this Schema
*/
public List columns() {
return struct.fields();
diff --git a/api/src/main/java/com/netflix/iceberg/Snapshot.java b/api/src/main/java/com/netflix/iceberg/Snapshot.java
index 89542dc3e32d..bd93aab42561 100644
--- a/api/src/main/java/com/netflix/iceberg/Snapshot.java
+++ b/api/src/main/java/com/netflix/iceberg/Snapshot.java
@@ -68,7 +68,7 @@ public interface Snapshot {
* The files returned include the following columns: file_path, file_format, partition,
* record_count, and file_size_in_bytes. Other columns will be null.
*
- * @return all files added to the table in this snapshot.
+ * @return all files added to the table in this snapshot
*/
Iterable addedFiles();
@@ -78,7 +78,7 @@ public interface Snapshot {
* The files returned include the following columns: file_path, file_format, partition,
* record_count, and file_size_in_bytes. Other columns will be null.
*
- * @return all files deleted from the table in this snapshot.
+ * @return all files deleted from the table in this snapshot
*/
Iterable deletedFiles();
diff --git a/api/src/main/java/com/netflix/iceberg/Table.java b/api/src/main/java/com/netflix/iceberg/Table.java
index c785f8e0d2ce..30d53b445ecf 100644
--- a/api/src/main/java/com/netflix/iceberg/Table.java
+++ b/api/src/main/java/com/netflix/iceberg/Table.java
@@ -71,14 +71,14 @@ public interface Table {
/**
* Get the current {@link Snapshot snapshot} for this table.
*
- * @return the current table Snapshot.
+ * @return the current table Snapshot
*/
Snapshot currentSnapshot();
/**
* Get the {@link Snapshot snapshots} of this table.
*
- * @return an Iterable of snapshots of this table.
+ * @return an Iterable of snapshots of this table
*/
Iterable snapshots();
diff --git a/api/src/main/java/com/netflix/iceberg/TableScan.java b/api/src/main/java/com/netflix/iceberg/TableScan.java
index 11df3be609ad..f02e985aaa43 100644
--- a/api/src/main/java/com/netflix/iceberg/TableScan.java
+++ b/api/src/main/java/com/netflix/iceberg/TableScan.java
@@ -96,6 +96,13 @@ default TableScan select(String... columns) {
*/
TableScan filter(Expression expr);
+ /**
+ * Returns this scan's filter {@link Expression}.
+ *
+ * @return this scan's filter expression
+ */
+ Expression filter();
+
/**
* Plan the {@link FileScanTask files} that will be read by this scan.
*
@@ -129,11 +136,4 @@ default TableScan select(String... columns) {
* @return this scan's projection schema
*/
Schema schema();
-
- /**
- * Returns this scan's filter {@link Expression}.
- *
- * @return this scan's filter expression
- */
- Expression filter();
}
diff --git a/api/src/main/java/com/netflix/iceberg/exceptions/RuntimeIOException.java b/api/src/main/java/com/netflix/iceberg/exceptions/RuntimeIOException.java
index 837b018d1cd4..8c3a4386d971 100644
--- a/api/src/main/java/com/netflix/iceberg/exceptions/RuntimeIOException.java
+++ b/api/src/main/java/com/netflix/iceberg/exceptions/RuntimeIOException.java
@@ -25,12 +25,12 @@
* Exception used to wrap {@link IOException} as a {@link RuntimeException} and add context.
*/
public class RuntimeIOException extends RuntimeException {
- public RuntimeIOException(IOException e) {
- super(e);
+ public RuntimeIOException(IOException cause) {
+ super(cause);
}
- public RuntimeIOException(IOException e, String message, Object... args) {
- super(String.format(message, args), e);
+ public RuntimeIOException(IOException cause, String message, Object... args) {
+ super(String.format(message, args), cause);
}
public RuntimeIOException(String message, Object...args) {
diff --git a/api/src/main/java/com/netflix/iceberg/expressions/BoundReference.java b/api/src/main/java/com/netflix/iceberg/expressions/BoundReference.java
index 5a836504bcad..4458ec80f55c 100644
--- a/api/src/main/java/com/netflix/iceberg/expressions/BoundReference.java
+++ b/api/src/main/java/com/netflix/iceberg/expressions/BoundReference.java
@@ -36,15 +36,15 @@ public class BoundReference implements Reference {
this.type = struct.fields().get(pos).type();
}
- private int find(int fieldId, Types.StructType struct) {
+ private int find(int fieldIdToFind, Types.StructType struct) {
List fields = struct.fields();
for (int i = 0; i < fields.size(); i += 1) {
- if (fields.get(i).fieldId() == fieldId) {
+ if (fields.get(i).fieldId() == fieldIdToFind) {
return i;
}
}
throw new ValidationException(
- "Cannot find top-level field id %d in struct: %s", fieldId, struct);
+ "Cannot find top-level field id %d in struct: %s", fieldIdToFind, struct);
}
public Type type() {
diff --git a/api/src/main/java/com/netflix/iceberg/expressions/Expression.java b/api/src/main/java/com/netflix/iceberg/expressions/Expression.java
index d499b7651aa1..7e727eadd9a3 100644
--- a/api/src/main/java/com/netflix/iceberg/expressions/Expression.java
+++ b/api/src/main/java/com/netflix/iceberg/expressions/Expression.java
@@ -100,12 +100,12 @@ public Operation flipLR() {
}
/**
- * @return the operation for an expression node.
+ * @return the operation for an expression node
*/
Operation op();
/**
- * @return the negation of this expression, equivalent to not(this).
+ * @return the negation of this expression, equivalent to not(this)
*/
default Expression negate() {
throw new UnsupportedOperationException(String.format("%s cannot be negated", this));
diff --git a/api/src/main/java/com/netflix/iceberg/expressions/ExpressionVisitors.java b/api/src/main/java/com/netflix/iceberg/expressions/ExpressionVisitors.java
index 4531b8cbe78d..c05858681cd1 100644
--- a/api/src/main/java/com/netflix/iceberg/expressions/ExpressionVisitors.java
+++ b/api/src/main/java/com/netflix/iceberg/expressions/ExpressionVisitors.java
@@ -23,6 +23,9 @@
* Utils for traversing {@link Expression expressions}.
*/
public class ExpressionVisitors {
+
+ private ExpressionVisitors() {}
+
public abstract static class ExpressionVisitor {
public R alwaysTrue() {
return null;
diff --git a/api/src/main/java/com/netflix/iceberg/expressions/Expressions.java b/api/src/main/java/com/netflix/iceberg/expressions/Expressions.java
index 670789b97381..38aaff3494a6 100644
--- a/api/src/main/java/com/netflix/iceberg/expressions/Expressions.java
+++ b/api/src/main/java/com/netflix/iceberg/expressions/Expressions.java
@@ -19,6 +19,15 @@
package com.netflix.iceberg.expressions;
+import static com.netflix.iceberg.expressions.Expression.Operation.EQ;
+import static com.netflix.iceberg.expressions.Expression.Operation.GT;
+import static com.netflix.iceberg.expressions.Expression.Operation.GT_EQ;
+import static com.netflix.iceberg.expressions.Expression.Operation.IS_NULL;
+import static com.netflix.iceberg.expressions.Expression.Operation.LT;
+import static com.netflix.iceberg.expressions.Expression.Operation.LT_EQ;
+import static com.netflix.iceberg.expressions.Expression.Operation.NOT_EQ;
+import static com.netflix.iceberg.expressions.Expression.Operation.NOT_NULL;
+
import com.google.common.base.Preconditions;
import com.netflix.iceberg.expressions.Expression.Operation;
@@ -68,51 +77,51 @@ public static Expression not(Expression child) {
}
public static UnboundPredicate isNull(String name) {
- return new UnboundPredicate<>(Expression.Operation.IS_NULL, ref(name));
+ return new UnboundPredicate<>(IS_NULL, ref(name));
}
public static UnboundPredicate notNull(String name) {
- return new UnboundPredicate<>(Expression.Operation.NOT_NULL, ref(name));
+ return new UnboundPredicate<>(NOT_NULL, ref(name));
}
public static UnboundPredicate lessThan(String name, T value) {
- return new UnboundPredicate<>(Expression.Operation.LT, ref(name), value);
+ return new UnboundPredicate<>(LT, ref(name), value);
}
public static UnboundPredicate lessThanOrEqual(String name, T value) {
- return new UnboundPredicate<>(Expression.Operation.LT_EQ, ref(name), value);
+ return new UnboundPredicate<>(LT_EQ, ref(name), value);
}
public static UnboundPredicate greaterThan(String name, T value) {
- return new UnboundPredicate<>(Expression.Operation.GT, ref(name), value);
+ return new UnboundPredicate<>(GT, ref(name), value);
}
public static UnboundPredicate greaterThanOrEqual(String name, T value) {
- return new UnboundPredicate<>(Expression.Operation.GT_EQ, ref(name), value);
+ return new UnboundPredicate<>(GT_EQ, ref(name), value);
}
public static UnboundPredicate equal(String name, T value) {
- return new UnboundPredicate<>(Expression.Operation.EQ, ref(name), value);
+ return new UnboundPredicate<>(EQ, ref(name), value);
}
public static UnboundPredicate notEqual(String name, T value) {
- return new UnboundPredicate<>(Expression.Operation.NOT_EQ, ref(name), value);
+ return new UnboundPredicate<>(NOT_EQ, ref(name), value);
}
public static UnboundPredicate predicate(Operation op, String name, T value) {
- Preconditions.checkArgument(op != Operation.IS_NULL && op != Operation.NOT_NULL,
+ Preconditions.checkArgument(op != IS_NULL && op != NOT_NULL,
"Cannot create %s predicate inclusive a value", op);
return new UnboundPredicate<>(op, ref(name), value);
}
public static UnboundPredicate predicate(Operation op, String name, Literal lit) {
- Preconditions.checkArgument(op != Operation.IS_NULL && op != Operation.NOT_NULL,
+ Preconditions.checkArgument(op != IS_NULL && op != NOT_NULL,
"Cannot create %s predicate inclusive a value", op);
return new UnboundPredicate<>(op, ref(name), lit);
}
public static UnboundPredicate predicate(Operation op, String name) {
- Preconditions.checkArgument(op == Operation.IS_NULL || op == Operation.NOT_NULL,
+ Preconditions.checkArgument(op == IS_NULL || op == NOT_NULL,
"Cannot create %s predicate without a value", op);
return new UnboundPredicate<>(op, ref(name));
}
diff --git a/api/src/main/java/com/netflix/iceberg/expressions/InclusiveManifestEvaluator.java b/api/src/main/java/com/netflix/iceberg/expressions/InclusiveManifestEvaluator.java
index cac617d777a1..10285fa3adb3 100644
--- a/api/src/main/java/com/netflix/iceberg/expressions/InclusiveManifestEvaluator.java
+++ b/api/src/main/java/com/netflix/iceberg/expressions/InclusiveManifestEvaluator.java
@@ -19,6 +19,8 @@
package com.netflix.iceberg.expressions;
+import static com.netflix.iceberg.expressions.Expressions.rewriteNot;
+
import com.netflix.iceberg.ManifestFile;
import com.netflix.iceberg.ManifestFile.PartitionFieldSummary;
import com.netflix.iceberg.PartitionSpec;
@@ -28,8 +30,6 @@
import java.nio.ByteBuffer;
import java.util.List;
-import static com.netflix.iceberg.expressions.Expressions.rewriteNot;
-
/**
* Evaluates an {@link Expression} on a {@link ManifestFile} to test whether the file contains
* matching partitions.
@@ -61,7 +61,7 @@ public InclusiveManifestEvaluator(PartitionSpec spec, Expression rowFilter) {
* Test whether the file may contain records that match the expression.
*
* @param manifest a manifest file
- * @return false if the file cannot contain rows that match the expression, true otherwise.
+ * @return false if the file cannot contain rows that match the expression, true otherwise
*/
public boolean eval(ManifestFile manifest) {
return visitor().eval(manifest);
diff --git a/api/src/main/java/com/netflix/iceberg/expressions/InclusiveMetricsEvaluator.java b/api/src/main/java/com/netflix/iceberg/expressions/InclusiveMetricsEvaluator.java
index 26c17e4f6078..8876da7e2ec9 100644
--- a/api/src/main/java/com/netflix/iceberg/expressions/InclusiveMetricsEvaluator.java
+++ b/api/src/main/java/com/netflix/iceberg/expressions/InclusiveMetricsEvaluator.java
@@ -29,8 +29,6 @@
import java.nio.ByteBuffer;
import java.util.Map;
-import static com.netflix.iceberg.expressions.Expressions.rewriteNot;
-
/**
* Evaluates an {@link Expression} on a {@link DataFile} to test whether rows in the file may match.
*
@@ -56,14 +54,14 @@ private MetricsEvalVisitor visitor() {
public InclusiveMetricsEvaluator(Schema schema, Expression unbound) {
this.schema = schema;
this.struct = schema.asStruct();
- this.expr = Binder.bind(struct, rewriteNot(unbound));
+ this.expr = Binder.bind(struct, Expressions.rewriteNot(unbound));
}
/**
* Test whether the file may contain records that match the expression.
*
* @param file a data file
- * @return false if the file cannot contain rows that match the expression, true otherwise.
+ * @return false if the file cannot contain rows that match the expression, true otherwise
*/
public boolean eval(DataFile file) {
// TODO: detect the case where a column is missing from the file using file's max field id.
@@ -140,9 +138,11 @@ public Boolean notNull(BoundReference ref) {
Preconditions.checkNotNull(struct.field(id),
"Cannot filter by nested column: %s", schema.findField(id));
- if (valueCounts != null && valueCounts.containsKey(id) &&
- nullCounts != null && nullCounts.containsKey(id) &&
- valueCounts.get(id) - nullCounts.get(id) == 0) {
+ if (valueCounts != null
+ && valueCounts.containsKey(id)
+ && nullCounts != null
+ && nullCounts.containsKey(id)
+ && valueCounts.get(id) - nullCounts.get(id) == 0) {
return ROWS_CANNOT_MATCH;
}
diff --git a/api/src/main/java/com/netflix/iceberg/expressions/Literal.java b/api/src/main/java/com/netflix/iceberg/expressions/Literal.java
index 69a2623303ae..abf4c5e0651f 100644
--- a/api/src/main/java/com/netflix/iceberg/expressions/Literal.java
+++ b/api/src/main/java/com/netflix/iceberg/expressions/Literal.java
@@ -27,7 +27,7 @@
import java.util.UUID;
/**
- * Represents a literal fixed value in an expression predicate
+ * Represents a literal fixed value in an expression predicate.
* @param The Java type of the value wrapped by a {@link Literal}
*/
public interface Literal extends Serializable {
@@ -56,7 +56,7 @@ static Literal of(CharSequence value) {
}
static Literal of(UUID value) {
- return new Literals.UUIDLiteral(value);
+ return new Literals.UuidLiteral(value);
}
static Literal of(byte[] value) {
diff --git a/api/src/main/java/com/netflix/iceberg/expressions/Literals.java b/api/src/main/java/com/netflix/iceberg/expressions/Literals.java
index f4e5d4e74446..e3ca899e8ed1 100644
--- a/api/src/main/java/com/netflix/iceberg/expressions/Literals.java
+++ b/api/src/main/java/com/netflix/iceberg/expressions/Literals.java
@@ -52,7 +52,8 @@ private Literals() {
* @param Java type of value
* @return a Literal for the given value
*/
- @SuppressWarnings("unchecked")
+ // Ignore cyclomatic complexity because of the instanceof branches.
+ @SuppressWarnings({"unchecked", "checkstyle:CyclomaticComplexity"})
static Literal from(T value) {
Preconditions.checkNotNull(value, "Cannot create expression literal from null");
@@ -69,7 +70,7 @@ static Literal from(T value) {
} else if (value instanceof CharSequence) {
return (Literal) new Literals.StringLiteral((CharSequence) value);
} else if (value instanceof UUID) {
- return (Literal) new Literals.UUIDLiteral((UUID) value);
+ return (Literal) new UuidLiteral((UUID) value);
} else if (value instanceof byte[]) {
return (Literal) new Literals.FixedLiteral(ByteBuffer.wrap((byte[]) value));
} else if (value instanceof ByteBuffer) {
@@ -116,7 +117,7 @@ private abstract static class ComparableLiteral> extends
private static final Comparator extends Comparable> CMP =
Comparators.nullsFirst().thenComparing(Comparator.naturalOrder());
- public ComparableLiteral(C value) {
+ ComparableLiteral(C value) {
super(value);
}
@@ -340,7 +341,7 @@ static class TimeLiteral extends ComparableLiteral {
@SuppressWarnings("unchecked")
public Literal to(Type type) {
if (type.typeId() == Type.TypeID.TIME) {
- return (Literal) this ;
+ return (Literal) this;
}
return null;
}
@@ -425,7 +426,7 @@ public Literal to(Type type) {
return (Literal) this;
case UUID:
- return (Literal) new UUIDLiteral(UUID.fromString(value().toString()));
+ return (Literal) new UuidLiteral(UUID.fromString(value().toString()));
case DECIMAL:
int scale = ((Types.DecimalType) type).scale();
@@ -451,8 +452,8 @@ public String toString() {
}
}
- static class UUIDLiteral extends ComparableLiteral {
- UUIDLiteral(UUID value) {
+ static class UuidLiteral extends ComparableLiteral {
+ UuidLiteral(UUID value) {
super(value);
}
diff --git a/api/src/main/java/com/netflix/iceberg/expressions/NamedReference.java b/api/src/main/java/com/netflix/iceberg/expressions/NamedReference.java
index 5e4ec1e7a592..ce7c964be2f8 100644
--- a/api/src/main/java/com/netflix/iceberg/expressions/NamedReference.java
+++ b/api/src/main/java/com/netflix/iceberg/expressions/NamedReference.java
@@ -22,7 +22,7 @@
import com.google.common.base.Preconditions;
public class NamedReference implements Reference {
- public final String name;
+ private final String name;
NamedReference(String name) {
Preconditions.checkNotNull(name, "Name cannot be null");
diff --git a/api/src/main/java/com/netflix/iceberg/expressions/Projections.java b/api/src/main/java/com/netflix/iceberg/expressions/Projections.java
index d9da0532c82f..266ce5448936 100644
--- a/api/src/main/java/com/netflix/iceberg/expressions/Projections.java
+++ b/api/src/main/java/com/netflix/iceberg/expressions/Projections.java
@@ -19,9 +19,9 @@
package com.netflix.iceberg.expressions;
-import com.netflix.iceberg.expressions.ExpressionVisitors.ExpressionVisitor;
import com.netflix.iceberg.PartitionField;
import com.netflix.iceberg.PartitionSpec;
+import com.netflix.iceberg.expressions.ExpressionVisitors.ExpressionVisitor;
import com.netflix.iceberg.transforms.Transform;
/**
@@ -43,7 +43,7 @@ private Projections() {
* A strict projection guarantees that if a partition matches a projected expression, then all
* rows in that partition will match the original expression.
*/
- public static abstract class ProjectionEvaluator extends ExpressionVisitor {
+ public abstract static class ProjectionEvaluator extends ExpressionVisitor {
/**
* Project the given row expression to a partition expression.
*
@@ -92,7 +92,7 @@ public static ProjectionEvaluator strict(PartitionSpec spec) {
}
private static class BaseProjectionEvaluator extends ProjectionEvaluator {
- final PartitionSpec spec;
+ private final PartitionSpec spec;
private BaseProjectionEvaluator(PartitionSpec spec) {
this.spec = spec;
@@ -143,6 +143,10 @@ public Expression predicate(UnboundPredicate pred) {
return bound;
}
+
+ protected PartitionSpec spec() {
+ return spec;
+ }
}
private static class InclusiveProjection extends BaseProjectionEvaluator {
@@ -153,7 +157,7 @@ private InclusiveProjection(PartitionSpec spec) {
@Override
@SuppressWarnings("unchecked")
public Expression predicate(BoundPredicate pred) {
- PartitionField part = spec.getFieldBySourceId(pred.ref().fieldId());
+ PartitionField part = spec().getFieldBySourceId(pred.ref().fieldId());
if (part == null) {
// the predicate has no partition column
return alwaysTrue();
@@ -178,7 +182,7 @@ private StrictProjection(PartitionSpec spec) {
@Override
@SuppressWarnings("unchecked")
public Expression predicate(BoundPredicate pred) {
- PartitionField part = spec.getFieldBySourceId(pred.ref().fieldId());
+ PartitionField part = spec().getFieldBySourceId(pred.ref().fieldId());
if (part == null) {
// the predicate has no partition column
return alwaysFalse();
diff --git a/api/src/main/java/com/netflix/iceberg/expressions/ResidualEvaluator.java b/api/src/main/java/com/netflix/iceberg/expressions/ResidualEvaluator.java
index 290ae4afe034..80a99b07c778 100644
--- a/api/src/main/java/com/netflix/iceberg/expressions/ResidualEvaluator.java
+++ b/api/src/main/java/com/netflix/iceberg/expressions/ResidualEvaluator.java
@@ -19,9 +19,9 @@
package com.netflix.iceberg.expressions;
-import com.netflix.iceberg.StructLike;
import com.netflix.iceberg.PartitionField;
import com.netflix.iceberg.PartitionSpec;
+import com.netflix.iceberg.StructLike;
import com.netflix.iceberg.transforms.Transform;
import java.io.Serializable;
import java.util.Comparator;
@@ -76,8 +76,8 @@ public Expression residualFor(StructLike partitionData) {
private class ResidualVisitor extends ExpressionVisitors.BoundExpressionVisitor {
private StructLike struct;
- private Expression eval(StructLike struct) {
- this.struct = struct;
+ private Expression eval(StructLike newStruct) {
+ this.struct = newStruct;
return ExpressionVisitors.visit(expr, this);
}
diff --git a/api/src/main/java/com/netflix/iceberg/expressions/SerializationProxies.java b/api/src/main/java/com/netflix/iceberg/expressions/SerializationProxies.java
index deac29ee170a..eb90a8fc41fc 100644
--- a/api/src/main/java/com/netflix/iceberg/expressions/SerializationProxies.java
+++ b/api/src/main/java/com/netflix/iceberg/expressions/SerializationProxies.java
@@ -35,10 +35,8 @@ static class ConstantExpressionProxy implements Serializable {
/**
* Constructor for Java serialization.
*/
- public ConstantExpressionProxy() {
- }
- public ConstantExpressionProxy(boolean trueOrFalse) {
+ ConstantExpressionProxy(boolean trueOrFalse) {
this.trueOrFalse = trueOrFalse;
}
@@ -63,7 +61,7 @@ static class BinaryLiteralProxy extends FixedLiteralProxy {
}
Object readResolve() throws ObjectStreamException {
- return new Literals.BinaryLiteral(ByteBuffer.wrap(bytes));
+ return new Literals.BinaryLiteral(ByteBuffer.wrap(bytes()));
}
}
@@ -71,7 +69,7 @@ Object readResolve() throws ObjectStreamException {
* Replacement for FixedLiteral in Java Serialization.
*/
static class FixedLiteralProxy implements Serializable {
- protected byte[] bytes;
+ private byte[] bytes;
/**
* Constructor for Java serialization.
@@ -87,5 +85,9 @@ static class FixedLiteralProxy implements Serializable {
Object readResolve() throws ObjectStreamException {
return new Literals.FixedLiteral(ByteBuffer.wrap(bytes));
}
+
+ protected byte[] bytes() {
+ return bytes;
+ }
}
}
diff --git a/api/src/main/java/com/netflix/iceberg/expressions/StrictMetricsEvaluator.java b/api/src/main/java/com/netflix/iceberg/expressions/StrictMetricsEvaluator.java
index d3fa1df5321a..1b6ccb67eb8a 100644
--- a/api/src/main/java/com/netflix/iceberg/expressions/StrictMetricsEvaluator.java
+++ b/api/src/main/java/com/netflix/iceberg/expressions/StrictMetricsEvaluator.java
@@ -29,8 +29,6 @@
import java.nio.ByteBuffer;
import java.util.Map;
-import static com.netflix.iceberg.expressions.Expressions.rewriteNot;
-
/**
* Evaluates an {@link Expression} on a {@link DataFile} to test whether all rows in the file match.
*
@@ -57,14 +55,14 @@ private MetricsEvalVisitor visitor() {
public StrictMetricsEvaluator(Schema schema, Expression unbound) {
this.schema = schema;
this.struct = schema.asStruct();
- this.expr = Binder.bind(struct, rewriteNot(unbound));
+ this.expr = Binder.bind(struct, Expressions.rewriteNot(unbound));
}
/**
* Test whether the file may contain records that match the expression.
*
* @param file a data file
- * @return false if the file cannot contain rows that match the expression, true otherwise.
+ * @return false if the file cannot contain rows that match the expression, true otherwise
*/
public boolean eval(DataFile file) {
// TODO: detect the case where a column is missing from the file using file's max field id.
@@ -126,9 +124,11 @@ public Boolean isNull(BoundReference ref) {
Preconditions.checkNotNull(struct.field(id),
"Cannot filter by nested column: %s", schema.findField(id));
- if (valueCounts != null && valueCounts.containsKey(id) &&
- nullCounts != null && nullCounts.containsKey(id) &&
- valueCounts.get(id) - nullCounts.get(id) == 0) {
+ if (valueCounts != null
+ && valueCounts.containsKey(id)
+ && nullCounts != null
+ && nullCounts.containsKey(id)
+ && valueCounts.get(id) - nullCounts.get(id) == 0) {
return ROWS_MUST_MATCH;
}
@@ -233,8 +233,10 @@ public Boolean eq(BoundReference ref, Literal lit) {
Types.NestedField field = struct.field(id);
Preconditions.checkNotNull(field, "Cannot filter by nested column: %s", schema.findField(id));
- if (lowerBounds != null && lowerBounds.containsKey(id) &&
- upperBounds != null && upperBounds.containsKey(id)) {
+ if (lowerBounds != null
+ && lowerBounds.containsKey(id)
+ && upperBounds != null
+ && upperBounds.containsKey(id)) {
T lower = Conversions.fromByteBuffer(struct.field(id).type(), lowerBounds.get(id));
int cmp = lit.comparator().compare(lower, lit.value());
diff --git a/api/src/main/java/com/netflix/iceberg/expressions/UnboundPredicate.java b/api/src/main/java/com/netflix/iceberg/expressions/UnboundPredicate.java
index 3523d1d4f9c0..6246c0081dac 100644
--- a/api/src/main/java/com/netflix/iceberg/expressions/UnboundPredicate.java
+++ b/api/src/main/java/com/netflix/iceberg/expressions/UnboundPredicate.java
@@ -22,9 +22,6 @@
import com.netflix.iceberg.exceptions.ValidationException;
import com.netflix.iceberg.types.Types;
-import static com.netflix.iceberg.expressions.Expression.Operation.IS_NULL;
-import static com.netflix.iceberg.expressions.Expression.Operation.NOT_NULL;
-
public class UnboundPredicate extends Predicate {
UnboundPredicate(Operation op, NamedReference namedRef, T value) {
@@ -55,12 +52,12 @@ public Expression bind(Types.StructType struct) {
if (field.isRequired()) {
return Expressions.alwaysFalse();
}
- return new BoundPredicate<>(IS_NULL, new BoundReference<>(struct, field.fieldId()));
+ return new BoundPredicate<>(Expression.Operation.IS_NULL, new BoundReference<>(struct, field.fieldId()));
case NOT_NULL:
if (field.isRequired()) {
return Expressions.alwaysTrue();
}
- return new BoundPredicate<>(NOT_NULL, new BoundReference<>(struct, field.fieldId()));
+ return new BoundPredicate<>(Expression.Operation.NOT_NULL, new BoundReference<>(struct, field.fieldId()));
default:
throw new ValidationException("Operation must be IS_NULL or NOT_NULL");
}
diff --git a/api/src/main/java/com/netflix/iceberg/io/CloseableGroup.java b/api/src/main/java/com/netflix/iceberg/io/CloseableGroup.java
index 1f6224691cf0..c774dbd835a5 100644
--- a/api/src/main/java/com/netflix/iceberg/io/CloseableGroup.java
+++ b/api/src/main/java/com/netflix/iceberg/io/CloseableGroup.java
@@ -23,10 +23,10 @@
import java.io.Closeable;
import java.io.IOException;
import java.util.Iterator;
-import java.util.LinkedList;
+import java.util.Queue;
public abstract class CloseableGroup implements Closeable {
- private final LinkedList closeables = Lists.newLinkedList();
+ private final Queue closeables = Lists.newLinkedList();
protected void addCloseable(Closeable closeable) {
closeables.add(closeable);
@@ -35,7 +35,7 @@ protected void addCloseable(Closeable closeable) {
@Override
public void close() throws IOException {
while (!closeables.isEmpty()) {
- Closeable toClose = closeables.removeFirst();
+ Closeable toClose = closeables.remove();
if (toClose != null) {
toClose.close();
}
@@ -45,7 +45,7 @@ public void close() throws IOException {
static class ClosingIterable extends CloseableGroup implements CloseableIterable {
private final Iterable iterable;
- public ClosingIterable(Iterable iterable, Iterable closeables) {
+ ClosingIterable(Iterable iterable, Iterable closeables) {
this.iterable = iterable;
for (Closeable closeable : closeables) {
addCloseable(closeable);
diff --git a/api/src/main/java/com/netflix/iceberg/io/FileAppender.java b/api/src/main/java/com/netflix/iceberg/io/FileAppender.java
index 6f5188697f2a..59f6b8b85507 100644
--- a/api/src/main/java/com/netflix/iceberg/io/FileAppender.java
+++ b/api/src/main/java/com/netflix/iceberg/io/FileAppender.java
@@ -37,7 +37,7 @@ default void addAll(Iterable values) {
}
/**
- * @return {@link Metrics} for this file. Only valid after the file is closed.
+ * @return {@link Metrics} for this file. Only valid after the file is closed
*/
Metrics metrics();
}
diff --git a/api/src/main/java/com/netflix/iceberg/io/InputFile.java b/api/src/main/java/com/netflix/iceberg/io/InputFile.java
index 91444f726b65..f323f81a4f77 100644
--- a/api/src/main/java/com/netflix/iceberg/io/InputFile.java
+++ b/api/src/main/java/com/netflix/iceberg/io/InputFile.java
@@ -35,7 +35,7 @@ public interface InputFile {
long getLength();
/**
- * Opens a new {@link SeekableInputStream} for the underlying data file
+ * Opens a new {@link SeekableInputStream} for the underlying data file.
*
* @return a seekable stream for reading the file
* @throws RuntimeIOException If the implementation throws an {@link IOException}
diff --git a/api/src/main/java/com/netflix/iceberg/transforms/Bucket.java b/api/src/main/java/com/netflix/iceberg/transforms/Bucket.java
index 4f9c2fda5f49..862dd9406d14 100644
--- a/api/src/main/java/com/netflix/iceberg/transforms/Bucket.java
+++ b/api/src/main/java/com/netflix/iceberg/transforms/Bucket.java
@@ -20,7 +20,6 @@
package com.netflix.iceberg.transforms;
import com.google.common.annotations.VisibleForTesting;
-import com.google.common.base.Charsets;
import com.google.common.base.Objects;
import com.google.common.collect.Sets;
import com.google.common.hash.HashFunction;
@@ -33,46 +32,45 @@
import java.math.BigDecimal;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
+import java.nio.charset.StandardCharsets;
import java.util.Set;
import java.util.UUID;
-import static com.netflix.iceberg.types.Type.TypeID;
-
abstract class Bucket implements Transform {
private static final HashFunction MURMUR3 = Hashing.murmur3_32();
@SuppressWarnings("unchecked")
- static Bucket get(Type type, int N) {
+ static Bucket get(Type type, int numBuckets) {
switch (type.typeId()) {
case DATE:
case INTEGER:
- return (Bucket) new BucketInteger(N);
+ return (Bucket) new BucketInteger(numBuckets);
case TIME:
case TIMESTAMP:
case LONG:
- return (Bucket) new BucketLong(N);
+ return (Bucket) new BucketLong(numBuckets);
case DECIMAL:
- return (Bucket) new BucketDecimal(N);
+ return (Bucket) new BucketDecimal(numBuckets);
case STRING:
- return (Bucket) new BucketString(N);
+ return (Bucket) new BucketString(numBuckets);
case FIXED:
case BINARY:
- return (Bucket) new BucketByteBuffer(N);
+ return (Bucket) new BucketByteBuffer(numBuckets);
case UUID:
- return (Bucket) new BucketUUID(N);
+ return (Bucket) new BucketUuid(numBuckets);
default:
throw new IllegalArgumentException("Cannot bucket by type: " + type);
}
}
- private final int N;
+ private final int numBuckets;
- private Bucket(int N) {
- this.N = N;
+ private Bucket(int numBuckets) {
+ this.numBuckets = numBuckets;
}
public Integer numBuckets() {
- return N;
+ return numBuckets;
}
@VisibleForTesting
@@ -80,30 +78,30 @@ public Integer numBuckets() {
@Override
public Integer apply(T value) {
- return (hash(value) & Integer.MAX_VALUE) % N;
+ return (hash(value) & Integer.MAX_VALUE) % numBuckets;
}
@Override
- public boolean equals(Object o) {
- if (this == o) {
+ public boolean equals(Object other) {
+ if (this == other) {
return true;
}
- if (o == null || getClass() != o.getClass()) {
+ if (other == null || getClass() != other.getClass()) {
return false;
}
- Bucket> bucket = (Bucket>) o;
- return N == bucket.N;
+ Bucket> bucket = (Bucket>) other;
+ return numBuckets == bucket.numBuckets;
}
@Override
public int hashCode() {
- return Objects.hashCode(N);
+ return Objects.hashCode(numBuckets);
}
@Override
public String toString() {
- return "bucket[" + N + "]";
+ return "bucket[" + numBuckets + "]";
}
@Override
@@ -141,8 +139,8 @@ public Type getResultType(Type sourceType) {
}
private static class BucketInteger extends Bucket {
- private BucketInteger(int N) {
- super(N);
+ private BucketInteger(int numBuckets) {
+ super(numBuckets);
}
public int hash(Integer value) {
@@ -151,13 +149,13 @@ public int hash(Integer value) {
@Override
public boolean canTransform(Type type) {
- return type.typeId() == TypeID.INTEGER || type.typeId() == TypeID.DATE;
+ return type.typeId() == Type.TypeID.INTEGER || type.typeId() == Type.TypeID.DATE;
}
}
private static class BucketLong extends Bucket {
- private BucketLong(int N) {
- super(N);
+ private BucketLong(int numBuckets) {
+ super(numBuckets);
}
public int hash(Long value) {
@@ -166,19 +164,17 @@ public int hash(Long value) {
@Override
public boolean canTransform(Type type) {
- return (
- type.typeId() == TypeID.LONG ||
- type.typeId() == TypeID.TIME ||
- type.typeId() == TypeID.TIMESTAMP
- );
+ return type.typeId() == Type.TypeID.LONG
+ || type.typeId() == Type.TypeID.TIME
+ || type.typeId() == Type.TypeID.TIMESTAMP;
}
}
// bucketing by Double is not allowed by the spec, but this has the float hash implementation
static class BucketFloat extends Bucket {
// used by tests because the factory method will not instantiate a bucket function for floats
- BucketFloat(int N) {
- super(N);
+ BucketFloat(int numBuckets) {
+ super(numBuckets);
}
public int hash(Float value) {
@@ -187,15 +183,15 @@ public int hash(Float value) {
@Override
public boolean canTransform(Type type) {
- return type.typeId() == TypeID.FLOAT;
+ return type.typeId() == Type.TypeID.FLOAT;
}
}
// bucketing by Double is not allowed by the spec, but this has the double hash implementation
static class BucketDouble extends Bucket {
// used by tests because the factory method will not instantiate a bucket function for doubles
- BucketDouble(int N) {
- super(N);
+ BucketDouble(int numBuckets) {
+ super(numBuckets);
}
public int hash(Double value) {
@@ -204,31 +200,31 @@ public int hash(Double value) {
@Override
public boolean canTransform(Type type) {
- return type.typeId() == TypeID.DOUBLE;
+ return type.typeId() == Type.TypeID.DOUBLE;
}
}
private static class BucketString extends Bucket {
- private BucketString(int N) {
- super(N);
+ private BucketString(int numBuckets) {
+ super(numBuckets);
}
public int hash(CharSequence value) {
- return MURMUR3.hashString(value, Charsets.UTF_8).asInt();
+ return MURMUR3.hashString(value, StandardCharsets.UTF_8).asInt();
}
@Override
public boolean canTransform(Type type) {
- return type.typeId() == TypeID.STRING;
+ return type.typeId() == Type.TypeID.STRING;
}
}
private static class BucketBytes extends Bucket {
- private static final Set SUPPORTED_TYPES = Sets.newHashSet(
- TypeID.BINARY, TypeID.FIXED);
+ private static final Set SUPPORTED_TYPES = Sets.newHashSet(
+ Type.TypeID.BINARY, Type.TypeID.FIXED);
- private BucketBytes(int N) {
- super(N);
+ private BucketBytes(int numBuckets) {
+ super(numBuckets);
}
public int hash(byte[] value) {
@@ -242,11 +238,11 @@ public boolean canTransform(Type type) {
}
private static class BucketByteBuffer extends Bucket {
- private static final Set SUPPORTED_TYPES = Sets.newHashSet(
- TypeID.BINARY, TypeID.FIXED);
+ private static final Set SUPPORTED_TYPES = Sets.newHashSet(
+ Type.TypeID.BINARY, Type.TypeID.FIXED);
- private BucketByteBuffer(int N) {
- super(N);
+ private BucketByteBuffer(int numBuckets) {
+ super(numBuckets);
}
public int hash(ByteBuffer value) {
@@ -273,15 +269,15 @@ public boolean canTransform(Type type) {
}
}
- private static class BucketUUID extends Bucket {
+ private static class BucketUuid extends Bucket {
private static final ThreadLocal BUFFER = ThreadLocal.withInitial(() -> {
ByteBuffer buffer = ByteBuffer.allocate(16);
buffer.order(ByteOrder.BIG_ENDIAN);
return buffer;
});
- private BucketUUID(int N) {
- super(N);
+ private BucketUuid(int numBuckets) {
+ super(numBuckets);
}
public int hash(UUID value) {
@@ -294,13 +290,13 @@ public int hash(UUID value) {
@Override
public boolean canTransform(Type type) {
- return type.typeId() == TypeID.UUID;
+ return type.typeId() == Type.TypeID.UUID;
}
}
private static class BucketDecimal extends Bucket {
- private BucketDecimal(int N) {
- super(N);
+ private BucketDecimal(int numBuckets) {
+ super(numBuckets);
}
public int hash(BigDecimal value) {
@@ -309,7 +305,7 @@ public int hash(BigDecimal value) {
@Override
public boolean canTransform(Type type) {
- return type.typeId() == TypeID.DECIMAL;
+ return type.typeId() == Type.TypeID.DECIMAL;
}
}
}
diff --git a/api/src/main/java/com/netflix/iceberg/transforms/Dates.java b/api/src/main/java/com/netflix/iceberg/transforms/Dates.java
index 0b45f0b0ebba..c3facb1f1890 100644
--- a/api/src/main/java/com/netflix/iceberg/transforms/Dates.java
+++ b/api/src/main/java/com/netflix/iceberg/transforms/Dates.java
@@ -19,6 +19,9 @@
package com.netflix.iceberg.transforms;
+import static com.netflix.iceberg.expressions.Expression.Operation.IS_NULL;
+import static com.netflix.iceberg.expressions.Expression.Operation.NOT_NULL;
+
import com.netflix.iceberg.expressions.BoundPredicate;
import com.netflix.iceberg.expressions.Expressions;
import com.netflix.iceberg.expressions.UnboundPredicate;
@@ -29,9 +32,6 @@
import java.time.ZoneOffset;
import java.time.temporal.ChronoUnit;
-import static com.netflix.iceberg.expressions.Expression.Operation.IS_NULL;
-import static com.netflix.iceberg.expressions.Expression.Operation.NOT_NULL;
-
enum Dates implements Transform {
YEAR(ChronoUnit.YEARS, "year"),
MONTH(ChronoUnit.MONTHS, "month"),
@@ -65,15 +65,15 @@ public Type getResultType(Type sourceType) {
}
@Override
- public UnboundPredicate project(String name, BoundPredicate pred) {
+ public UnboundPredicate project(String nameToProject, BoundPredicate pred) {
if (pred.op() == NOT_NULL || pred.op() == IS_NULL) {
- return Expressions.predicate(pred.op(), name);
+ return Expressions.predicate(pred.op(), nameToProject);
}
- return ProjectionUtil.truncateInteger(name, pred, this);
+ return ProjectionUtil.truncateInteger(nameToProject, pred, this);
}
@Override
- public UnboundPredicate projectStrict(String name, BoundPredicate predicate) {
+ public UnboundPredicate projectStrict(String nameToProject, BoundPredicate predicate) {
return null;
}
diff --git a/api/src/main/java/com/netflix/iceberg/transforms/Identity.java b/api/src/main/java/com/netflix/iceberg/transforms/Identity.java
index c1620ed17901..e95b5df95d2c 100644
--- a/api/src/main/java/com/netflix/iceberg/transforms/Identity.java
+++ b/api/src/main/java/com/netflix/iceberg/transforms/Identity.java
@@ -45,8 +45,8 @@ public T apply(T value) {
}
@Override
- public boolean canTransform(Type type) {
- return type.isPrimitiveType();
+ public boolean canTransform(Type typeToTransform) {
+ return typeToTransform.isPrimitiveType();
}
@Override
@@ -105,15 +105,15 @@ public String toString() {
}
@Override
- public boolean equals(Object o) {
- if (this == o) {
+ public boolean equals(Object other) {
+ if (this == other) {
return true;
}
- if (o == null || getClass() != o.getClass()) {
+ if (other == null || getClass() != other.getClass()) {
return false;
}
- Identity> that = (Identity>) o;
+ Identity> that = (Identity>) other;
return type.equals(that.type);
}
diff --git a/api/src/main/java/com/netflix/iceberg/transforms/PartitionSpecVisitor.java b/api/src/main/java/com/netflix/iceberg/transforms/PartitionSpecVisitor.java
index 0de992adfba2..c05b90af87af 100644
--- a/api/src/main/java/com/netflix/iceberg/transforms/PartitionSpecVisitor.java
+++ b/api/src/main/java/com/netflix/iceberg/transforms/PartitionSpecVisitor.java
@@ -40,6 +40,8 @@ public interface PartitionSpecVisitor {
T hour(String sourceName, int sourceId);
+ // Suppressing cyclomatic complexity because of the instanceof checks and inherent branching.
+ @SuppressWarnings("checkstyle:CyclomaticComplexity")
static List visit(Schema schema, PartitionSpec spec, PartitionSpecVisitor visitor) {
List results = Lists.newArrayListWithExpectedSize(spec.fields().size());
diff --git a/api/src/main/java/com/netflix/iceberg/transforms/ProjectionUtil.java b/api/src/main/java/com/netflix/iceberg/transforms/ProjectionUtil.java
index 06f0067fb49e..e269250b3c2b 100644
--- a/api/src/main/java/com/netflix/iceberg/transforms/ProjectionUtil.java
+++ b/api/src/main/java/com/netflix/iceberg/transforms/ProjectionUtil.java
@@ -21,29 +21,31 @@
import com.netflix.iceberg.expressions.BoundPredicate;
import com.netflix.iceberg.expressions.Expression;
+import com.netflix.iceberg.expressions.Expressions;
import com.netflix.iceberg.expressions.UnboundPredicate;
import java.math.BigDecimal;
import java.math.BigInteger;
-import static com.netflix.iceberg.expressions.Expressions.predicate;
-
class ProjectionUtil {
+
+ private ProjectionUtil() {}
+
static UnboundPredicate truncateInteger(
String name, BoundPredicate pred, Transform transform) {
int boundary = pred.literal().value();
switch (pred.op()) {
case LT:
// adjust closed and then transform ltEq
- return predicate(Expression.Operation.LT_EQ, name, transform.apply(boundary - 1));
+ return Expressions.predicate(Expression.Operation.LT_EQ, name, transform.apply(boundary - 1));
case LT_EQ:
- return predicate(Expression.Operation.LT_EQ, name, transform.apply(boundary));
+ return Expressions.predicate(Expression.Operation.LT_EQ, name, transform.apply(boundary));
case GT:
// adjust closed and then transform gtEq
- return predicate(Expression.Operation.GT_EQ, name, transform.apply(boundary + 1));
+ return Expressions.predicate(Expression.Operation.GT_EQ, name, transform.apply(boundary + 1));
case GT_EQ:
- return predicate(Expression.Operation.GT_EQ, name, transform.apply(boundary));
+ return Expressions.predicate(Expression.Operation.GT_EQ, name, transform.apply(boundary));
case EQ:
- return predicate(pred.op(), name, transform.apply(boundary));
+ return Expressions.predicate(pred.op(), name, transform.apply(boundary));
default:
return null;
}
@@ -55,16 +57,16 @@ static UnboundPredicate truncateLong(
switch (pred.op()) {
case LT:
// adjust closed and then transform ltEq
- return predicate(Expression.Operation.LT_EQ, name, transform.apply(boundary - 1L));
+ return Expressions.predicate(Expression.Operation.LT_EQ, name, transform.apply(boundary - 1L));
case LT_EQ:
- return predicate(Expression.Operation.LT_EQ, name, transform.apply(boundary));
+ return Expressions.predicate(Expression.Operation.LT_EQ, name, transform.apply(boundary));
case GT:
// adjust closed and then transform gtEq
- return predicate(Expression.Operation.GT_EQ, name, transform.apply(boundary + 1L));
+ return Expressions.predicate(Expression.Operation.GT_EQ, name, transform.apply(boundary + 1L));
case GT_EQ:
- return predicate(Expression.Operation.GT_EQ, name, transform.apply(boundary));
+ return Expressions.predicate(Expression.Operation.GT_EQ, name, transform.apply(boundary));
case EQ:
- return predicate(pred.op(), name, transform.apply(boundary));
+ return Expressions.predicate(pred.op(), name, transform.apply(boundary));
default:
return null;
}
@@ -80,19 +82,19 @@ static UnboundPredicate truncateDecimal(
BigDecimal minusOne = new BigDecimal(
boundary.unscaledValue().subtract(BigInteger.ONE),
boundary.scale());
- return predicate(Expression.Operation.LT_EQ, name, transform.apply(minusOne));
+ return Expressions.predicate(Expression.Operation.LT_EQ, name, transform.apply(minusOne));
case LT_EQ:
- return predicate(Expression.Operation.LT_EQ, name, transform.apply(boundary));
+ return Expressions.predicate(Expression.Operation.LT_EQ, name, transform.apply(boundary));
case GT:
// adjust closed and then transform gtEq
BigDecimal plusOne = new BigDecimal(
boundary.unscaledValue().add(BigInteger.ONE),
boundary.scale());
- return predicate(Expression.Operation.GT_EQ, name, transform.apply(plusOne));
+ return Expressions.predicate(Expression.Operation.GT_EQ, name, transform.apply(plusOne));
case GT_EQ:
- return predicate(Expression.Operation.GT_EQ, name, transform.apply(boundary));
+ return Expressions.predicate(Expression.Operation.GT_EQ, name, transform.apply(boundary));
case EQ:
- return predicate(pred.op(), name, transform.apply(boundary));
+ return Expressions.predicate(pred.op(), name, transform.apply(boundary));
default:
return null;
}
@@ -104,12 +106,12 @@ static UnboundPredicate truncateArray(
switch (pred.op()) {
case LT:
case LT_EQ:
- return predicate(Expression.Operation.LT_EQ, name, transform.apply(boundary));
+ return Expressions.predicate(Expression.Operation.LT_EQ, name, transform.apply(boundary));
case GT:
case GT_EQ:
- return predicate(Expression.Operation.GT_EQ, name, transform.apply(boundary));
+ return Expressions.predicate(Expression.Operation.GT_EQ, name, transform.apply(boundary));
case EQ:
- return predicate(Expression.Operation.EQ, name, transform.apply(boundary));
+ return Expressions.predicate(Expression.Operation.EQ, name, transform.apply(boundary));
// case IN: // TODO
// return Expressions.predicate(Operation.IN, name, transform.apply(boundary));
default:
diff --git a/api/src/main/java/com/netflix/iceberg/transforms/Timestamps.java b/api/src/main/java/com/netflix/iceberg/transforms/Timestamps.java
index 7977e5bb97e0..82b3d59fc938 100644
--- a/api/src/main/java/com/netflix/iceberg/transforms/Timestamps.java
+++ b/api/src/main/java/com/netflix/iceberg/transforms/Timestamps.java
@@ -19,6 +19,9 @@
package com.netflix.iceberg.transforms;
+import static com.netflix.iceberg.expressions.Expression.Operation.IS_NULL;
+import static com.netflix.iceberg.expressions.Expression.Operation.NOT_NULL;
+
import com.netflix.iceberg.expressions.BoundPredicate;
import com.netflix.iceberg.expressions.Expressions;
import com.netflix.iceberg.expressions.UnboundPredicate;
@@ -29,9 +32,6 @@
import java.time.ZoneOffset;
import java.time.temporal.ChronoUnit;
-import static com.netflix.iceberg.expressions.Expression.Operation.IS_NULL;
-import static com.netflix.iceberg.expressions.Expression.Operation.NOT_NULL;
-
enum Timestamps implements Transform {
YEAR(ChronoUnit.YEARS, "year"),
MONTH(ChronoUnit.MONTHS, "month"),
@@ -53,7 +53,8 @@ public Integer apply(Long timestampMicros) {
OffsetDateTime timestamp = Instant
.ofEpochSecond(timestampMicros / 1_000_000)
.atOffset(ZoneOffset.UTC);
- return (int) granularity.between(EPOCH, timestamp);
+ Integer year = Long.valueOf(granularity.between(EPOCH, timestamp)).intValue();
+ return year;
}
@Override
@@ -67,15 +68,15 @@ public Type getResultType(Type sourceType) {
}
@Override
- public UnboundPredicate project(String name, BoundPredicate pred) {
+ public UnboundPredicate project(String nameToProject, BoundPredicate pred) {
if (pred.op() == NOT_NULL || pred.op() == IS_NULL) {
- return Expressions.predicate(pred.op(), name);
+ return Expressions.predicate(pred.op(), nameToProject);
}
- return ProjectionUtil.truncateLong(name, pred, this);
+ return ProjectionUtil.truncateLong(nameToProject, pred, this);
}
@Override
- public UnboundPredicate projectStrict(String name, BoundPredicate predicate) {
+ public UnboundPredicate projectStrict(String nameToProject, BoundPredicate predicate) {
return null;
}
diff --git a/api/src/main/java/com/netflix/iceberg/transforms/TransformUtil.java b/api/src/main/java/com/netflix/iceberg/transforms/TransformUtil.java
index 8a71d44659b5..bbfc5d98e244 100644
--- a/api/src/main/java/com/netflix/iceberg/transforms/TransformUtil.java
+++ b/api/src/main/java/com/netflix/iceberg/transforms/TransformUtil.java
@@ -19,8 +19,8 @@
package com.netflix.iceberg.transforms;
-import com.google.common.base.Charsets;
import java.nio.ByteBuffer;
+import java.nio.charset.StandardCharsets;
import java.time.Instant;
import java.time.LocalTime;
import java.time.OffsetDateTime;
@@ -29,6 +29,8 @@
import java.util.Base64;
class TransformUtil {
+ private TransformUtil() {}
+
private static final OffsetDateTime EPOCH = Instant.ofEpochSecond(0).atOffset(ZoneOffset.UTC);
private static final int EPOCH_YEAR = EPOCH.getYear();
@@ -66,6 +68,6 @@ static String humanHour(int hourOrdinal) {
static String base64encode(ByteBuffer buffer) {
// use direct encoding because all of the encoded bytes are in ASCII
- return Charsets.ISO_8859_1.decode(Base64.getEncoder().encode(buffer)).toString();
+ return StandardCharsets.ISO_8859_1.decode(Base64.getEncoder().encode(buffer)).toString();
}
}
diff --git a/api/src/main/java/com/netflix/iceberg/transforms/Transforms.java b/api/src/main/java/com/netflix/iceberg/transforms/Transforms.java
index 044fe8928662..969a725dde7b 100644
--- a/api/src/main/java/com/netflix/iceberg/transforms/Transforms.java
+++ b/api/src/main/java/com/netflix/iceberg/transforms/Transforms.java
@@ -20,8 +20,8 @@
package com.netflix.iceberg.transforms;
import com.google.common.base.Preconditions;
-import com.netflix.iceberg.Schema;
import com.netflix.iceberg.PartitionSpec;
+import com.netflix.iceberg.Schema;
import com.netflix.iceberg.types.Type;
import java.util.Locale;
import java.util.regex.Matcher;
@@ -45,11 +45,11 @@ private Transforms() {
Matcher width = HAS_WIDTH.matcher(transform);
if (width.matches()) {
String name = width.group(1);
- int w = Integer.parseInt(width.group(2));
+ int parsedWidth = Integer.parseInt(width.group(2));
if (name.equalsIgnoreCase("truncate")) {
- return Truncate.get(type, w);
+ return Truncate.get(type, parsedWidth);
} else if (name.equals("bucket")) {
- return Bucket.get(type, w);
+ return Bucket.get(type, parsedWidth);
}
}
diff --git a/api/src/main/java/com/netflix/iceberg/transforms/Truncate.java b/api/src/main/java/com/netflix/iceberg/transforms/Truncate.java
index d2542079f366..bb9bd83fce76 100644
--- a/api/src/main/java/com/netflix/iceberg/transforms/Truncate.java
+++ b/api/src/main/java/com/netflix/iceberg/transforms/Truncate.java
@@ -19,6 +19,11 @@
package com.netflix.iceberg.transforms;
+import static com.netflix.iceberg.expressions.Expression.Operation.IS_NULL;
+import static com.netflix.iceberg.expressions.Expression.Operation.LT;
+import static com.netflix.iceberg.expressions.Expression.Operation.LT_EQ;
+import static com.netflix.iceberg.expressions.Expression.Operation.NOT_NULL;
+
import com.google.common.base.Objects;
import com.netflix.iceberg.expressions.BoundPredicate;
import com.netflix.iceberg.expressions.Expressions;
@@ -28,11 +33,6 @@
import java.math.BigInteger;
import java.nio.ByteBuffer;
-import static com.netflix.iceberg.expressions.Expression.Operation.IS_NULL;
-import static com.netflix.iceberg.expressions.Expression.Operation.LT;
-import static com.netflix.iceberg.expressions.Expression.Operation.LT_EQ;
-import static com.netflix.iceberg.expressions.Expression.Operation.NOT_NULL;
-
abstract class Truncate implements Transform {
@SuppressWarnings("unchecked")
static Truncate get(Type type, int width) {
@@ -53,10 +53,10 @@ static Truncate get(Type type, int width) {
}
}
- abstract public Integer width();
+ public abstract Integer width();
@Override
- abstract public T apply(T value);
+ public abstract T apply(T value);
@Override
public Type getResultType(Type sourceType) {
@@ -64,20 +64,20 @@ public Type getResultType(Type sourceType) {
}
private static class TruncateInteger extends Truncate {
- private final int W;
+ private final int width;
private TruncateInteger(int width) {
- this.W = width;
+ this.width = width;
}
@Override
public Integer width() {
- return W;
+ return width;
}
@Override
public Integer apply(Integer value) {
- return value - (((value % W) + W) % W);
+ return value - (((value % width) + width) % width);
}
@Override
@@ -137,44 +137,44 @@ public UnboundPredicate projectStrict(String name, BoundPredicate {
- private final int W;
+ private final int width;
private TruncateLong(int width) {
- this.W = width;
+ this.width = width;
}
@Override
public Integer width() {
- return W;
+ return width;
}
@Override
public Long apply(Long value) {
- return value - (((value % W) + W) % W);
+ return value - (((value % width) + width) % width);
}
@Override
@@ -196,44 +196,44 @@ public UnboundPredicate projectStrict(String name, BoundPredicate pr
}
@Override
- public boolean equals(Object o) {
- if (this == o) {
+ public boolean equals(Object other) {
+ if (this == other) {
return true;
}
- if (o == null || getClass() != o.getClass()) {
+ if (other == null || getClass() != other.getClass()) {
return false;
}
- TruncateLong that = (TruncateLong) o;
- return W == that.W;
+ TruncateLong that = (TruncateLong) other;
+ return width == that.width;
}
@Override
public int hashCode() {
- return Objects.hashCode(W);
+ return Objects.hashCode(width);
}
@Override
public String toString() {
- return "truncate[" + W + "]";
+ return "truncate[" + width + "]";
}
}
private static class TruncateString extends Truncate {
- private final int L;
+ private final int length;
private TruncateString(int length) {
- this.L = length;
+ this.length = length;
}
@Override
public Integer width() {
- return L;
+ return length;
}
@Override
public CharSequence apply(CharSequence value) {
- return value.subSequence(0, Math.min(value.length(), L));
+ return value.subSequence(0, Math.min(value.length(), length));
}
@Override
@@ -257,45 +257,45 @@ public UnboundPredicate projectStrict(String name,
}
@Override
- public boolean equals(Object o) {
- if (this == o) {
+ public boolean equals(Object other) {
+ if (this == other) {
return true;
}
- if (o == null || getClass() != o.getClass()) {
+ if (other == null || getClass() != other.getClass()) {
return false;
}
- TruncateString that = (TruncateString) o;
- return L == that.L;
+ TruncateString that = (TruncateString) other;
+ return length == that.length;
}
@Override
public int hashCode() {
- return Objects.hashCode(L);
+ return Objects.hashCode(length);
}
@Override
public String toString() {
- return "truncate[" + L + "]";
+ return "truncate[" + length + "]";
}
}
private static class TruncateByteBuffer extends Truncate {
- private final int L;
+ private final int length;
private TruncateByteBuffer(int length) {
- this.L = length;
+ this.length = length;
}
@Override
public Integer width() {
- return L;
+ return length;
}
@Override
public ByteBuffer apply(ByteBuffer value) {
ByteBuffer ret = value.duplicate();
- ret.limit(Math.min(value.limit(), value.position() + L));
+ ret.limit(Math.min(value.limit(), value.position() + length));
return ret;
}
@@ -320,21 +320,21 @@ public UnboundPredicate projectStrict(String name,
}
@Override
- public boolean equals(Object o) {
- if (this == o) {
+ public boolean equals(Object other) {
+ if (this == other) {
return true;
}
- if (o == null || getClass() != o.getClass()) {
+ if (other == null || getClass() != other.getClass()) {
return false;
}
- TruncateByteBuffer that = (TruncateByteBuffer) o;
- return L == that.L;
+ TruncateByteBuffer that = (TruncateByteBuffer) other;
+ return length == that.length;
}
@Override
public int hashCode() {
- return Objects.hashCode(L);
+ return Objects.hashCode(length);
}
@Override
@@ -344,7 +344,7 @@ public String toHumanString(ByteBuffer value) {
@Override
public String toString() {
- return "truncate[" + L + "]";
+ return "truncate[" + length + "]";
}
}
@@ -392,15 +392,15 @@ public UnboundPredicate projectStrict(String name,
}
@Override
- public boolean equals(Object o) {
- if (this == o) {
+ public boolean equals(Object other) {
+ if (this == other) {
return true;
}
- if (o == null || getClass() != o.getClass()) {
+ if (other == null || getClass() != other.getClass()) {
return false;
}
- TruncateDecimal that = (TruncateDecimal) o;
+ TruncateDecimal that = (TruncateDecimal) other;
return unscaledWidth.equals(that.unscaledWidth);
}
diff --git a/api/src/main/java/com/netflix/iceberg/types/CheckCompatibility.java b/api/src/main/java/com/netflix/iceberg/types/CheckCompatibility.java
index 48ebb8b71b3c..4467756946b8 100644
--- a/api/src/main/java/com/netflix/iceberg/types/CheckCompatibility.java
+++ b/api/src/main/java/com/netflix/iceberg/types/CheckCompatibility.java
@@ -29,8 +29,6 @@
import java.util.Map;
import java.util.function.Supplier;
-import static com.netflix.iceberg.types.TypeUtil.isPromotionAllowed;
-
public class CheckCompatibility extends TypeUtil.CustomOrderSchemaVisitor> {
/**
* Returns a list of compatibility errors for writing with the given write schema.
@@ -217,7 +215,7 @@ public List primitive(Type.PrimitiveType readPrimitive) {
currentType.typeId().toString().toLowerCase(Locale.ENGLISH), readPrimitive));
}
- if (!isPromotionAllowed(currentType.asPrimitiveType(), readPrimitive)) {
+ if (!TypeUtil.isPromotionAllowed(currentType.asPrimitiveType(), readPrimitive)) {
return ImmutableList.of(String.format(": %s cannot be promoted to %s",
currentType, readPrimitive));
}
diff --git a/api/src/main/java/com/netflix/iceberg/types/Comparators.java b/api/src/main/java/com/netflix/iceberg/types/Comparators.java
index 6680f7dd16ff..5fc6fc4cdf57 100644
--- a/api/src/main/java/com/netflix/iceberg/types/Comparators.java
+++ b/api/src/main/java/com/netflix/iceberg/types/Comparators.java
@@ -24,6 +24,9 @@
import java.util.Comparator;
public class Comparators {
+
+ private Comparators() {}
+
private static final ImmutableMap> COMPARATORS = ImmutableMap
.>builder()
.put(Types.BooleanType.get(), Comparator.naturalOrder())
@@ -130,7 +133,7 @@ private static class NullSafeChainedComparator implements Comparator {
private final Comparator first;
private final Comparator super T> second;
- public NullSafeChainedComparator(Comparator first, Comparator super T> second) {
+ NullSafeChainedComparator(Comparator first, Comparator super T> second) {
this.first = first;
this.second = second;
}
diff --git a/api/src/main/java/com/netflix/iceberg/types/Conversions.java b/api/src/main/java/com/netflix/iceberg/types/Conversions.java
index cfef71d133da..cf6597ca25b4 100644
--- a/api/src/main/java/com/netflix/iceberg/types/Conversions.java
+++ b/api/src/main/java/com/netflix/iceberg/types/Conversions.java
@@ -19,7 +19,6 @@
package com.netflix.iceberg.types;
-import com.google.common.base.Charsets;
import com.netflix.iceberg.exceptions.RuntimeIOException;
import java.math.BigDecimal;
import java.math.BigInteger;
@@ -29,10 +28,14 @@
import java.nio.charset.CharacterCodingException;
import java.nio.charset.CharsetDecoder;
import java.nio.charset.CharsetEncoder;
+import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.UUID;
public class Conversions {
+
+ private Conversions() {}
+
private static final String HIVE_NULL = "__HIVE_DEFAULT_PARTITION__";
public static Object fromPartitionString(Type type, String asString) {
@@ -58,9 +61,9 @@ public static Object fromPartitionString(Type type, String asString) {
case FIXED:
Types.FixedType fixed = (Types.FixedType) type;
return Arrays.copyOf(
- asString.getBytes(Charsets.UTF_8), fixed.length());
+ asString.getBytes(StandardCharsets.UTF_8), fixed.length());
case BINARY:
- return asString.getBytes(Charsets.UTF_8);
+ return asString.getBytes(StandardCharsets.UTF_8);
case DECIMAL:
return new BigDecimal(asString);
default:
@@ -70,9 +73,9 @@ public static Object fromPartitionString(Type type, String asString) {
}
private static final ThreadLocal ENCODER =
- ThreadLocal.withInitial(Charsets.UTF_8::newEncoder);
+ ThreadLocal.withInitial(StandardCharsets.UTF_8::newEncoder);
private static final ThreadLocal DECODER =
- ThreadLocal.withInitial(Charsets.UTF_8::newDecoder);
+ ThreadLocal.withInitial(StandardCharsets.UTF_8::newDecoder);
public static ByteBuffer toByteBuffer(Type type, Object value) {
switch (type.typeId()) {
@@ -120,7 +123,7 @@ private static Object internalFromByteBuffer(Type type, ByteBuffer buffer) {
ByteBuffer tmp = buffer.duplicate().order(ByteOrder.LITTLE_ENDIAN);
switch (type.typeId()) {
case BOOLEAN:
- return (tmp.get() != 0x00);
+ return tmp.get() != 0x00;
case INTEGER:
case DATE:
return tmp.getInt();
diff --git a/api/src/main/java/com/netflix/iceberg/types/IndexById.java b/api/src/main/java/com/netflix/iceberg/types/IndexById.java
index 84d8061e19ed..ef47485b7786 100644
--- a/api/src/main/java/com/netflix/iceberg/types/IndexById.java
+++ b/api/src/main/java/com/netflix/iceberg/types/IndexById.java
@@ -33,7 +33,8 @@ public Map schema(Schema schema, Map struct(Types.StructType struct, List