RussellSpitzer commented on code in PR #16198: URL: https://github.com/apache/iceberg/pull/16198#discussion_r3269862455
########## api/src/main/java/org/apache/iceberg/functions/Action.java: ########## @@ -0,0 +1,109 @@ +/* + * 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.functions; + +import java.io.Serializable; +import java.util.Objects; +import org.apache.iceberg.types.Type; +import org.apache.iceberg.util.SerializableFunction; + +/** + * A column projection action from the ReadRestrictions spec. + * + * <p>{@link #bind(Type)} returns the masking {@link SerializableFunction} for a given column type; + * all bound functions return null for null input. Per spec all predefined actions preserve the + * input column type, so the bound function maps {@code T -> T}. + * + * @param <T> column value type + */ +public interface Action<T> extends Serializable { + + String MASK_ALPHANUM = "mask-alphanum"; + String MASK_TO_FIXED_VALUE = "mask-to-fixed-value"; + String REPLACE_WITH_NULL = "replace-with-null"; + String SHOW_FIRST_4 = "show-first-4"; + String SHOW_LAST_4 = "show-last-4"; + String TRUNCATE_TO_YEAR = "truncate-to-year"; + String TRUNCATE_TO_MONTH = "truncate-to-month"; + String SHA_256_GLOBAL = "sha-256-global"; + String SHA_256_QUERY_LOCAL = "sha-256-query-local"; + String APPLY_EXPRESSION = "apply-expression"; + + /** The action discriminator string as sent on the wire. */ + String actionType(); + + /** The field id of the column this action applies to. */ + int fieldId(); + + /** + * Returns a function that applies this action to values of the given {@link Type}. + * + * @throws IllegalArgumentException if the type is not supported by this action. + */ + default SerializableFunction<T, T> bind(Type type) { + throw new UnsupportedOperationException("bind is not implemented for " + getClass().getName()); + } + + /** + * Variant that accepts a per-query salt. Only {@link Sha256QueryLocal} uses the salt; other + * actions ignore it and delegate to {@link #bind(Type)}. + */ + default SerializableFunction<T, T> bind(Type type, byte[] salt) { Review Comment: This feels uncomfortable to me. We are adding an API method that only a single instance uses and is silently ignored by everyone else. This may be a little heavy but maybe we should consider adding another interface SaltedAction and only have Sha256 implement it? This is only a single usage so that seems heavy but i'd rather we hardcode in the dependency rather than keep that knowledge in a javadoc -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
