xuyangzhong commented on code in PR #26632: URL: https://github.com/apache/flink/pull/26632#discussion_r2126176656
########## flink-table/flink-table-api-java/src/main/java/org/apache/flink/table/api/config/OptimizerConfigOptions.java: ########## @@ -373,6 +373,25 @@ public class OptimizerConfigOptions { + "requires reserving network buffers, which impacts memory usage. For this reason, " + "the number of input tables is limited to 20."); + @Documentation.TableOption(execMode = Documentation.ExecMode.STREAMING) Review Comment: Remove this config ########## flink-table/flink-table-common/src/main/java/org/apache/flink/table/api/Schema.java: ########## @@ -595,9 +621,57 @@ public Builder primaryKeyNamed(String constraintName, List<String> columnNames) return this; } + /** + * Declares an index for a set of given columns. Indexes are designed to enable very + * efficient search. The indexes are informational only and can be used for optimizations. + * It is the data owner's responsibility to guarantee the index queries allow the complete + * row to be retrieved efficiently. + * + * <p>The index will be assigned a generated name in the format {@code INDEX_col1_col2}. + * + * @param columns indexes that form a table index + */ + public Builder index(String... columns) { + Preconditions.checkNotNull(indexes, "Index column names must not be null."); + return index(Arrays.asList(columns)); + } + + /** + * Declares an index for a set of given columns. Indexes are designed to enable very + * efficient search. The indexes are informational only and can be used for optimizations. + * It is the data owner's responsibility to guarantee the index queries allow the complete + * row to be retrieved efficiently. + * + * <p>The index will be assigned a generated name in the format {@code INDEX_col1_col2}. + * + * @param columns indexes that form a table index + */ + public Builder index(List<String> columns) { + Preconditions.checkNotNull(indexes, "Index column names must not be null."); + final String generatedIndexName = + columns.stream().collect(Collectors.joining("_", "INDEX_", "")); + return indexNamed(generatedIndexName, columns); + } + + /** + * Declares an index for a set of given columns. Indexes are designed to enable very + * efficient search. The indexes are informational only and can be used for optimizations. + * It is the data owner's responsibility to guarantee the index queries allow the complete + * row to be retrieved efficiently. + * + * @param indexName the name of the index + * @param columns columns that form a table index + */ + public Builder indexNamed(String indexName, List<String> columns) { + Preconditions.checkNotNull(indexName, "Index name must not be null."); + Preconditions.checkNotNull(columns, "Index column names must not be null."); + this.indexes.add(new UnresolvedIndex(indexName, columns)); Review Comment: nit: add one more validation just like primary key and add one test for it. ``` Preconditions.checkArgument( !columns.isEmpty(), "Index must be defined for at least a single column."); ``` ########## flink-table/flink-table-common/src/main/java/org/apache/flink/table/catalog/ResolvedSchema.java: ########## @@ -63,15 +63,25 @@ public final class ResolvedSchema { private final List<Column> columns; private final List<WatermarkSpec> watermarkSpecs; private final @Nullable UniqueConstraint primaryKey; + private final List<Index> indexes; public ResolvedSchema( Review Comment: nit: Nit: tag this as `@Deprecated` ########## flink-table/flink-table-common/src/main/java/org/apache/flink/table/api/Schema.java: ########## @@ -77,13 +79,24 @@ public final class Schema { private final @Nullable UnresolvedPrimaryKey primaryKey; - private Schema( + private final List<UnresolvedIndex> indexes; + + public Schema( Review Comment: Nit: tag this as `@Deprecated` ########## flink-table/flink-table-common/src/main/java/org/apache/flink/table/catalog/ResolvedSchema.java: ########## @@ -63,15 +63,25 @@ public final class ResolvedSchema { private final List<Column> columns; private final List<WatermarkSpec> watermarkSpecs; private final @Nullable UniqueConstraint primaryKey; + private final List<Index> indexes; public ResolvedSchema( Review Comment: The ser and deser should also be adjust due to this new change. For example, `CompiledPlanSerdeUtil` ########## flink-table/flink-table-common/src/main/java/org/apache/flink/table/catalog/ResolvedSchema.java: ########## @@ -63,15 +63,25 @@ public final class ResolvedSchema { private final List<Column> columns; private final List<WatermarkSpec> watermarkSpecs; private final @Nullable UniqueConstraint primaryKey; + private final List<Index> indexes; public ResolvedSchema( Review Comment: Could you please double check that all usages on this except tests are moved to the new construct? ########## flink-table/flink-table-common/src/main/java/org/apache/flink/table/catalog/Index.java: ########## @@ -0,0 +1,41 @@ +/* + * 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.catalog; + +import org.apache.flink.annotation.Experimental; + +import java.util.List; + +/** + * An index is a copy of selected columns of data, from a table, that is designed to enable very + * efficient search. An index normally includes a "key" or direct link to the original row of data + * from which it was copied, to allow the complete row to be retrieved efficiently. + */ Review Comment: nit: add the comment following to explain the annotation `@Experimental`: ``` * <p>Currently, this interface is only exposed to developers. In the future, when we introduce * Index during lexical parsing, this can be marked as {@link PublicEvolving}. ``` -- 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: issues-unsubscr...@flink.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org