Skip to content
Open
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.paimon.predicate;

import org.apache.paimon.types.DataType;

import org.apache.paimon.shade.jackson2.com.fasterxml.jackson.annotation.JsonCreator;

import java.util.List;
import java.util.Optional;

/** A {@link LeafFunction} that always returns {@code false}. Used for AlwaysFalse predicates. */
public class FalseFunction extends LeafFunction {

private static final long serialVersionUID = 1L;

public static final String NAME = "FALSE";

public static final FalseFunction INSTANCE = new FalseFunction();

@JsonCreator
private FalseFunction() {}

@Override
public boolean test(DataType type, Object field, List<Object> literals) {
return false;
}

@Override
public boolean test(
DataType type,
long rowCount,
Object min,
Object max,
Long nullCount,
List<Object> literals) {
return false;
}

@Override
public Optional<LeafFunction> negate() {
return Optional.of(TrueFunction.INSTANCE);
}

@Override
public <T> T visit(FunctionVisitor<T> visitor, FieldRef fieldRef, List<Object> literals) {
throw new UnsupportedOperationException(
"FalseFunction does not support field-based visitation.");
}

@Override
public String toJson() {
return NAME;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ private static Map<String, LeafFunction> createRegistry() {
registry.put(NotIn.NAME, NotIn.INSTANCE);
registry.put(Between.NAME, Between.INSTANCE);
registry.put(NotBetween.NAME, NotBetween.INSTANCE);
registry.put(TrueFunction.NAME, TrueFunction.INSTANCE);
registry.put(FalseFunction.NAME, FalseFunction.INSTANCE);
return Collections.unmodifiableMap(registry);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,9 @@ public boolean test(
long rowCount, InternalRow minValues, InternalRow maxValues, InternalArray nullCounts) {
Optional<FieldRef> fieldRefOptional = fieldRefOptional();
if (!fieldRefOptional.isPresent()) {
if (transform instanceof TrueTransform) {
return function.test(transform.outputType(), 0, null, null, null, literals);
}
return true;
}
FieldRef fieldRef = fieldRefOptional.get();
Expand All @@ -165,6 +168,9 @@ public boolean test(

@Override
public Optional<Predicate> negate() {
if (transform instanceof TrueTransform) {
return function.negate().map(neg -> new LeafPredicate(transform, neg, literals));
}
Optional<FieldRef> fieldRefOptional = fieldRefOptional();
if (!fieldRefOptional.isPresent()) {
return Optional.empty();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,16 @@ public PartitionPredicateVisitor(List<String> partitionKeys) {
@Override
public Boolean visit(LeafPredicate predicate) {
Transform transform = predicate.transform();
boolean hasFieldRef = false;
for (Object input : transform.inputs()) {
if (input instanceof FieldRef) {
hasFieldRef = true;
if (!partitionKeys.contains(((FieldRef) input).name())) {
return false;
}
}
}
return true;
return hasFieldRef;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@
@JsonSubTypes.Type(value = ConcatTransform.class, name = ConcatTransform.NAME),
@JsonSubTypes.Type(value = ConcatWsTransform.class, name = ConcatWsTransform.NAME),
@JsonSubTypes.Type(value = UpperTransform.class, name = UpperTransform.NAME),
@JsonSubTypes.Type(value = LowerTransform.class, name = LowerTransform.NAME)
@JsonSubTypes.Type(value = LowerTransform.class, name = LowerTransform.NAME),
@JsonSubTypes.Type(value = TrueTransform.class, name = TrueTransform.NAME)
})
public interface Transform extends Serializable {

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.paimon.predicate;

import org.apache.paimon.types.DataType;

import org.apache.paimon.shade.jackson2.com.fasterxml.jackson.annotation.JsonCreator;

import java.util.List;
import java.util.Optional;

/** A {@link LeafFunction} that always returns {@code true}. Used for AlwaysTrue predicates. */
public class TrueFunction extends LeafFunction {

private static final long serialVersionUID = 1L;

public static final String NAME = "TRUE";

public static final TrueFunction INSTANCE = new TrueFunction();

@JsonCreator
private TrueFunction() {}

@Override
public boolean test(DataType type, Object field, List<Object> literals) {
return true;
}

@Override
public boolean test(
DataType type,
long rowCount,
Object min,
Object max,
Long nullCount,
List<Object> literals) {
return true;
}

@Override
public Optional<LeafFunction> negate() {
return Optional.of(FalseFunction.INSTANCE);
}

@Override
public <T> T visit(FunctionVisitor<T> visitor, FieldRef fieldRef, List<Object> literals) {
throw new UnsupportedOperationException(
"TrueFunction does not support field-based visitation.");
}

@Override
public String toJson() {
return NAME;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.paimon.predicate;

import org.apache.paimon.data.InternalRow;
import org.apache.paimon.types.DataType;
import org.apache.paimon.types.DataTypes;

import org.apache.paimon.shade.jackson2.com.fasterxml.jackson.annotation.JsonCreator;

import java.util.Collections;
import java.util.List;

/** A {@link Transform} that always returns {@code true}. Used for constant predicates. */
public class TrueTransform implements Transform {

private static final long serialVersionUID = 1L;

public static final String NAME = "TRUE";

public static final TrueTransform INSTANCE = new TrueTransform();

@JsonCreator
private TrueTransform() {}

@Override
public String name() {
return NAME;
}

@Override
public List<Object> inputs() {
return Collections.emptyList();
}

@Override
public DataType outputType() {
return DataTypes.BOOLEAN();
}

@Override
public Object transform(InternalRow row) {
return true;
}

@Override
public Transform copyWithNewInputs(List<Object> inputs) {
return INSTANCE;
}

@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
return o != null && getClass() == o.getClass();
}

@Override
public int hashCode() {
return NAME.hashCode();
}

@Override
public String toString() {
return NAME;
}
}
Loading
Loading