twalthr commented on code in PR #29967: URL: https://github.com/apache/flink/pull/29967#discussion_r4694503655
########## flink-table/flink-table-runtime/src/main/java/org/apache/flink/table/runtime/functions/DefaultGeneratedComparator.java: ########## @@ -0,0 +1,81 @@ +/* + * 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.runtime.functions; + +import org.apache.flink.annotation.Internal; +import org.apache.flink.table.data.GenericRowData; +import org.apache.flink.table.data.RowData; +import org.apache.flink.table.functions.FunctionContext; +import org.apache.flink.table.functions.SpecializedFunction.GeneratedComparator; +import org.apache.flink.table.runtime.generated.GeneratedRecordComparator; +import org.apache.flink.table.runtime.generated.RecordComparator; + +/** + * Default runtime implementation for {@link GeneratedComparator}, backed by a generated {@link + * RecordComparator}. A value that is not a row is compared as a row of one field. + */ +@Internal +public final class DefaultGeneratedComparator implements GeneratedComparator { + + private static final long serialVersionUID = 1L; + + private final GeneratedRecordComparator generated; + + private final boolean isComposite; + + private final boolean isNullFirst; + + private transient RecordComparator comparator; + + private transient GenericRowData leftRow; + + private transient GenericRowData rightRow; + + public DefaultGeneratedComparator( + final GeneratedRecordComparator generated, + final boolean isComposite, + final boolean isNullFirst) { + this.generated = generated; + this.isComposite = isComposite; + this.isNullFirst = isNullFirst; + } + + @Override + public void open(final FunctionContext context) { + comparator = generated.newInstance(context.getUserCodeClassLoader()); + leftRow = new GenericRowData(1); + rightRow = new GenericRowData(1); + } + + @Override + public int compare(final Object left, final Object right) { + if (isComposite) { + if (left == null || right == null) { + if (left == right) { + return 0; + } + return (left == null) == isNullFirst ? -1 : 1; + } Review Comment: Is this part needed? Top-level rows should never be null, no? -- 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]
