yihua commented on code in PR #9872:
URL: https://github.com/apache/hudi/pull/9872#discussion_r1377108821
##########
hudi-client/hudi-client-common/src/main/java/org/apache/hudi/metadata/HoodieBackedTableMetadataWriter.java:
##########
@@ -205,17 +216,27 @@ private void initMetadataReader() {
*/
private void enablePartitions() {
final HoodieMetadataConfig metadataConfig =
dataWriteConfig.getMetadataConfig();
- if (dataWriteConfig.isMetadataTableEnabled() ||
dataMetaClient.getTableConfig().isMetadataPartitionAvailable(MetadataPartitionType.FILES))
{
- this.enabledPartitionTypes.add(MetadataPartitionType.FILES);
+ if (dataWriteConfig.isMetadataTableEnabled() ||
dataMetaClient.getTableConfig().isMetadataPartitionAvailable(FILES)) {
+ this.enabledPartitionTypes.add(FILES);
}
- if (metadataConfig.isBloomFilterIndexEnabled() ||
dataMetaClient.getTableConfig().isMetadataPartitionAvailable(MetadataPartitionType.BLOOM_FILTERS))
{
- this.enabledPartitionTypes.add(MetadataPartitionType.BLOOM_FILTERS);
+ if (metadataConfig.isBloomFilterIndexEnabled() ||
dataMetaClient.getTableConfig().isMetadataPartitionAvailable(BLOOM_FILTERS)) {
+ this.enabledPartitionTypes.add(BLOOM_FILTERS);
}
- if (metadataConfig.isColumnStatsIndexEnabled() ||
dataMetaClient.getTableConfig().isMetadataPartitionAvailable(MetadataPartitionType.COLUMN_STATS))
{
- this.enabledPartitionTypes.add(MetadataPartitionType.COLUMN_STATS);
+ if (metadataConfig.isColumnStatsIndexEnabled() ||
dataMetaClient.getTableConfig().isMetadataPartitionAvailable(COLUMN_STATS)) {
+ this.enabledPartitionTypes.add(COLUMN_STATS);
}
- if (dataWriteConfig.isRecordIndexEnabled() ||
dataMetaClient.getTableConfig().isMetadataPartitionAvailable(MetadataPartitionType.RECORD_INDEX))
{
- this.enabledPartitionTypes.add(MetadataPartitionType.RECORD_INDEX);
+ if (dataWriteConfig.isRecordIndexEnabled() ||
dataMetaClient.getTableConfig().isMetadataPartitionAvailable(RECORD_INDEX)) {
+ this.enabledPartitionTypes.add(RECORD_INDEX);
+ }
+ Option<HoodieFunctionalIndexConfig> functionalIndexConfig =
dataMetaClient.getFunctionalIndexConfig();
+ if (functionalIndexConfig.isPresent()) {
+ this.enabledPartitionTypes.add(FUNCTIONAL_INDEX);
Review Comment:
I'm trying to understand how `FUNCTIONAL_INDEX` is enabled. Based on the
code, `CREATE INDEX` can add a new functional index partition. What about the
write configs? Are users allowed to create a functional index through write
configs?
##########
hudi-common/src/main/java/org/apache/hudi/common/config/ConfigGroups.java:
##########
@@ -40,7 +40,8 @@ public enum Names {
RECORD_PAYLOAD("Record Payload Config"),
KAFKA_CONNECT("Kafka Connect Configs"),
AWS("Amazon Web Services Configs"),
- HUDI_STREAMER("Hudi Streamer Configs");
+ HUDI_STREAMER("Hudi Streamer Configs"),
+ INDEXING("Indexing Configs");
Review Comment:
There is `INDEX` sub-group name below. Should that be consolidated?
```
INDEX(
"Index Configs",
"Configurations that control indexing behavior, "
+ "which tags incoming records as either inserts or updates to
older records."),
```
##########
hudi-client/hudi-client-common/src/main/java/org/apache/hudi/metadata/HoodieBackedTableMetadataWriter.java:
##########
@@ -498,6 +524,40 @@ private Pair<Integer, HoodieData<HoodieRecord>>
initializeBloomFiltersPartition(
return Pair.of(fileGroupCount, records);
}
+ protected abstract HoodieData<HoodieRecord>
getFunctionalIndexRecords(List<Pair<String, FileSlice>> partitionFileSlicePairs,
+
HoodieFunctionalIndexDefinition indexDefinition,
+
HoodieTableMetaClient metaClient,
+ int
parallelism, Schema readerSchema,
+
SerializableConfiguration hadoopConf);
+
+ private Pair<Integer, HoodieData<HoodieRecord>>
initializeFunctionalIndexPartition() throws Exception {
+ HoodieMetadataFileSystemView fsView = new
HoodieMetadataFileSystemView(dataMetaClient,
dataMetaClient.getActiveTimeline(), metadata);
+ HoodieFunctionalIndexDefinition indexDefinition =
getFunctionalIndexDefinition("");
Review Comment:
Why is the index name empty?
##########
hudi-client/hudi-spark-client/src/main/java/org/apache/hudi/index/functional/HoodieSparkFunctionalIndex.java:
##########
@@ -0,0 +1,229 @@
+/*
+ * 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.hudi.index.functional;
+
+import org.apache.hudi.common.util.CollectionUtils;
+import org.apache.hudi.common.util.collection.Pair;
+
+import org.apache.spark.sql.Column;
+import org.apache.spark.sql.functions;
+
+import java.io.Serializable;
+import java.util.List;
+import java.util.Map;
+
+public class HoodieSparkFunctionalIndex implements
HoodieFunctionalIndex<Column, Column>, Serializable {
+
+ /**
+ * Custom interface to support Spark functions
+ */
+ @FunctionalInterface
+ interface SparkFunction {
+ Column apply(List<Column> columns, Map<String, String> options);
+ }
+
+ /**
+ * Map of Spark functions to their implementations.
+ * NOTE: This is not an exhaustive list of spark-sql functions. Only the
common date/timestamp and string functions have been added.
+ * Add more functions as needed. However, keep the key should match the
exact spark-sql function name in lowercase.
+ */
+ private static final Map<String, SparkFunction> SPARK_FUNCTION_MAP =
CollectionUtils.createImmutableMap(
Review Comment:
Do we consider identity function, i.e., the column itself?
##########
hudi-client/hudi-client-common/src/main/java/org/apache/hudi/metadata/HoodieBackedTableMetadataWriter.java:
##########
@@ -422,6 +445,9 @@ private boolean initializeFromFilesystem(String
initializationTime, List<Metadat
case RECORD_INDEX:
fileGroupCountAndRecordsPair = initializeRecordIndexPartition();
break;
+ case FUNCTIONAL_INDEX:
+ fileGroupCountAndRecordsPair =
initializeFunctionalIndexPartition();
Review Comment:
Does each individual function have its only MDT partition, e.g.,
`metadata/functional_index_date`, `metadata/functional_index_month`? Should
this consider multiple partitions?
##########
hudi-client/hudi-client-common/src/main/java/org/apache/hudi/table/action/index/functional/BaseHoodieFunctionalIndexClient.java:
##########
@@ -0,0 +1,45 @@
+/*
+ * 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.hudi.table.action.index.functional;
+
+import org.apache.hudi.common.table.HoodieTableMetaClient;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Map;
+
+public abstract class BaseHoodieFunctionalIndexClient {
+
+ private static final Logger LOG =
LoggerFactory.getLogger(BaseHoodieFunctionalIndexClient.class);
+
+ public BaseHoodieFunctionalIndexClient() {
+ }
+
+ public void register(HoodieTableMetaClient metaClient, String indexName,
String indexType, Map<String, Map<String, String>> columns, Map<String, String>
options) {
Review Comment:
An example in the javadocs of how an index definition is retrieved and
serialized into the index metadata under `.hoodie` would help here.
--
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]