-
Notifications
You must be signed in to change notification settings - Fork 3k
Add void transform that always produces null #924
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
api/src/main/java/org/apache/iceberg/transforms/SerializationProxies.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| /* | ||
| * 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.iceberg.transforms; | ||
|
|
||
| import java.io.ObjectStreamException; | ||
| import java.io.Serializable; | ||
|
|
||
| /** | ||
| * Stand-in classes for expression classes in Java Serialization. | ||
| * <p> | ||
| * These are used so that transform classes can be singletons and use identical equality. | ||
| */ | ||
| class SerializationProxies { | ||
| private SerializationProxies() { | ||
| } | ||
|
|
||
| static class VoidTransformProxy implements Serializable { | ||
| private static final VoidTransformProxy INSTANCE = new VoidTransformProxy(); | ||
|
|
||
| static VoidTransformProxy get() { | ||
| return INSTANCE; | ||
| } | ||
|
|
||
| /** | ||
| * Constructor for Java serialization. | ||
| */ | ||
| VoidTransformProxy() { | ||
| } | ||
|
|
||
| Object readResolve() throws ObjectStreamException { | ||
| return VoidTransform.get(); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
api/src/main/java/org/apache/iceberg/transforms/VoidTransform.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| /* | ||
| * 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.iceberg.transforms; | ||
|
|
||
| import java.io.ObjectStreamException; | ||
| import org.apache.iceberg.expressions.BoundPredicate; | ||
| import org.apache.iceberg.expressions.UnboundPredicate; | ||
| import org.apache.iceberg.types.Type; | ||
|
|
||
| class VoidTransform<S> implements Transform<S, Void> { | ||
| private static final VoidTransform<Object> INSTANCE = new VoidTransform<>(); | ||
|
|
||
| @SuppressWarnings("unchecked") | ||
| static <T> VoidTransform<T> get() { | ||
| return (VoidTransform<T>) INSTANCE; | ||
| } | ||
|
|
||
| private VoidTransform() { | ||
| } | ||
|
|
||
| @Override | ||
| public Void apply(Object value) { | ||
| return null; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean canTransform(Type type) { | ||
| return true; | ||
| } | ||
|
|
||
| @Override | ||
| public Type getResultType(Type sourceType) { | ||
| return sourceType; | ||
| } | ||
|
|
||
| @Override | ||
| public UnboundPredicate<Void> projectStrict(String name, BoundPredicate<S> predicate) { | ||
| return null; | ||
| } | ||
|
|
||
| @Override | ||
| public UnboundPredicate<Void> project(String name, BoundPredicate<S> predicate) { | ||
| return null; | ||
| } | ||
|
|
||
| @Override | ||
| public String toHumanString(Void value) { | ||
| return "null"; | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return "void"; | ||
| } | ||
|
|
||
| Object writeReplace() throws ObjectStreamException { | ||
| return SerializationProxies.VoidTransformProxy.get(); | ||
| } | ||
| } | ||
76 changes: 76 additions & 0 deletions
76
api/src/test/java/org/apache/iceberg/PartitionSpecTestBase.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| /* | ||
| * 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.iceberg; | ||
|
|
||
| import org.apache.iceberg.types.Types; | ||
|
|
||
| @SuppressWarnings("checkstyle:HideUtilityClassConstructor") | ||
| public class PartitionSpecTestBase { | ||
| public static final Schema SCHEMA = new Schema( | ||
| Types.NestedField.required(1, "i", Types.IntegerType.get()), | ||
| Types.NestedField.required(2, "l", Types.LongType.get()), | ||
| Types.NestedField.required(3, "d", Types.DateType.get()), | ||
| Types.NestedField.required(4, "t", Types.TimeType.get()), | ||
| Types.NestedField.required(5, "ts", Types.TimestampType.withoutZone()), | ||
| Types.NestedField.required(6, "dec", Types.DecimalType.of(9, 2)), | ||
| Types.NestedField.required(7, "s", Types.StringType.get()), | ||
| Types.NestedField.required(8, "u", Types.UUIDType.get()), | ||
| Types.NestedField.required(9, "f", Types.FixedType.ofLength(3)), | ||
| Types.NestedField.required(10, "b", Types.BinaryType.get()) | ||
| ); | ||
|
|
||
| // a spec with all of the allowed transform/type pairs | ||
| public static final PartitionSpec[] SPECS = new PartitionSpec[] { | ||
| PartitionSpec.builderFor(SCHEMA).identity("i").build(), | ||
| PartitionSpec.builderFor(SCHEMA).identity("l").build(), | ||
| PartitionSpec.builderFor(SCHEMA).identity("d").build(), | ||
| PartitionSpec.builderFor(SCHEMA).identity("t").build(), | ||
| PartitionSpec.builderFor(SCHEMA).identity("ts").build(), | ||
| PartitionSpec.builderFor(SCHEMA).identity("dec").build(), | ||
| PartitionSpec.builderFor(SCHEMA).identity("s").build(), | ||
| PartitionSpec.builderFor(SCHEMA).identity("u").build(), | ||
| PartitionSpec.builderFor(SCHEMA).identity("f").build(), | ||
| PartitionSpec.builderFor(SCHEMA).identity("b").build(), | ||
| PartitionSpec.builderFor(SCHEMA).bucket("i", 128).build(), | ||
| PartitionSpec.builderFor(SCHEMA).bucket("l", 128).build(), | ||
| PartitionSpec.builderFor(SCHEMA).bucket("d", 128).build(), | ||
| PartitionSpec.builderFor(SCHEMA).bucket("t", 128).build(), | ||
| PartitionSpec.builderFor(SCHEMA).bucket("ts", 128).build(), | ||
| PartitionSpec.builderFor(SCHEMA).bucket("dec", 128).build(), | ||
| PartitionSpec.builderFor(SCHEMA).bucket("s", 128).build(), | ||
| PartitionSpec.builderFor(SCHEMA).bucket("u", 128).build(), | ||
| PartitionSpec.builderFor(SCHEMA).bucket("f", 128).build(), | ||
| PartitionSpec.builderFor(SCHEMA).bucket("b", 128).build(), | ||
| PartitionSpec.builderFor(SCHEMA).year("d").build(), | ||
| PartitionSpec.builderFor(SCHEMA).month("d").build(), | ||
| PartitionSpec.builderFor(SCHEMA).day("d").build(), | ||
| PartitionSpec.builderFor(SCHEMA).year("ts").build(), | ||
| PartitionSpec.builderFor(SCHEMA).month("ts").build(), | ||
| PartitionSpec.builderFor(SCHEMA).day("ts").build(), | ||
| PartitionSpec.builderFor(SCHEMA).hour("ts").build(), | ||
| PartitionSpec.builderFor(SCHEMA).truncate("i", 10).build(), | ||
| PartitionSpec.builderFor(SCHEMA).truncate("l", 10).build(), | ||
| PartitionSpec.builderFor(SCHEMA).truncate("dec", 10).build(), | ||
| PartitionSpec.builderFor(SCHEMA).truncate("s", 10).build(), | ||
| PartitionSpec.builderFor(SCHEMA).add(6, "dec_unsupported", "unsupported").build(), | ||
| PartitionSpec.builderFor(SCHEMA).add(6, 1111, "dec_unsupported", "unsupported").build(), | ||
| PartitionSpec.builderFor(SCHEMA).alwaysNull("ts").build(), | ||
| }; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor nit here to think about . . . we seem to be using both
voidandnull. Would it make more sense to just consistently usevoidas it seems to better indicate there there is no expected value?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Null is the human-readable string for the value produced by the transform. Void is the name of the transform. I considered naming it something like
always_nullbutvoidseemed shorter and less error prone (was that alwaysNull or always-null?)