You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hudi.apache.org by GitBox <gi...@apache.org> on 2022/10/21 08:32:44 UTC

[GitHub] [hudi] trushev commented on a diff in pull request #5830: [WIP][HUDI-3981] Flink engine support for comprehensive schema evolution(RFC-33)

trushev commented on code in PR #5830:
URL: https://github.com/apache/hudi/pull/5830#discussion_r1001518524


##########
hudi-flink-datasource/hudi-flink/src/main/java/org/apache/hudi/table/format/mor/MergeOnReadInputFormat.java:
##########
@@ -166,29 +177,56 @@ public void open(MergeOnReadInputSplit split) throws IOException {
     this.currentReadCount = 0L;
     this.closed = false;
     this.hadoopConf = HadoopConfigurations.getHadoopConf(this.conf);
+    if (schemaEvolutionContext.isPresent()) {
+      SchemaEvolutionContext context = schemaEvolutionContext.get();
+      querySchema = context.getQuerySchema();
+      actualSchema = context.getActualSchema(split);
+      actualFieldNames = context.getFieldNames(actualSchema);
+      actualFieldTypes = context.getFieldTypes(actualSchema);
+    } else {
+      querySchema = InternalSchema.getEmptyInternalSchema();
+      actualSchema = InternalSchema.getEmptyInternalSchema();
+      actualFieldNames = fieldNames;
+      actualFieldTypes = fieldTypes;
+    }
+
     if (!(split.getLogPaths().isPresent() && split.getLogPaths().get().size() > 0)) {
-      if (split.getInstantRange() != null) {
+      if (split.getInstantRange().isPresent()) {
         // base file only with commit time filtering
         this.iterator = new BaseFileOnlyFilteringIterator(
-            split.getInstantRange(),
-            this.tableState.getRequiredRowType(),
+            split.getInstantRange().get(),
             getReader(split.getBasePath().get(), getRequiredPosWithCommitTime(this.requiredPos)));
+        int[] positions = IntStream.range(1, requiredPos.length + 1).toArray();
+        RowDataProjection projection = getCastProjection(positions)
+            .orElse(RowDataProjection.instance(tableState.getRequiredRowType(), positions));
+        projectRecordIterator(projection);
       } else {
         // base file only
         this.iterator = new BaseFileOnlyIterator(getRequiredSchemaReader(split.getBasePath().get()));
+        projectRecordIterator();
       }
     } else if (!split.getBasePath().isPresent()) {
       // log files only
       if (OptionsResolver.emitChangelog(conf)) {
         this.iterator = new LogFileOnlyIterator(getUnMergedLogFileIterator(split));
+        projectRecordIterator();
       } else {
         this.iterator = new LogFileOnlyIterator(getLogFileIterator(split));
+        projectRecordIterator();

Review Comment:
   You are right, fixed



##########
hudi-flink-datasource/hudi-flink/src/main/java/org/apache/hudi/table/format/CastMap.java:
##########
@@ -0,0 +1,259 @@
+/*
+ * 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.format;
+
+import org.apache.hudi.internal.schema.InternalSchema;
+import org.apache.hudi.internal.schema.Type;
+import org.apache.hudi.internal.schema.Types;
+import org.apache.hudi.internal.schema.convert.AvroInternalSchemaConverter;
+import org.apache.hudi.internal.schema.utils.InternalSchemaUtils;
+import org.apache.hudi.util.AvroSchemaConverter;
+
+import org.apache.avro.Schema;
+import org.apache.flink.annotation.VisibleForTesting;
+import org.apache.flink.table.data.DecimalData;
+import org.apache.flink.table.data.binary.BinaryStringData;
+import org.apache.flink.table.types.DataType;
+import org.apache.flink.table.types.logical.DecimalType;
+import org.apache.flink.table.types.logical.LogicalType;
+import org.apache.flink.table.types.logical.LogicalTypeRoot;
+import org.apache.flink.util.Preconditions;
+
+import java.io.Serializable;
+import java.math.BigDecimal;
+import java.time.LocalDate;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.function.Function;
+import java.util.stream.Collectors;
+
+import static org.apache.flink.table.types.logical.LogicalTypeRoot.BIGINT;
+import static org.apache.flink.table.types.logical.LogicalTypeRoot.DATE;
+import static org.apache.flink.table.types.logical.LogicalTypeRoot.DECIMAL;
+import static org.apache.flink.table.types.logical.LogicalTypeRoot.DOUBLE;
+import static org.apache.flink.table.types.logical.LogicalTypeRoot.FLOAT;
+import static org.apache.flink.table.types.logical.LogicalTypeRoot.INTEGER;
+import static org.apache.flink.table.types.logical.LogicalTypeRoot.VARCHAR;
+
+/**
+ * CastMap is responsible for conversion of flink types when full schema evolution enabled.
+ */
+public final class CastMap implements Serializable {
+  private static final long serialVersionUID = 1L;
+
+  // Maps position to corresponding cast
+  private final Map<Integer, Cast> castMap = new HashMap<>();
+
+  /**
+   * Creates CastMap by comparing two schemes. Cast of a specific column is created if its type has changed.
+   */
+  public static CastMap of(String tableName, InternalSchema querySchema, InternalSchema actualSchema) {
+    DataType queryType = internalSchemaToDataType(tableName, querySchema);
+    DataType actualType = internalSchemaToDataType(tableName, actualSchema);
+    CastMap castMap = new CastMap();
+    InternalSchemaUtils.collectTypeChangedCols(querySchema, actualSchema).entrySet().stream()
+        .filter(e -> !isSameType(e.getValue().getLeft(), e.getValue().getRight()))

Review Comment:
   fixed



-- 
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: commits-unsubscribe@hudi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org