Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 1 addition & 19 deletions api/src/main/java/org/apache/iceberg/expressions/And.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,7 @@

package org.apache.iceberg.expressions;

import org.apache.iceberg.StructLike;
import org.apache.iceberg.relocated.com.google.common.base.Preconditions;

public class And implements Expression, Bound<Boolean> {
public class And implements Expression {
private final Expression left;
private final Expression right;

Expand Down Expand Up @@ -50,21 +47,6 @@ public Expression negate() {
return Expressions.or(left.negate(), right.negate());
}

@Override
public BoundReference<?> ref() {
return null;
}

@Override
public Boolean eval(StructLike struct) {
Preconditions.checkNotNull(left, "Left expression cannot be null.");
Preconditions.checkNotNull(right, "Right expression cannot be null.");
if (!(left instanceof Bound) || !(right instanceof Bound)) {
throw new IllegalStateException("Unbound predicate not expected");
}
return ((Bound<Boolean>) left).eval(struct) && ((Bound<Boolean>) right).eval(struct);
}

@Override
public String toString() {
return String.format("(%s and %s)", left, right);
Expand Down
20 changes: 1 addition & 19 deletions api/src/main/java/org/apache/iceberg/expressions/Or.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,7 @@

package org.apache.iceberg.expressions;

import org.apache.iceberg.StructLike;
import org.apache.iceberg.relocated.com.google.common.base.Preconditions;

public class Or implements Expression, Bound<Boolean> {
public class Or implements Expression {
private final Expression left;
private final Expression right;

Expand Down Expand Up @@ -50,21 +47,6 @@ public Expression negate() {
return Expressions.and(left.negate(), right.negate());
}

@Override
public BoundReference<?> ref() {
return null;
}

@Override
public Boolean eval(StructLike struct) {
Preconditions.checkNotNull(left, "Left expression cannot be null.");
Preconditions.checkNotNull(right, "Right expression cannot be null.");
if (!(left instanceof Bound) || !(right instanceof Bound)) {
throw new IllegalStateException("Unbound predicate not expected");
}
return ((Bound<Boolean>) left).eval(struct) || ((Bound<Boolean>) right).eval(struct);
}

@Override
public String toString() {
return String.format("(%s or %s)", left, right);
Expand Down
4 changes: 0 additions & 4 deletions api/src/main/java/org/apache/iceberg/types/Conversions.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
import org.apache.iceberg.expressions.Literal;
import org.apache.iceberg.util.UUIDUtil;


public class Conversions {

private Conversions() {
Expand Down Expand Up @@ -72,9 +71,6 @@ public static Object fromPartitionString(Type type, String asString) {
return new BigDecimal(asString);
case DATE:
return Literal.of(asString).to(Types.DateType.get()).value();
case TIMESTAMP:
final String isoFormatTs = asString.replaceFirst(" ", "T");
return Literal.of(isoFormatTs).to(Types.TimestampType.withoutZone()).value();
default:
throw new UnsupportedOperationException(
"Unsupported type for fromPartitionString: " + type);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
import org.apache.iceberg.TableProperties;
import org.apache.iceberg.data.GenericRecord;
import org.apache.iceberg.expressions.Binder;
import org.apache.iceberg.expressions.Bound;
import org.apache.iceberg.expressions.Evaluator;
import org.apache.iceberg.expressions.Expression;
import org.apache.iceberg.expressions.Expressions;
import org.apache.iceberg.hadoop.HadoopFileIO;
Expand Down Expand Up @@ -202,6 +202,7 @@ private List<DirectoryInfo> getDirectoryInfosByFilter(Expression expression) {
databaseName, tableName, null, (short) -1));
} else {
boundExpression = Binder.bind(partitionSchema, simplified, false);
Evaluator evaluator = new Evaluator(partitionSchema, simplified, false);
String partitionFilterString = HiveExpressions.toPartitionFilterString(boundExpression);
LOG.info("Listing partitions for {}.{} with filter string: {}", databaseName, tableName, partitionFilterString);
try {
Expand Down Expand Up @@ -239,7 +240,7 @@ private List<DirectoryInfo> getDirectoryInfosByFilter(Expression expression) {
break;
}
}
return ((Bound<Boolean>) boundExpression).eval(record);
return evaluator.eval(record);
}).collect(Collectors.toList());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import org.apache.iceberg.StructLike;
import org.apache.iceberg.avro.AvroSchemaUtil;
import org.apache.iceberg.avro.AvroSchemaVisitor;
import org.apache.iceberg.expressions.Literal;
import org.apache.iceberg.hivelink.core.schema.MergeHiveSchemaWithAvro;
import org.apache.iceberg.hivelink.core.utils.HiveTypeUtil;
import org.apache.iceberg.relocated.com.google.common.base.Preconditions;
Expand Down Expand Up @@ -165,9 +166,17 @@ public int size() {

@Override
public <T> T get(int pos, Class<T> javaClass) {
final Object partitionValue = Conversions.fromPartitionString(
fields.get(pos).type(),
partitionValues.get(pos));
Type type = fields.get(pos).type();
String partitionString = partitionValues.get(pos);
final Object partitionValue;
// Special handling of TIMESTAMP type since Iceberg Conversions.fromPartitionString
// does not support it
if (type.typeId() == Type.TypeID.TIMESTAMP) {
String isoFormatTs = partitionString.replaceFirst(" ", "T");
partitionValue = Literal.of(isoFormatTs).to(Types.TimestampType.withoutZone()).value();
} else {
partitionValue = Conversions.fromPartitionString(type, partitionString);
}
return javaClass.cast(partitionValue);
}

Expand Down