twalthr commented on a change in pull request #11925: URL: https://github.com/apache/flink/pull/11925#discussion_r416373024
########## File path: flink-table/flink-table-common/src/main/java/org/apache/flink/table/data/TypedSetters.java ########## @@ -0,0 +1,90 @@ +/* + * 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.flink.table.data; + +import org.apache.flink.annotation.Internal; +import org.apache.flink.table.data.binary.BinaryRowData; + +/** + * Provide type specialized setters to reduce if/else and eliminate box and unbox. This is mainly + * used on the binary format such as {@link BinaryRowData}. + */ +@Internal +public interface TypedSetters { + + /** + * Set null to this field. + */ + void setNullAt(int pos); + + /** + * Set boolean value. + */ + void setBoolean(int pos, boolean value); + + /** + * Set byte value. + */ + void setByte(int pos, byte value); + + /** + * Set short value. + */ + void setShort(int pos, short value); + + /** + * Set int value. + */ + void setInt(int pos, int value); + + /** + * Set long value. + */ + void setLong(int pos, long value); + + /** + * Set float value. + */ + void setFloat(int pos, float value); + + /** + * Set double value. + */ + void setDouble(int pos, double value); + + /** + * Set the decimal column value. + * + * <p>Note: + * Precision is compact: can call setNullAt when decimal is null. + * Precision is not compact: can not call setNullAt when decimal is null, must call + * setDecimal(i, null, precision) because we need update var-length-part. + */ + void setDecimal(int i, DecimalData value, int precision); Review comment: i => pos ########## File path: flink-table/flink-table-common/src/main/java/org/apache/flink/table/data/TypedSetters.java ########## @@ -0,0 +1,90 @@ +/* + * 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.flink.table.data; + +import org.apache.flink.annotation.Internal; +import org.apache.flink.table.data.binary.BinaryRowData; + +/** + * Provide type specialized setters to reduce if/else and eliminate box and unbox. This is mainly + * used on the binary format such as {@link BinaryRowData}. + */ +@Internal +public interface TypedSetters { + + /** + * Set null to this field. + */ + void setNullAt(int pos); + + /** + * Set boolean value. + */ + void setBoolean(int pos, boolean value); + + /** + * Set byte value. + */ + void setByte(int pos, byte value); + + /** + * Set short value. + */ + void setShort(int pos, short value); + + /** + * Set int value. + */ + void setInt(int pos, int value); + + /** + * Set long value. + */ + void setLong(int pos, long value); + + /** + * Set float value. + */ + void setFloat(int pos, float value); + + /** + * Set double value. + */ + void setDouble(int pos, double value); + + /** + * Set the decimal column value. + * + * <p>Note: + * Precision is compact: can call setNullAt when decimal is null. + * Precision is not compact: can not call setNullAt when decimal is null, must call + * setDecimal(i, null, precision) because we need update var-length-part. Review comment: nit: use `{@code }` to format the JavaDoc ########## File path: flink-table/flink-table-common/src/main/java/org/apache/flink/table/data/TypedSetters.java ########## @@ -0,0 +1,90 @@ +/* + * 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.flink.table.data; + +import org.apache.flink.annotation.Internal; +import org.apache.flink.table.data.binary.BinaryRowData; + +/** + * Provide type specialized setters to reduce if/else and eliminate box and unbox. This is mainly + * used on the binary format such as {@link BinaryRowData}. + */ +@Internal +public interface TypedSetters { + + /** + * Set null to this field. + */ + void setNullAt(int pos); + + /** + * Set boolean value. Review comment: Remove those JavaDocs. They are not useful and just make the code more complicated. ########## File path: flink-table/flink-table-common/src/main/java/org/apache/flink/table/data/binary/BinaryFormat.java ########## @@ -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.flink.table.data.binary; + +import org.apache.flink.core.memory.MemorySegment; + +/** + * Binary format spanning {@link MemorySegment}s. + */ +public interface BinaryFormat { Review comment: Missing `@Internal` ########## File path: flink-table/flink-table-common/src/main/java/org/apache/flink/table/data/binary/LazyBinaryFormat.java ########## @@ -0,0 +1,139 @@ +/* + * 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.flink.table.data.binary; + +import org.apache.flink.api.common.typeutils.TypeSerializer; +import org.apache.flink.core.memory.MemorySegment; +import org.apache.flink.util.WrappingRuntimeException; + +import java.io.IOException; + +/** + * An abstract implementation fo {@link BinaryFormat} which is lazily serialized into binary + * or lazily deserialized into Java object. + * + * <p>The reason why we introduce this data structure is in order to save (de)serialization + * in nested function calls. Consider the following function call chain: + * + * <pre>UDF0(input) -> UDF1(result0) -> UDF2(result1) -> UDF3(result2)</pre> + * + * <p>Such nested calls, if the return values of UDFs are Java object format, + * it will result in multiple conversions between Java object and binary format: + * + * <pre> + * converterToBinary(UDF0(converterToJavaObject(input))) -> + * converterToBinary(UDF1(converterToJavaObject(result0))) -> + * converterToBinary(UDF2(converterToJavaObject(result1))) -> + * ... + * </pre> + * + * <p>So we introduced {@link LazyBinaryFormat} to avoid the redundant cost, it has three forms: + * <ul> + * <li>Binary form</li> + * <li>Java object form</li> + * <li>Binary and Java object both exist</li> + * </ul> + * + * <p>It can lazy the conversions as much as possible. It will be converted into required form + * only when it is needed. + */ +public abstract class LazyBinaryFormat<T> implements BinaryFormat { Review comment: Missing `@Internal` ########## File path: flink-table/flink-table-common/src/main/java/org/apache/flink/table/utils/BinarySegmentUtils.java ########## @@ -0,0 +1,1201 @@ +/* + * 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.flink.table.utils; + +import org.apache.flink.annotation.Internal; +import org.apache.flink.annotation.VisibleForTesting; +import org.apache.flink.core.memory.DataOutputView; +import org.apache.flink.core.memory.MemorySegment; +import org.apache.flink.table.data.ArrayData; +import org.apache.flink.table.data.DecimalData; +import org.apache.flink.table.data.MapData; +import org.apache.flink.table.data.RawValueData; +import org.apache.flink.table.data.RowData; +import org.apache.flink.table.data.StringData; +import org.apache.flink.table.data.TimestampData; +import org.apache.flink.table.data.binary.BinaryArrayData; +import org.apache.flink.table.data.binary.BinaryMapData; +import org.apache.flink.table.data.binary.BinaryRawValueData; +import org.apache.flink.table.data.binary.BinaryStringData; +import org.apache.flink.table.data.binary.NestedRowData; + +import java.io.IOException; +import java.nio.ByteOrder; + +import static org.apache.flink.core.memory.MemoryUtils.UNSAFE; +import static org.apache.flink.table.data.binary.BinaryFormat.HIGHEST_FIRST_BIT; +import static org.apache.flink.table.data.binary.BinaryFormat.HIGHEST_SECOND_TO_EIGHTH_BIT; + +/** + * Utilities for binary data segments which heavily uses {@link MemorySegment}. + */ +@Internal +public class BinarySegmentUtils { Review comment: Put this under `org.apache.flink.table.data.binary`. Make the class `final` with a private default constructor. ########## File path: flink-table/flink-table-common/src/main/java/org/apache/flink/table/utils/MurmurHashUtils.java ########## @@ -0,0 +1,171 @@ +/* + * 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.flink.table.utils; + +import org.apache.flink.annotation.Internal; +import org.apache.flink.core.memory.MemorySegment; + +import static org.apache.flink.core.memory.MemoryUtils.UNSAFE; + +/** + * Murmur Hash. This is inspired by Guava's Murmur3_32HashFunction. + */ +@Internal +public final class MurmurHashUtils { Review comment: put under `org.apache.flink.table.data.binary` add private default constructor ########## File path: flink-table/flink-table-common/src/main/java/org/apache/flink/table/utils/StringUtf8Utils.java ########## @@ -0,0 +1,302 @@ +/* + * 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.flink.table.utils; + +import org.apache.flink.annotation.Internal; +import org.apache.flink.core.memory.MemorySegment; + +import java.io.UnsupportedEncodingException; +import java.nio.charset.StandardCharsets; +import java.util.Arrays; + +import static org.apache.flink.table.utils.BinarySegmentUtils.allocateReuseBytes; +import static org.apache.flink.table.utils.BinarySegmentUtils.allocateReuseChars; + +/** + * Utilities for String UTF-8. + */ +@Internal +public class StringUtf8Utils { Review comment: put under `org.apache.flink.table.data.binary` make final with private default constructor ########## File path: flink-table/flink-table-common/src/main/java/org/apache/flink/table/data/TypedSetters.java ########## @@ -0,0 +1,90 @@ +/* + * 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.flink.table.data; + +import org.apache.flink.annotation.Internal; +import org.apache.flink.table.data.binary.BinaryRowData; + +/** + * Provide type specialized setters to reduce if/else and eliminate box and unbox. This is mainly + * used on the binary format such as {@link BinaryRowData}. + */ +@Internal +public interface TypedSetters { Review comment: If this is mainly used for binary formats, put it in the binary package. ---------------------------------------------------------------- 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. For queries about this service, please contact Infrastructure at: [email protected]
